avc.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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/in6.h>
  16. #include <linux/path.h>
  17. #include <asm/system.h>
  18. #include "flask.h"
  19. #include "av_permissions.h"
  20. #include "security.h"
  21. #ifdef CONFIG_SECURITY_SELINUX_DEVELOP
  22. extern int selinux_enforcing;
  23. #else
  24. #define selinux_enforcing 1
  25. #endif
  26. /*
  27. * An entry in the AVC.
  28. */
  29. struct avc_entry;
  30. struct task_struct;
  31. struct inode;
  32. struct sock;
  33. struct sk_buff;
  34. /* Auxiliary data to use in generating the audit record. */
  35. struct avc_audit_data {
  36. char type;
  37. #define AVC_AUDIT_DATA_FS 1
  38. #define AVC_AUDIT_DATA_NET 2
  39. #define AVC_AUDIT_DATA_CAP 3
  40. #define AVC_AUDIT_DATA_IPC 4
  41. struct task_struct *tsk;
  42. union {
  43. struct {
  44. struct path path;
  45. struct inode *inode;
  46. } fs;
  47. struct {
  48. int netif;
  49. struct sock *sk;
  50. u16 family;
  51. __be16 dport;
  52. __be16 sport;
  53. union {
  54. struct {
  55. __be32 daddr;
  56. __be32 saddr;
  57. } v4;
  58. struct {
  59. struct in6_addr daddr;
  60. struct in6_addr saddr;
  61. } v6;
  62. } fam;
  63. } net;
  64. int cap;
  65. int ipc_id;
  66. } u;
  67. };
  68. #define v4info fam.v4
  69. #define v6info fam.v6
  70. /* Initialize an AVC audit data structure. */
  71. #define AVC_AUDIT_DATA_INIT(_d,_t) \
  72. { memset((_d), 0, sizeof(struct avc_audit_data)); (_d)->type = AVC_AUDIT_DATA_##_t; }
  73. /*
  74. * AVC statistics
  75. */
  76. struct avc_cache_stats {
  77. unsigned int lookups;
  78. unsigned int hits;
  79. unsigned int misses;
  80. unsigned int allocations;
  81. unsigned int reclaims;
  82. unsigned int frees;
  83. };
  84. /*
  85. * AVC operations
  86. */
  87. void __init avc_init(void);
  88. void avc_audit(u32 ssid, u32 tsid,
  89. u16 tclass, u32 requested,
  90. struct av_decision *avd, int result, struct avc_audit_data *auditdata);
  91. #define AVC_STRICT 1 /* Ignore permissive mode. */
  92. int avc_has_perm_noaudit(u32 ssid, u32 tsid,
  93. u16 tclass, u32 requested,
  94. unsigned flags,
  95. struct av_decision *avd);
  96. int avc_has_perm(u32 ssid, u32 tsid,
  97. u16 tclass, u32 requested,
  98. struct avc_audit_data *auditdata);
  99. u32 avc_policy_seqno(void);
  100. #define AVC_CALLBACK_GRANT 1
  101. #define AVC_CALLBACK_TRY_REVOKE 2
  102. #define AVC_CALLBACK_REVOKE 4
  103. #define AVC_CALLBACK_RESET 8
  104. #define AVC_CALLBACK_AUDITALLOW_ENABLE 16
  105. #define AVC_CALLBACK_AUDITALLOW_DISABLE 32
  106. #define AVC_CALLBACK_AUDITDENY_ENABLE 64
  107. #define AVC_CALLBACK_AUDITDENY_DISABLE 128
  108. int avc_add_callback(int (*callback)(u32 event, u32 ssid, u32 tsid,
  109. u16 tclass, u32 perms,
  110. u32 *out_retained),
  111. u32 events, u32 ssid, u32 tsid,
  112. u16 tclass, u32 perms);
  113. /* Shows permission in human readable form */
  114. void avc_dump_av(struct audit_buffer *ab, u16 tclass, u32 av);
  115. /* Exported to selinuxfs */
  116. int avc_get_hash_stats(char *page);
  117. extern unsigned int avc_cache_threshold;
  118. #ifdef CONFIG_SECURITY_SELINUX_AVC_STATS
  119. DECLARE_PER_CPU(struct avc_cache_stats, avc_cache_stats);
  120. #endif
  121. #endif /* _SELINUX_AVC_H_ */