security.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 "flask.h"
  10. #define SECSID_NULL 0x00000000 /* unspecified SID */
  11. #define SECSID_WILD 0xffffffff /* wildcard SID */
  12. #define SECCLASS_NULL 0x0000 /* no class */
  13. #define SELINUX_MAGIC 0xf97cff8c
  14. /* Identify specific policy version changes */
  15. #define POLICYDB_VERSION_BASE 15
  16. #define POLICYDB_VERSION_BOOL 16
  17. #define POLICYDB_VERSION_IPV6 17
  18. #define POLICYDB_VERSION_NLCLASS 18
  19. #define POLICYDB_VERSION_VALIDATETRANS 19
  20. #define POLICYDB_VERSION_MLS 19
  21. #define POLICYDB_VERSION_AVTAB 20
  22. #define POLICYDB_VERSION_RANGETRANS 21
  23. #define POLICYDB_VERSION_POLCAP 22
  24. #define POLICYDB_VERSION_PERMISSIVE 23
  25. #define POLICYDB_VERSION_BOUNDARY 24
  26. /* Range of policy versions we understand*/
  27. #define POLICYDB_VERSION_MIN POLICYDB_VERSION_BASE
  28. #ifdef CONFIG_SECURITY_SELINUX_POLICYDB_VERSION_MAX
  29. #define POLICYDB_VERSION_MAX CONFIG_SECURITY_SELINUX_POLICYDB_VERSION_MAX_VALUE
  30. #else
  31. #define POLICYDB_VERSION_MAX POLICYDB_VERSION_BOUNDARY
  32. #endif
  33. #define CONTEXT_MNT 0x01
  34. #define FSCONTEXT_MNT 0x02
  35. #define ROOTCONTEXT_MNT 0x04
  36. #define DEFCONTEXT_MNT 0x08
  37. #define CONTEXT_STR "context="
  38. #define FSCONTEXT_STR "fscontext="
  39. #define ROOTCONTEXT_STR "rootcontext="
  40. #define DEFCONTEXT_STR "defcontext="
  41. struct netlbl_lsm_secattr;
  42. extern int selinux_enabled;
  43. extern int selinux_mls_enabled;
  44. /* Policy capabilities */
  45. enum {
  46. POLICYDB_CAPABILITY_NETPEER,
  47. POLICYDB_CAPABILITY_OPENPERM,
  48. __POLICYDB_CAPABILITY_MAX
  49. };
  50. #define POLICYDB_CAPABILITY_MAX (__POLICYDB_CAPABILITY_MAX - 1)
  51. extern int selinux_policycap_netpeer;
  52. extern int selinux_policycap_openperm;
  53. /*
  54. * type_datum properties
  55. * available at the kernel policy version >= POLICYDB_VERSION_BOUNDARY
  56. */
  57. #define TYPEDATUM_PROPERTY_PRIMARY 0x0001
  58. #define TYPEDATUM_PROPERTY_ATTRIBUTE 0x0002
  59. /* limitation of boundary depth */
  60. #define POLICYDB_BOUNDS_MAXDEPTH 4
  61. int security_load_policy(void *data, size_t len);
  62. int security_policycap_supported(unsigned int req_cap);
  63. #define SEL_VEC_MAX 32
  64. struct av_decision {
  65. u32 allowed;
  66. u32 decided;
  67. u32 auditallow;
  68. u32 auditdeny;
  69. u32 seqno;
  70. };
  71. int security_permissive_sid(u32 sid);
  72. int security_compute_av(u32 ssid, u32 tsid,
  73. u16 tclass, u32 requested,
  74. struct av_decision *avd);
  75. int security_transition_sid(u32 ssid, u32 tsid,
  76. u16 tclass, u32 *out_sid);
  77. int security_member_sid(u32 ssid, u32 tsid,
  78. u16 tclass, u32 *out_sid);
  79. int security_change_sid(u32 ssid, u32 tsid,
  80. u16 tclass, u32 *out_sid);
  81. int security_sid_to_context(u32 sid, char **scontext,
  82. u32 *scontext_len);
  83. int security_sid_to_context_force(u32 sid, char **scontext, u32 *scontext_len);
  84. int security_context_to_sid(const char *scontext, u32 scontext_len,
  85. u32 *out_sid);
  86. int security_context_to_sid_default(const char *scontext, u32 scontext_len,
  87. u32 *out_sid, u32 def_sid, gfp_t gfp_flags);
  88. int security_context_to_sid_force(const char *scontext, u32 scontext_len,
  89. u32 *sid);
  90. int security_get_user_sids(u32 callsid, char *username,
  91. u32 **sids, u32 *nel);
  92. int security_port_sid(u8 protocol, u16 port, u32 *out_sid);
  93. int security_netif_sid(char *name, u32 *if_sid);
  94. int security_node_sid(u16 domain, void *addr, u32 addrlen,
  95. u32 *out_sid);
  96. int security_validate_transition(u32 oldsid, u32 newsid, u32 tasksid,
  97. u16 tclass);
  98. int security_bounded_transition(u32 oldsid, u32 newsid);
  99. int security_sid_mls_copy(u32 sid, u32 mls_sid, u32 *new_sid);
  100. int security_net_peersid_resolve(u32 nlbl_sid, u32 nlbl_type,
  101. u32 xfrm_sid,
  102. u32 *peer_sid);
  103. int security_get_classes(char ***classes, int *nclasses);
  104. int security_get_permissions(char *class, char ***perms, int *nperms);
  105. int security_get_reject_unknown(void);
  106. int security_get_allow_unknown(void);
  107. #define SECURITY_FS_USE_XATTR 1 /* use xattr */
  108. #define SECURITY_FS_USE_TRANS 2 /* use transition SIDs, e.g. devpts/tmpfs */
  109. #define SECURITY_FS_USE_TASK 3 /* use task SIDs, e.g. pipefs/sockfs */
  110. #define SECURITY_FS_USE_GENFS 4 /* use the genfs support */
  111. #define SECURITY_FS_USE_NONE 5 /* no labeling support */
  112. #define SECURITY_FS_USE_MNTPOINT 6 /* use mountpoint labeling */
  113. int security_fs_use(const char *fstype, unsigned int *behavior,
  114. u32 *sid);
  115. int security_genfs_sid(const char *fstype, char *name, u16 sclass,
  116. u32 *sid);
  117. #ifdef CONFIG_NETLABEL
  118. int security_netlbl_secattr_to_sid(struct netlbl_lsm_secattr *secattr,
  119. u32 *sid);
  120. int security_netlbl_sid_to_secattr(u32 sid,
  121. struct netlbl_lsm_secattr *secattr);
  122. #else
  123. static inline int security_netlbl_secattr_to_sid(
  124. struct netlbl_lsm_secattr *secattr,
  125. u32 *sid)
  126. {
  127. return -EIDRM;
  128. }
  129. static inline int security_netlbl_sid_to_secattr(u32 sid,
  130. struct netlbl_lsm_secattr *secattr)
  131. {
  132. return -ENOENT;
  133. }
  134. #endif /* CONFIG_NETLABEL */
  135. const char *security_get_initial_sid_context(u32 sid);
  136. #endif /* _SELINUX_SECURITY_H_ */