Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Security server interface. | |
3 | * | |
4 | * Author : Stephen Smalley, <sds@epoch.ncsc.mil> | |
5 | * | |
6 | */ | |
7 | ||
8 | #ifndef _SELINUX_SECURITY_H_ | |
9 | #define _SELINUX_SECURITY_H_ | |
10 | ||
652bb9b0 | 11 | #include <linux/dcache.h> |
75834fc3 | 12 | #include <linux/magic.h> |
2606fd1f | 13 | #include <linux/types.h> |
1da177e4 LT |
14 | #include "flask.h" |
15 | ||
16 | #define SECSID_NULL 0x00000000 /* unspecified SID */ | |
17 | #define SECSID_WILD 0xffffffff /* wildcard SID */ | |
18 | #define SECCLASS_NULL 0x0000 /* no class */ | |
19 | ||
1da177e4 LT |
20 | /* Identify specific policy version changes */ |
21 | #define POLICYDB_VERSION_BASE 15 | |
22 | #define POLICYDB_VERSION_BOOL 16 | |
23 | #define POLICYDB_VERSION_IPV6 17 | |
24 | #define POLICYDB_VERSION_NLCLASS 18 | |
25 | #define POLICYDB_VERSION_VALIDATETRANS 19 | |
26 | #define POLICYDB_VERSION_MLS 19 | |
782ebb99 | 27 | #define POLICYDB_VERSION_AVTAB 20 |
f3f87714 | 28 | #define POLICYDB_VERSION_RANGETRANS 21 |
3bb56b25 | 29 | #define POLICYDB_VERSION_POLCAP 22 |
64dbf074 | 30 | #define POLICYDB_VERSION_PERMISSIVE 23 |
d9250dea | 31 | #define POLICYDB_VERSION_BOUNDARY 24 |
652bb9b0 | 32 | #define POLICYDB_VERSION_FILENAME_TRANS 25 |
8023976c | 33 | #define POLICYDB_VERSION_ROLETRANS 26 |
aa893269 | 34 | #define POLICYDB_VERSION_NEW_OBJECT_DEFAULTS 27 |
eed7795d | 35 | #define POLICYDB_VERSION_DEFAULT_TYPE 28 |
949c2c1d S |
36 | #define POLICYDB_VERSION_CONSTRAINT_NAMES 29 |
37 | #define POLICYDB_VERSION_XPERMS_IOCTL 30 | |
1da177e4 LT |
38 | |
39 | /* Range of policy versions we understand*/ | |
40 | #define POLICYDB_VERSION_MIN POLICYDB_VERSION_BASE | |
016b9bdb SS |
41 | #ifdef CONFIG_SECURITY_SELINUX_POLICYDB_VERSION_MAX |
42 | #define POLICYDB_VERSION_MAX CONFIG_SECURITY_SELINUX_POLICYDB_VERSION_MAX_VALUE | |
43 | #else | |
949c2c1d | 44 | #define POLICYDB_VERSION_MAX POLICYDB_VERSION_XPERMS_IOCTL |
016b9bdb | 45 | #endif |
1da177e4 | 46 | |
0d90a7ec DQ |
47 | /* Mask for just the mount related flags */ |
48 | #define SE_MNTMASK 0x0f | |
49 | /* Super block security struct flags for mount options */ | |
e0007529 EP |
50 | #define CONTEXT_MNT 0x01 |
51 | #define FSCONTEXT_MNT 0x02 | |
52 | #define ROOTCONTEXT_MNT 0x04 | |
53 | #define DEFCONTEXT_MNT 0x08 | |
0d90a7ec DQ |
54 | /* Non-mount related flags */ |
55 | #define SE_SBINITIALIZED 0x10 | |
56 | #define SE_SBPROC 0x20 | |
11689d47 | 57 | #define SE_SBLABELSUPP 0x40 |
e0007529 | 58 | |
832cbd9a EP |
59 | #define CONTEXT_STR "context=" |
60 | #define FSCONTEXT_STR "fscontext=" | |
61 | #define ROOTCONTEXT_STR "rootcontext=" | |
62 | #define DEFCONTEXT_STR "defcontext=" | |
11689d47 | 63 | #define LABELSUPP_STR "seclabel" |
832cbd9a | 64 | |
5778eabd | 65 | struct netlbl_lsm_secattr; |
bb22f580 | 66 | |
1da177e4 | 67 | extern int selinux_enabled; |
1da177e4 | 68 | |
3bb56b25 PM |
69 | /* Policy capabilities */ |
70 | enum { | |
71 | POLICYDB_CAPABILITY_NETPEER, | |
b0c636b9 | 72 | POLICYDB_CAPABILITY_OPENPERM, |
3bb56b25 PM |
73 | __POLICYDB_CAPABILITY_MAX |
74 | }; | |
75 | #define POLICYDB_CAPABILITY_MAX (__POLICYDB_CAPABILITY_MAX - 1) | |
76 | ||
77 | extern int selinux_policycap_netpeer; | |
b0c636b9 | 78 | extern int selinux_policycap_openperm; |
3bb56b25 | 79 | |
d9250dea KK |
80 | /* |
81 | * type_datum properties | |
82 | * available at the kernel policy version >= POLICYDB_VERSION_BOUNDARY | |
83 | */ | |
84 | #define TYPEDATUM_PROPERTY_PRIMARY 0x0001 | |
85 | #define TYPEDATUM_PROPERTY_ATTRIBUTE 0x0002 | |
86 | ||
87 | /* limitation of boundary depth */ | |
88 | #define POLICYDB_BOUNDS_MAXDEPTH 4 | |
89 | ||
0719aaf5 GT |
90 | int security_mls_enabled(void); |
91 | ||
b19d8eae | 92 | int security_load_policy(void *data, size_t len); |
6b697323 | 93 | int security_read_policy(void **data, size_t *len); |
cee74f47 | 94 | size_t security_policydb_len(void); |
1da177e4 | 95 | |
3bb56b25 PM |
96 | int security_policycap_supported(unsigned int req_cap); |
97 | ||
e47c8fc5 | 98 | #define SEL_VEC_MAX 32 |
1da177e4 LT |
99 | struct av_decision { |
100 | u32 allowed; | |
1da177e4 LT |
101 | u32 auditallow; |
102 | u32 auditdeny; | |
103 | u32 seqno; | |
8a6f83af | 104 | u32 flags; |
1da177e4 LT |
105 | }; |
106 | ||
949c2c1d S |
107 | #define XPERMS_ALLOWED 1 |
108 | #define XPERMS_AUDITALLOW 2 | |
109 | #define XPERMS_DONTAUDIT 4 | |
110 | ||
111 | #define security_xperm_set(perms, x) (perms[x >> 5] |= 1 << (x & 0x1f)) | |
112 | #define security_xperm_test(perms, x) (1 & (perms[x >> 5] >> (x & 0x1f))) | |
113 | struct extended_perms_data { | |
114 | u32 p[8]; | |
115 | }; | |
116 | ||
117 | struct extended_perms_decision { | |
118 | u8 used; | |
119 | u8 driver; | |
120 | struct extended_perms_data *allowed; | |
121 | struct extended_perms_data *auditallow; | |
122 | struct extended_perms_data *dontaudit; | |
123 | }; | |
124 | ||
125 | struct extended_perms { | |
126 | u16 len; /* length associated decision chain */ | |
127 | struct extended_perms_data drivers; /* flag drivers that are used */ | |
128 | }; | |
129 | ||
8a6f83af KK |
130 | /* definitions of av_decision.flags */ |
131 | #define AVD_FLAGS_PERMISSIVE 0x0001 | |
64dbf074 | 132 | |
19439d05 | 133 | void security_compute_av(u32 ssid, u32 tsid, |
949c2c1d S |
134 | u16 tclass, struct av_decision *avd, |
135 | struct extended_perms *xperms); | |
136 | ||
137 | void security_compute_xperms_decision(u32 ssid, u32 tsid, u16 tclass, | |
138 | u8 driver, struct extended_perms_decision *xpermd); | |
c6d3aaa4 | 139 | |
19439d05 SS |
140 | void security_compute_av_user(u32 ssid, u32 tsid, |
141 | u16 tclass, struct av_decision *avd); | |
1da177e4 | 142 | |
652bb9b0 EP |
143 | int security_transition_sid(u32 ssid, u32 tsid, u16 tclass, |
144 | const struct qstr *qstr, u32 *out_sid); | |
c6d3aaa4 | 145 | |
f50a3ec9 KK |
146 | int security_transition_sid_user(u32 ssid, u32 tsid, u16 tclass, |
147 | const char *objname, u32 *out_sid); | |
1da177e4 LT |
148 | |
149 | int security_member_sid(u32 ssid, u32 tsid, | |
150 | u16 tclass, u32 *out_sid); | |
151 | ||
152 | int security_change_sid(u32 ssid, u32 tsid, | |
153 | u16 tclass, u32 *out_sid); | |
154 | ||
155 | int security_sid_to_context(u32 sid, char **scontext, | |
156 | u32 *scontext_len); | |
157 | ||
12b29f34 SS |
158 | int security_sid_to_context_force(u32 sid, char **scontext, u32 *scontext_len); |
159 | ||
8f0cfa52 | 160 | int security_context_to_sid(const char *scontext, u32 scontext_len, |
1da177e4 LT |
161 | u32 *out_sid); |
162 | ||
7bf570dc | 163 | int security_context_to_sid_default(const char *scontext, u32 scontext_len, |
869ab514 | 164 | u32 *out_sid, u32 def_sid, gfp_t gfp_flags); |
f5c1d5b2 | 165 | |
12b29f34 SS |
166 | int security_context_to_sid_force(const char *scontext, u32 scontext_len, |
167 | u32 *sid); | |
168 | ||
1da177e4 LT |
169 | int security_get_user_sids(u32 callsid, char *username, |
170 | u32 **sids, u32 *nel); | |
171 | ||
3e112172 | 172 | int security_port_sid(u8 protocol, u16 port, u32 *out_sid); |
1da177e4 | 173 | |
e8bfdb9d | 174 | int security_netif_sid(char *name, u32 *if_sid); |
1da177e4 LT |
175 | |
176 | int security_node_sid(u16 domain, void *addr, u32 addrlen, | |
177 | u32 *out_sid); | |
178 | ||
179 | int security_validate_transition(u32 oldsid, u32 newsid, u32 tasksid, | |
b19d8eae | 180 | u16 tclass); |
1da177e4 | 181 | |
d9250dea KK |
182 | int security_bounded_transition(u32 oldsid, u32 newsid); |
183 | ||
08554d6b VY |
184 | int security_sid_mls_copy(u32 sid, u32 mls_sid, u32 *new_sid); |
185 | ||
220deb96 PM |
186 | int security_net_peersid_resolve(u32 nlbl_sid, u32 nlbl_type, |
187 | u32 xfrm_sid, | |
188 | u32 *peer_sid); | |
189 | ||
55fcf09b CP |
190 | int security_get_classes(char ***classes, int *nclasses); |
191 | int security_get_permissions(char *class, char ***perms, int *nperms); | |
3f12070e EP |
192 | int security_get_reject_unknown(void); |
193 | int security_get_allow_unknown(void); | |
55fcf09b | 194 | |
1da177e4 LT |
195 | #define SECURITY_FS_USE_XATTR 1 /* use xattr */ |
196 | #define SECURITY_FS_USE_TRANS 2 /* use transition SIDs, e.g. devpts/tmpfs */ | |
197 | #define SECURITY_FS_USE_TASK 3 /* use task SIDs, e.g. pipefs/sockfs */ | |
198 | #define SECURITY_FS_USE_GENFS 4 /* use the genfs support */ | |
199 | #define SECURITY_FS_USE_NONE 5 /* no labeling support */ | |
200 | #define SECURITY_FS_USE_MNTPOINT 6 /* use mountpoint labeling */ | |
201 | ||
202 | int security_fs_use(const char *fstype, unsigned int *behavior, | |
089be43e | 203 | u32 *sid); |
1da177e4 LT |
204 | |
205 | int security_genfs_sid(const char *fstype, char *name, u16 sclass, | |
206 | u32 *sid); | |
207 | ||
5778eabd PM |
208 | #ifdef CONFIG_NETLABEL |
209 | int security_netlbl_secattr_to_sid(struct netlbl_lsm_secattr *secattr, | |
5778eabd PM |
210 | u32 *sid); |
211 | ||
212 | int security_netlbl_sid_to_secattr(u32 sid, | |
213 | struct netlbl_lsm_secattr *secattr); | |
214 | #else | |
215 | static inline int security_netlbl_secattr_to_sid( | |
216 | struct netlbl_lsm_secattr *secattr, | |
5778eabd PM |
217 | u32 *sid) |
218 | { | |
219 | return -EIDRM; | |
220 | } | |
221 | ||
222 | static inline int security_netlbl_sid_to_secattr(u32 sid, | |
223 | struct netlbl_lsm_secattr *secattr) | |
224 | { | |
225 | return -ENOENT; | |
226 | } | |
227 | #endif /* CONFIG_NETLABEL */ | |
228 | ||
f0ee2e46 JC |
229 | const char *security_get_initial_sid_context(u32 sid); |
230 | ||
11904167 KK |
231 | /* |
232 | * status notifier using mmap interface | |
233 | */ | |
234 | extern struct page *selinux_kernel_status_page(void); | |
235 | ||
236 | #define SELINUX_KERNEL_STATUS_VERSION 1 | |
36f7f284 | 237 | struct selinux_kernel_status { |
11904167 KK |
238 | u32 version; /* version number of thie structure */ |
239 | u32 sequence; /* sequence number of seqlock logic */ | |
240 | u32 enforcing; /* current setting of enforcing mode */ | |
241 | u32 policyload; /* times of policy reloaded */ | |
242 | u32 deny_unknown; /* current setting of deny_unknown */ | |
243 | /* | |
244 | * The version > 0 supports above members. | |
245 | */ | |
246 | } __attribute__((packed)); | |
247 | ||
248 | extern void selinux_status_update_setenforce(int enforcing); | |
249 | extern void selinux_status_update_policyload(int seqno); | |
cc59a582 | 250 | extern void selinux_complete_init(void); |
58982b74 | 251 | extern int selinux_disable(void); |
ad3fa08c | 252 | extern void exit_sel_fs(void); |
765927b2 | 253 | extern struct path selinux_null; |
ad3fa08c | 254 | extern struct vfsmount *selinuxfs_mount; |
6a3fbe81 JM |
255 | extern void selnl_notify_setenforce(int val); |
256 | extern void selnl_notify_policyload(u32 seqno); | |
257 | extern int selinux_nlmsg_lookup(u16 sclass, u16 nlmsg_type, u32 *perm); | |
11904167 | 258 | |
1da177e4 LT |
259 | #endif /* _SELINUX_SECURITY_H_ */ |
260 |