2 * SELinux services exported to the rest of the kernel.
4 * Author: James Morris <jmorris@redhat.com>
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>
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.
14 #ifndef _LINUX_SELINUX_H
15 #define _LINUX_SELINUX_H
17 struct selinux_audit_rule;
21 #ifdef CONFIG_SECURITY_SELINUX
24 * selinux_audit_rule_init - alloc/init an selinux audit rule structure.
25 * @field: the field this rule refers to
26 * @op: the operater the rule uses
27 * @rulestr: the text "target" of the rule
28 * @rule: pointer to the new rule structure returned via this
30 * Returns 0 if successful, -errno if not. On success, the rule structure
31 * will be allocated internally. The caller must free this structure with
32 * selinux_audit_rule_free() after use.
34 int selinux_audit_rule_init(u32 field, u32 op, char *rulestr,
35 struct selinux_audit_rule **rule);
38 * selinux_audit_rule_free - free an selinux audit rule structure.
39 * @rule: pointer to the audit rule to be freed
41 * This will free all memory associated with the given rule.
42 * If @rule is NULL, no operation is performed.
44 void selinux_audit_rule_free(struct selinux_audit_rule *rule);
47 * selinux_audit_rule_match - determine if a context ID matches a rule.
48 * @sid: the context ID to check
49 * @field: the field this rule refers to
50 * @op: the operater the rule uses
51 * @rule: pointer to the audit rule to check against
52 * @actx: the audit context (can be NULL) associated with the check
54 * Returns 1 if the context id matches the rule, 0 if it does not, and
57 int selinux_audit_rule_match(u32 sid, u32 field, u32 op,
58 struct selinux_audit_rule *rule,
59 struct audit_context *actx);
62 * selinux_audit_set_callback - set the callback for policy reloads.
63 * @callback: the function to call when the policy is reloaded
65 * This sets the function callback function that will update the rules
66 * upon policy reloads. This callback should rebuild all existing rules
67 * using selinux_audit_rule_init().
69 void selinux_audit_set_callback(int (*callback)(void));
72 * selinux_string_to_sid - map a security context string to a security ID
73 * @str: the security context string to be mapped
74 * @sid: ID value returned via this.
76 * Returns 0 if successful, with the SID stored in sid. A value
77 * of zero for sid indicates no SID could be determined (but no error
80 int selinux_string_to_sid(char *str, u32 *sid);
83 * selinux_secmark_relabel_packet_permission - secmark permission check
84 * @sid: SECMARK ID value to be applied to network packet
86 * Returns 0 if the current task is allowed to set the SECMARK label of
87 * packets with the supplied security ID. Note that it is implicit that
88 * the packet is always being relabeled from the default unlabeled value,
89 * and that the access control decision is made in the AVC.
91 int selinux_secmark_relabel_packet_permission(u32 sid);
94 * selinux_secmark_refcount_inc - increments the secmark use counter
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 incements this reference count to indicate that a new SECMARK
99 * target has been configured.
101 void selinux_secmark_refcount_inc(void);
104 * selinux_secmark_refcount_dec - decrements the secmark use counter
106 * SELinux keeps track of the current SECMARK targets in use so it knows
107 * when to apply SECMARK label access checks to network packets. This
108 * function decements this reference count to indicate that one of the
109 * existing SECMARK targets has been removed/flushed.
111 void selinux_secmark_refcount_dec(void);
114 static inline int selinux_audit_rule_init(u32 field, u32 op,
116 struct selinux_audit_rule **rule)
121 static inline void selinux_audit_rule_free(struct selinux_audit_rule *rule)
126 static inline int selinux_audit_rule_match(u32 sid, u32 field, u32 op,
127 struct selinux_audit_rule *rule,
128 struct audit_context *actx)
133 static inline void selinux_audit_set_callback(int (*callback)(void))
138 static inline int selinux_string_to_sid(const char *str, u32 *sid)
144 static inline int selinux_secmark_relabel_packet_permission(u32 sid)
149 static inline void selinux_secmark_refcount_inc(void)
154 static inline void selinux_secmark_refcount_dec(void)
159 #endif /* CONFIG_SECURITY_SELINUX */
161 #endif /* _LINUX_SELINUX_H */