avc.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Access vector cache interface for object managers.
  3. *
  4. * Author : Stephen Smalley, <sds@epoch.ncsc.mil>
  5. */
  6. #ifndef _SELINUX_AVC_H_
  7. #define _SELINUX_AVC_H_
  8. #include <linux/stddef.h>
  9. #include <linux/errno.h>
  10. #include <linux/kernel.h>
  11. #include <linux/kdev_t.h>
  12. #include <linux/spinlock.h>
  13. #include <linux/init.h>
  14. #include <linux/audit.h>
  15. #include <linux/lsm_audit.h>
  16. #include <linux/in6.h>
  17. #include "flask.h"
  18. #include "av_permissions.h"
  19. #include "security.h"
  20. #ifdef CONFIG_SECURITY_SELINUX_DEVELOP
  21. extern int selinux_enforcing;
  22. #else
  23. #define selinux_enforcing 1
  24. #endif
  25. /*
  26. * An entry in the AVC.
  27. */
  28. struct avc_entry;
  29. struct task_struct;
  30. struct inode;
  31. struct sock;
  32. struct sk_buff;
  33. /*
  34. * AVC statistics
  35. */
  36. struct avc_cache_stats {
  37. unsigned int lookups;
  38. unsigned int misses;
  39. unsigned int allocations;
  40. unsigned int reclaims;
  41. unsigned int frees;
  42. };
  43. /*
  44. * We only need this data after we have decided to send an audit message.
  45. */
  46. struct selinux_late_audit_data {
  47. u32 ssid;
  48. u32 tsid;
  49. u16 tclass;
  50. u32 requested;
  51. u32 audited;
  52. u32 denied;
  53. int result;
  54. };
  55. /*
  56. * We collect this at the beginning or during an selinux security operation
  57. */
  58. struct selinux_audit_data {
  59. /*
  60. * auditdeny is a bit tricky and unintuitive. See the
  61. * comments in avc.c for it's meaning and usage.
  62. */
  63. u32 auditdeny;
  64. struct selinux_late_audit_data *slad;
  65. };
  66. /*
  67. * AVC operations
  68. */
  69. void __init avc_init(void);
  70. int avc_audit(u32 ssid, u32 tsid,
  71. u16 tclass, u32 requested,
  72. struct av_decision *avd,
  73. int result,
  74. struct common_audit_data *a, unsigned flags);
  75. #define AVC_STRICT 1 /* Ignore permissive mode. */
  76. #define AVC_EXTENDED_PERMS 2 /* update extended permissions */
  77. int avc_has_perm_noaudit(u32 ssid, u32 tsid,
  78. u16 tclass, u32 requested,
  79. unsigned flags,
  80. struct av_decision *avd);
  81. int avc_has_perm_flags(u32 ssid, u32 tsid,
  82. u16 tclass, u32 requested,
  83. struct common_audit_data *auditdata,
  84. unsigned);
  85. static inline int avc_has_perm(u32 ssid, u32 tsid,
  86. u16 tclass, u32 requested,
  87. struct common_audit_data *auditdata)
  88. {
  89. return avc_has_perm_flags(ssid, tsid, tclass, requested, auditdata, 0);
  90. }
  91. int avc_has_extended_perms(u32 ssid, u32 tsid, u16 tclass, u32 requested,
  92. u8 driver, u8 perm, struct common_audit_data *ad);
  93. u32 avc_policy_seqno(void);
  94. #define AVC_CALLBACK_GRANT 1
  95. #define AVC_CALLBACK_TRY_REVOKE 2
  96. #define AVC_CALLBACK_REVOKE 4
  97. #define AVC_CALLBACK_RESET 8
  98. #define AVC_CALLBACK_AUDITALLOW_ENABLE 16
  99. #define AVC_CALLBACK_AUDITALLOW_DISABLE 32
  100. #define AVC_CALLBACK_AUDITDENY_ENABLE 64
  101. #define AVC_CALLBACK_AUDITDENY_DISABLE 128
  102. #define AVC_CALLBACK_ADD_XPERMS 256
  103. int avc_add_callback(int (*callback)(u32 event, u32 ssid, u32 tsid,
  104. u16 tclass, u32 perms,
  105. u32 *out_retained),
  106. u32 events, u32 ssid, u32 tsid,
  107. u16 tclass, u32 perms);
  108. /* Exported to selinuxfs */
  109. int avc_get_hash_stats(char *page);
  110. extern unsigned int avc_cache_threshold;
  111. /* Attempt to free avc node cache */
  112. void avc_disable(void);
  113. #ifdef CONFIG_SECURITY_SELINUX_AVC_STATS
  114. DECLARE_PER_CPU(struct avc_cache_stats, avc_cache_stats);
  115. #endif
  116. #endif /* _SELINUX_AVC_H_ */