avc.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 <asm/system.h>
  16. #include "flask.h"
  17. #include "av_permissions.h"
  18. #include "security.h"
  19. #ifdef CONFIG_SECURITY_SELINUX_DEVELOP
  20. extern int selinux_enforcing;
  21. #else
  22. #define selinux_enforcing 1
  23. #endif
  24. /*
  25. * An entry in the AVC.
  26. */
  27. struct avc_entry;
  28. struct task_struct;
  29. struct vfsmount;
  30. struct dentry;
  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 vfsmount *mnt;
  45. struct dentry *dentry;
  46. struct inode *inode;
  47. } fs;
  48. struct {
  49. char *netif;
  50. struct sock *sk;
  51. u16 family;
  52. u16 dport;
  53. u16 sport;
  54. union {
  55. struct {
  56. u32 daddr;
  57. u32 saddr;
  58. } v4;
  59. struct {
  60. struct in6_addr daddr;
  61. struct in6_addr saddr;
  62. } v6;
  63. } fam;
  64. } net;
  65. int cap;
  66. int ipc_id;
  67. } u;
  68. };
  69. #define v4info fam.v4
  70. #define v6info fam.v6
  71. /* Initialize an AVC audit data structure. */
  72. #define AVC_AUDIT_DATA_INIT(_d,_t) \
  73. { memset((_d), 0, sizeof(struct avc_audit_data)); (_d)->type = AVC_AUDIT_DATA_##_t; }
  74. /*
  75. * AVC statistics
  76. */
  77. struct avc_cache_stats
  78. {
  79. unsigned int lookups;
  80. unsigned int hits;
  81. unsigned int misses;
  82. unsigned int allocations;
  83. unsigned int reclaims;
  84. unsigned int frees;
  85. };
  86. /*
  87. * AVC operations
  88. */
  89. void __init avc_init(void);
  90. void avc_audit(u32 ssid, u32 tsid,
  91. u16 tclass, u32 requested,
  92. struct av_decision *avd, int result, struct avc_audit_data *auditdata);
  93. int avc_has_perm_noaudit(u32 ssid, u32 tsid,
  94. u16 tclass, u32 requested,
  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. #define AVC_CALLBACK_GRANT 1
  100. #define AVC_CALLBACK_TRY_REVOKE 2
  101. #define AVC_CALLBACK_REVOKE 4
  102. #define AVC_CALLBACK_RESET 8
  103. #define AVC_CALLBACK_AUDITALLOW_ENABLE 16
  104. #define AVC_CALLBACK_AUDITALLOW_DISABLE 32
  105. #define AVC_CALLBACK_AUDITDENY_ENABLE 64
  106. #define AVC_CALLBACK_AUDITDENY_DISABLE 128
  107. int avc_add_callback(int (*callback)(u32 event, u32 ssid, u32 tsid,
  108. u16 tclass, u32 perms,
  109. u32 *out_retained),
  110. u32 events, u32 ssid, u32 tsid,
  111. u16 tclass, u32 perms);
  112. /* Exported to selinuxfs */
  113. int avc_get_hash_stats(char *page);
  114. extern unsigned int avc_cache_threshold;
  115. #ifdef CONFIG_SECURITY_SELINUX_AVC_STATS
  116. DECLARE_PER_CPU(struct avc_cache_stats, avc_cache_stats);
  117. #endif
  118. #endif /* _SELINUX_AVC_H_ */