security.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /*
  2. * Security server interface.
  3. *
  4. * Author : Stephen Smalley, <sds@epoch.ncsc.mil>
  5. *
  6. */
  7. #ifndef _SELINUX_SECURITY_H_
  8. #define _SELINUX_SECURITY_H_
  9. #include <linux/compiler.h>
  10. #include <linux/dcache.h>
  11. #include <linux/magic.h>
  12. #include <linux/types.h>
  13. #include "flask.h"
  14. #define SECSID_NULL 0x00000000 /* unspecified SID */
  15. #define SECSID_WILD 0xffffffff /* wildcard SID */
  16. #define SECCLASS_NULL 0x0000 /* no class */
  17. /* Identify specific policy version changes */
  18. #define POLICYDB_VERSION_BASE 15
  19. #define POLICYDB_VERSION_BOOL 16
  20. #define POLICYDB_VERSION_IPV6 17
  21. #define POLICYDB_VERSION_NLCLASS 18
  22. #define POLICYDB_VERSION_VALIDATETRANS 19
  23. #define POLICYDB_VERSION_MLS 19
  24. #define POLICYDB_VERSION_AVTAB 20
  25. #define POLICYDB_VERSION_RANGETRANS 21
  26. #define POLICYDB_VERSION_POLCAP 22
  27. #define POLICYDB_VERSION_PERMISSIVE 23
  28. #define POLICYDB_VERSION_BOUNDARY 24
  29. #define POLICYDB_VERSION_FILENAME_TRANS 25
  30. #define POLICYDB_VERSION_ROLETRANS 26
  31. #define POLICYDB_VERSION_NEW_OBJECT_DEFAULTS 27
  32. #define POLICYDB_VERSION_DEFAULT_TYPE 28
  33. #define POLICYDB_VERSION_CONSTRAINT_NAMES 29
  34. #define POLICYDB_VERSION_XPERMS_IOCTL 30
  35. /* Range of policy versions we understand*/
  36. #define POLICYDB_VERSION_MIN POLICYDB_VERSION_BASE
  37. #ifdef CONFIG_SECURITY_SELINUX_POLICYDB_VERSION_MAX
  38. #define POLICYDB_VERSION_MAX CONFIG_SECURITY_SELINUX_POLICYDB_VERSION_MAX_VALUE
  39. #else
  40. #define POLICYDB_VERSION_MAX POLICYDB_VERSION_XPERMS_IOCTL
  41. #endif
  42. /* Mask for just the mount related flags */
  43. #define SE_MNTMASK 0x0f
  44. /* Super block security struct flags for mount options */
  45. #define CONTEXT_MNT 0x01
  46. #define FSCONTEXT_MNT 0x02
  47. #define ROOTCONTEXT_MNT 0x04
  48. #define DEFCONTEXT_MNT 0x08
  49. /* Non-mount related flags */
  50. #define SE_SBINITIALIZED 0x10
  51. #define SE_SBPROC 0x20
  52. #define SE_SBLABELSUPP 0x40
  53. #define SE_SBGENFS 0x80
  54. #define CONTEXT_STR "context="
  55. #define FSCONTEXT_STR "fscontext="
  56. #define ROOTCONTEXT_STR "rootcontext="
  57. #define DEFCONTEXT_STR "defcontext="
  58. #define LABELSUPP_STR "seclabel"
  59. struct netlbl_lsm_secattr;
  60. extern int selinux_enabled;
  61. /* Policy capabilities */
  62. enum {
  63. POLICYDB_CAPABILITY_NETPEER,
  64. POLICYDB_CAPABILITY_OPENPERM,
  65. __POLICYDB_CAPABILITY_MAX
  66. };
  67. #define POLICYDB_CAPABILITY_MAX (__POLICYDB_CAPABILITY_MAX - 1)
  68. extern int selinux_policycap_netpeer;
  69. extern int selinux_policycap_openperm;
  70. /*
  71. * type_datum properties
  72. * available at the kernel policy version >= POLICYDB_VERSION_BOUNDARY
  73. */
  74. #define TYPEDATUM_PROPERTY_PRIMARY 0x0001
  75. #define TYPEDATUM_PROPERTY_ATTRIBUTE 0x0002
  76. /* limitation of boundary depth */
  77. #define POLICYDB_BOUNDS_MAXDEPTH 4
  78. int security_mls_enabled(void);
  79. int security_load_policy(void *data, size_t len);
  80. int security_read_policy(void **data, size_t *len);
  81. size_t security_policydb_len(void);
  82. int security_policycap_supported(unsigned int req_cap);
  83. #define SEL_VEC_MAX 32
  84. struct av_decision {
  85. u32 allowed;
  86. u32 auditallow;
  87. u32 auditdeny;
  88. u32 seqno;
  89. u32 flags;
  90. };
  91. #define XPERMS_ALLOWED 1
  92. #define XPERMS_AUDITALLOW 2
  93. #define XPERMS_DONTAUDIT 4
  94. #define security_xperm_set(perms, x) (perms[x >> 5] |= 1 << (x & 0x1f))
  95. #define security_xperm_test(perms, x) (1 & (perms[x >> 5] >> (x & 0x1f)))
  96. struct extended_perms_data {
  97. u32 p[8];
  98. };
  99. struct extended_perms_decision {
  100. u8 used;
  101. u8 driver;
  102. struct extended_perms_data *allowed;
  103. struct extended_perms_data *auditallow;
  104. struct extended_perms_data *dontaudit;
  105. };
  106. struct extended_perms {
  107. u16 len; /* length associated decision chain */
  108. struct extended_perms_data drivers; /* flag drivers that are used */
  109. };
  110. /* definitions of av_decision.flags */
  111. // START_SEC_SELINUX_PORTING_COMMON
  112. #ifdef CONFIG_ALWAYS_ENFORCE
  113. #define AVD_FLAGS_PERMISSIVE 0x0000
  114. #else
  115. #define AVD_FLAGS_PERMISSIVE 0x0001
  116. #endif
  117. // END_SEC_SELINUX_PORTING_COMMON
  118. void security_compute_av(u32 ssid, u32 tsid,
  119. u16 tclass, struct av_decision *avd,
  120. struct extended_perms *xperms);
  121. void security_compute_xperms_decision(u32 ssid, u32 tsid, u16 tclass,
  122. u8 driver, struct extended_perms_decision *xpermd);
  123. void security_compute_av_user(u32 ssid, u32 tsid,
  124. u16 tclass, struct av_decision *avd);
  125. int security_transition_sid(u32 ssid, u32 tsid, u16 tclass,
  126. const struct qstr *qstr, u32 *out_sid);
  127. int security_transition_sid_user(u32 ssid, u32 tsid, u16 tclass,
  128. const char *objname, u32 *out_sid);
  129. int security_member_sid(u32 ssid, u32 tsid,
  130. u16 tclass, u32 *out_sid);
  131. int security_change_sid(u32 ssid, u32 tsid,
  132. u16 tclass, u32 *out_sid);
  133. int security_sid_to_context(u32 sid, char **scontext,
  134. u32 *scontext_len);
  135. int security_sid_to_context_force(u32 sid, char **scontext, u32 *scontext_len);
  136. int security_context_to_sid(const char *scontext, u32 scontext_len,
  137. u32 *out_sid);
  138. int security_context_to_sid_default(const char *scontext, u32 scontext_len,
  139. u32 *out_sid, u32 def_sid, gfp_t gfp_flags);
  140. int security_context_to_sid_force(const char *scontext, u32 scontext_len,
  141. u32 *sid);
  142. int security_get_user_sids(u32 callsid, char *username,
  143. u32 **sids, u32 *nel);
  144. int security_port_sid(u8 protocol, u16 port, u32 *out_sid);
  145. int security_netif_sid(char *name, u32 *if_sid);
  146. int security_node_sid(u16 domain, void *addr, u32 addrlen,
  147. u32 *out_sid);
  148. int security_validate_transition(u32 oldsid, u32 newsid, u32 tasksid,
  149. u16 tclass);
  150. int security_bounded_transition(u32 oldsid, u32 newsid);
  151. int security_sid_mls_copy(u32 sid, u32 mls_sid, u32 *new_sid);
  152. int security_net_peersid_resolve(u32 nlbl_sid, u32 nlbl_type,
  153. u32 xfrm_sid,
  154. u32 *peer_sid);
  155. int security_get_classes(char ***classes, int *nclasses);
  156. int security_get_permissions(char *class, char ***perms, int *nperms);
  157. int security_get_reject_unknown(void);
  158. int security_get_allow_unknown(void);
  159. #define SECURITY_FS_USE_XATTR 1 /* use xattr */
  160. #define SECURITY_FS_USE_TRANS 2 /* use transition SIDs, e.g. devpts/tmpfs */
  161. #define SECURITY_FS_USE_TASK 3 /* use task SIDs, e.g. pipefs/sockfs */
  162. #define SECURITY_FS_USE_GENFS 4 /* use the genfs support */
  163. #define SECURITY_FS_USE_NONE 5 /* no labeling support */
  164. #define SECURITY_FS_USE_MNTPOINT 6 /* use mountpoint labeling */
  165. int security_fs_use(const char *fstype, unsigned int *behavior,
  166. u32 *sid);
  167. int security_genfs_sid(const char *fstype, char *name, u16 sclass,
  168. u32 *sid);
  169. #ifdef CONFIG_NETLABEL
  170. int security_netlbl_secattr_to_sid(struct netlbl_lsm_secattr *secattr,
  171. u32 *sid);
  172. int security_netlbl_sid_to_secattr(u32 sid,
  173. struct netlbl_lsm_secattr *secattr);
  174. #else
  175. static inline int security_netlbl_secattr_to_sid(
  176. struct netlbl_lsm_secattr *secattr,
  177. u32 *sid)
  178. {
  179. return -EIDRM;
  180. }
  181. static inline int security_netlbl_sid_to_secattr(u32 sid,
  182. struct netlbl_lsm_secattr *secattr)
  183. {
  184. return -ENOENT;
  185. }
  186. #endif /* CONFIG_NETLABEL */
  187. const char *security_get_initial_sid_context(u32 sid);
  188. /*
  189. * status notifier using mmap interface
  190. */
  191. extern struct page *selinux_kernel_status_page(void);
  192. #define SELINUX_KERNEL_STATUS_VERSION 1
  193. struct selinux_kernel_status {
  194. u32 version; /* version number of thie structure */
  195. u32 sequence; /* sequence number of seqlock logic */
  196. u32 enforcing; /* current setting of enforcing mode */
  197. u32 policyload; /* times of policy reloaded */
  198. u32 deny_unknown; /* current setting of deny_unknown */
  199. /*
  200. * The version > 0 supports above members.
  201. */
  202. } __packed;
  203. extern void selinux_status_update_setenforce(int enforcing);
  204. extern void selinux_status_update_policyload(int seqno);
  205. extern void selinux_complete_init(void);
  206. extern int selinux_disable(void);
  207. extern void exit_sel_fs(void);
  208. extern struct dentry *selinux_null;
  209. extern struct vfsmount *selinuxfs_mount;
  210. extern void selnl_notify_setenforce(int val);
  211. extern void selnl_notify_policyload(u32 seqno);
  212. extern int selinux_nlmsg_lookup(u16 sclass, u16 nlmsg_type, u32 *perm);
  213. #endif /* _SELINUX_SECURITY_H_ */