avc.h 3.0 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/in6.h>
  15. #include <linux/path.h>
  16. #include <asm/system.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. /* Auxiliary data to use in generating the audit record. */
  34. struct avc_audit_data {
  35. char type;
  36. #define AVC_AUDIT_DATA_FS 1
  37. #define AVC_AUDIT_DATA_NET 2
  38. #define AVC_AUDIT_DATA_CAP 3
  39. #define AVC_AUDIT_DATA_IPC 4
  40. struct task_struct *tsk;
  41. union {
  42. struct {
  43. struct path path;
  44. struct inode *inode;
  45. } fs;
  46. struct {
  47. int netif;
  48. struct sock *sk;
  49. u16 family;
  50. __be16 dport;
  51. __be16 sport;
  52. union {
  53. struct {
  54. __be32 daddr;
  55. __be32 saddr;
  56. } v4;
  57. struct {
  58. struct in6_addr daddr;
  59. struct in6_addr saddr;
  60. } v6;
  61. } fam;
  62. } net;
  63. int cap;
  64. int ipc_id;
  65. } u;
  66. };
  67. #define v4info fam.v4
  68. #define v6info fam.v6
  69. /* Initialize an AVC audit data structure. */
  70. #define AVC_AUDIT_DATA_INIT(_d,_t) \
  71. { memset((_d), 0, sizeof(struct avc_audit_data)); (_d)->type = AVC_AUDIT_DATA_##_t; }
  72. /*
  73. * AVC statistics
  74. */
  75. struct avc_cache_stats
  76. {
  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. /* Exported to selinuxfs */
  114. int avc_get_hash_stats(char *page);
  115. extern unsigned int avc_cache_threshold;
  116. #ifdef CONFIG_SECURITY_SELINUX_AVC_STATS
  117. DECLARE_PER_CPU(struct avc_cache_stats, avc_cache_stats);
  118. #endif
  119. #endif /* _SELINUX_AVC_H_ */