selinux.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * SELinux services exported to the rest of the kernel.
  3. *
  4. * Author: James Morris <jmorris@redhat.com>
  5. *
  6. * Copyright (C) 2005 Red Hat, Inc., James Morris <jmorris@redhat.com>
  7. * Copyright (C) 2006 Trusted Computer Solutions, Inc. <dgoeddel@trustedcs.com>
  8. * Copyright (C) 2006 IBM Corporation, Timothy R. Chavez <tinytim@us.ibm.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2,
  12. * as published by the Free Software Foundation.
  13. */
  14. #ifndef _LINUX_SELINUX_H
  15. #define _LINUX_SELINUX_H
  16. struct selinux_audit_rule;
  17. struct audit_context;
  18. struct kern_ipc_perm;
  19. #ifdef CONFIG_SECURITY_SELINUX
  20. /**
  21. * selinux_audit_rule_init - alloc/init an selinux audit rule structure.
  22. * @field: the field this rule refers to
  23. * @op: the operater the rule uses
  24. * @rulestr: the text "target" of the rule
  25. * @rule: pointer to the new rule structure returned via this
  26. *
  27. * Returns 0 if successful, -errno if not. On success, the rule structure
  28. * will be allocated internally. The caller must free this structure with
  29. * selinux_audit_rule_free() after use.
  30. */
  31. int selinux_audit_rule_init(u32 field, u32 op, char *rulestr,
  32. struct selinux_audit_rule **rule);
  33. /**
  34. * selinux_audit_rule_free - free an selinux audit rule structure.
  35. * @rule: pointer to the audit rule to be freed
  36. *
  37. * This will free all memory associated with the given rule.
  38. * If @rule is NULL, no operation is performed.
  39. */
  40. void selinux_audit_rule_free(struct selinux_audit_rule *rule);
  41. /**
  42. * selinux_audit_rule_match - determine if a context ID matches a rule.
  43. * @sid: the context ID to check
  44. * @field: the field this rule refers to
  45. * @op: the operater the rule uses
  46. * @rule: pointer to the audit rule to check against
  47. * @actx: the audit context (can be NULL) associated with the check
  48. *
  49. * Returns 1 if the context id matches the rule, 0 if it does not, and
  50. * -errno on failure.
  51. */
  52. int selinux_audit_rule_match(u32 sid, u32 field, u32 op,
  53. struct selinux_audit_rule *rule,
  54. struct audit_context *actx);
  55. /**
  56. * selinux_audit_set_callback - set the callback for policy reloads.
  57. * @callback: the function to call when the policy is reloaded
  58. *
  59. * This sets the function callback function that will update the rules
  60. * upon policy reloads. This callback should rebuild all existing rules
  61. * using selinux_audit_rule_init().
  62. */
  63. void selinux_audit_set_callback(int (*callback)(void));
  64. /**
  65. * selinux_string_to_sid - map a security context string to a security ID
  66. * @str: the security context string to be mapped
  67. * @sid: ID value returned via this.
  68. *
  69. * Returns 0 if successful, with the SID stored in sid. A value
  70. * of zero for sid indicates no SID could be determined (but no error
  71. * occurred).
  72. */
  73. int selinux_string_to_sid(char *str, u32 *sid);
  74. /**
  75. * selinux_secmark_relabel_packet_permission - secmark permission check
  76. * @sid: SECMARK ID value to be applied to network packet
  77. *
  78. * Returns 0 if the current task is allowed to set the SECMARK label of
  79. * packets with the supplied security ID. Note that it is implicit that
  80. * the packet is always being relabeled from the default unlabeled value,
  81. * and that the access control decision is made in the AVC.
  82. */
  83. int selinux_secmark_relabel_packet_permission(u32 sid);
  84. /**
  85. * selinux_secmark_refcount_inc - increments the secmark use counter
  86. *
  87. * SELinux keeps track of the current SECMARK targets in use so it knows
  88. * when to apply SECMARK label access checks to network packets. This
  89. * function incements this reference count to indicate that a new SECMARK
  90. * target has been configured.
  91. */
  92. void selinux_secmark_refcount_inc(void);
  93. /**
  94. * selinux_secmark_refcount_dec - decrements the secmark use counter
  95. *
  96. * SELinux keeps track of the current SECMARK targets in use so it knows
  97. * when to apply SECMARK label access checks to network packets. This
  98. * function decements this reference count to indicate that one of the
  99. * existing SECMARK targets has been removed/flushed.
  100. */
  101. void selinux_secmark_refcount_dec(void);
  102. #else
  103. static inline int selinux_audit_rule_init(u32 field, u32 op,
  104. char *rulestr,
  105. struct selinux_audit_rule **rule)
  106. {
  107. return -EOPNOTSUPP;
  108. }
  109. static inline void selinux_audit_rule_free(struct selinux_audit_rule *rule)
  110. {
  111. return;
  112. }
  113. static inline int selinux_audit_rule_match(u32 sid, u32 field, u32 op,
  114. struct selinux_audit_rule *rule,
  115. struct audit_context *actx)
  116. {
  117. return 0;
  118. }
  119. static inline void selinux_audit_set_callback(int (*callback)(void))
  120. {
  121. return;
  122. }
  123. static inline int selinux_string_to_sid(const char *str, u32 *sid)
  124. {
  125. *sid = 0;
  126. return 0;
  127. }
  128. static inline int selinux_secmark_relabel_packet_permission(u32 sid)
  129. {
  130. return 0;
  131. }
  132. static inline void selinux_secmark_refcount_inc(void)
  133. {
  134. return;
  135. }
  136. static inline void selinux_secmark_refcount_dec(void)
  137. {
  138. return;
  139. }
  140. #endif /* CONFIG_SECURITY_SELINUX */
  141. #endif /* _LINUX_SELINUX_H */