xref: /freebsd/sys/security/mac/mac_policy.h (revision 0afa8e065e14bb8fd338d75690e0238c00167d40)
1 /*-
2  * Copyright (c) 1999-2002, 2007-2011 Robert N. M. Watson
3  * Copyright (c) 2001-2005 Networks Associates Technology, Inc.
4  * Copyright (c) 2005-2006 SPARTA, Inc.
5  * Copyright (c) 2008 Apple Inc.
6  * All rights reserved.
7  *
8  * This software was developed by Robert Watson for the TrustedBSD Project.
9  *
10  * This software was developed for the FreeBSD Project in part by Network
11  * Associates Laboratories, the Security Research Division of Network
12  * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
13  * as part of the DARPA CHATS research program.
14  *
15  * This software was enhanced by SPARTA ISSO under SPAWAR contract
16  * N66001-04-C-6019 ("SEFOS").
17  *
18  * This software was developed at the University of Cambridge Computer
19  * Laboratory with support from a grant from Google, Inc.
20  *
21  * Redistribution and use in source and binary forms, with or without
22  * modification, are permitted provided that the following conditions
23  * are met:
24  * 1. Redistributions of source code must retain the above copyright
25  *    notice, this list of conditions and the following disclaimer.
26  * 2. Redistributions in binary form must reproduce the above copyright
27  *    notice, this list of conditions and the following disclaimer in the
28  *    documentation and/or other materials provided with the distribution.
29  *
30  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
31  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
34  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40  * SUCH DAMAGE.
41  *
42  * $FreeBSD$
43  */
44 /*
45  * Kernel interface for MAC policy modules.
46  */
47 #ifndef _SECURITY_MAC_MAC_POLICY_H_
48 #define	_SECURITY_MAC_MAC_POLICY_H_
49 
50 #ifndef _KERNEL
51 #error "no user-serviceable parts inside"
52 #endif
53 
54 /*-
55  * Pluggable access control policy definition structure.
56  *
57  * List of operations that are performed as part of the implementation of a
58  * MAC policy.  Policy implementors declare operations with a mac_policy_ops
59  * structure, and using the MAC_POLICY_SET() macro.  If an entry point is not
60  * declared, then then the policy will be ignored during evaluation of that
61  * event or check.
62  *
63  * Operations are sorted first by general class of operation, then
64  * alphabetically.
65  */
66 #include <sys/acl.h>	/* XXX acl_type_t */
67 #include <sys/types.h>	/* XXX accmode_t */
68 
69 struct acl;
70 struct auditinfo;
71 struct auditinfo_addr;
72 struct bpf_d;
73 struct cdev;
74 struct componentname;
75 struct devfs_dirent;
76 struct ifnet;
77 struct image_params;
78 struct inpcb;
79 struct ip6q;
80 struct ipq;
81 struct ksem;
82 struct label;
83 struct mac_policy_conf;
84 struct mbuf;
85 struct mount;
86 struct msg;
87 struct msqid_kernel;
88 struct pipepair;
89 struct proc;
90 struct sbuf;
91 struct semid_kernel;
92 struct shmfd;
93 struct shmid_kernel;
94 struct sockaddr;
95 struct socket;
96 struct sysctl_oid;
97 struct sysctl_req;
98 struct thread;
99 struct ucred;
100 struct vattr;
101 struct vnode;
102 
103 /*
104  * Policy module operations.
105  */
106 typedef void	(*mpo_destroy_t)(struct mac_policy_conf *mpc);
107 typedef void	(*mpo_init_t)(struct mac_policy_conf *mpc);
108 
109 /*
110  * General policy-directed security system call so that policies may
111  * implement new services without reserving explicit system call numbers.
112  */
113 typedef int	(*mpo_syscall_t)(struct thread *td, int call, void *arg);
114 
115 /*
116  * Place-holder function pointers for ABI-compatibility purposes.
117  */
118 typedef void	(*mpo_placeholder_t)(void);
119 
120 /*
121  * Operations sorted alphabetically by primary object type and then method.
122  */
123 typedef	int	(*mpo_bpfdesc_check_receive_t)(struct bpf_d *d,
124 		    struct label *dlabel, struct ifnet *ifp,
125 		    struct label *ifplabel);
126 typedef void	(*mpo_bpfdesc_create_t)(struct ucred *cred,
127 		    struct bpf_d *d, struct label *dlabel);
128 typedef void	(*mpo_bpfdesc_create_mbuf_t)(struct bpf_d *d,
129 		    struct label *dlabel, struct mbuf *m,
130 		    struct label *mlabel);
131 typedef void	(*mpo_bpfdesc_destroy_label_t)(struct label *label);
132 typedef void	(*mpo_bpfdesc_init_label_t)(struct label *label);
133 
134 typedef void	(*mpo_cred_associate_nfsd_t)(struct ucred *cred);
135 typedef int	(*mpo_cred_check_relabel_t)(struct ucred *cred,
136 		    struct label *newlabel);
137 typedef int	(*mpo_cred_check_setaudit_t)(struct ucred *cred,
138 		    struct auditinfo *ai);
139 typedef int	(*mpo_cred_check_setaudit_addr_t)(struct ucred *cred,
140 		    struct auditinfo_addr *aia);
141 typedef int	(*mpo_cred_check_setauid_t)(struct ucred *cred, uid_t auid);
142 typedef int	(*mpo_cred_check_setegid_t)(struct ucred *cred, gid_t egid);
143 typedef int	(*mpo_cred_check_seteuid_t)(struct ucred *cred, uid_t euid);
144 typedef int	(*mpo_cred_check_setgid_t)(struct ucred *cred, gid_t gid);
145 typedef int	(*mpo_cred_check_setgroups_t)(struct ucred *cred, int ngroups,
146 		    gid_t *gidset);
147 typedef int	(*mpo_cred_check_setregid_t)(struct ucred *cred, gid_t rgid,
148 		    gid_t egid);
149 typedef int	(*mpo_cred_check_setresgid_t)(struct ucred *cred, gid_t rgid,
150 		    gid_t egid, gid_t sgid);
151 typedef int	(*mpo_cred_check_setresuid_t)(struct ucred *cred, uid_t ruid,
152 		    uid_t euid, uid_t suid);
153 typedef int	(*mpo_cred_check_setreuid_t)(struct ucred *cred, uid_t ruid,
154 		    uid_t euid);
155 typedef int	(*mpo_cred_check_setuid_t)(struct ucred *cred, uid_t uid);
156 typedef int	(*mpo_cred_check_visible_t)(struct ucred *cr1,
157 		    struct ucred *cr2);
158 typedef void	(*mpo_cred_copy_label_t)(struct label *src,
159 		    struct label *dest);
160 typedef void	(*mpo_cred_create_init_t)(struct ucred *cred);
161 typedef void	(*mpo_cred_create_swapper_t)(struct ucred *cred);
162 typedef void	(*mpo_cred_destroy_label_t)(struct label *label);
163 typedef int	(*mpo_cred_externalize_label_t)(struct label *label,
164 		    char *element_name, struct sbuf *sb, int *claimed);
165 typedef void	(*mpo_cred_init_label_t)(struct label *label);
166 typedef int	(*mpo_cred_internalize_label_t)(struct label *label,
167 		    char *element_name, char *element_data, int *claimed);
168 typedef void	(*mpo_cred_relabel_t)(struct ucred *cred,
169 		    struct label *newlabel);
170 
171 typedef void	(*mpo_devfs_create_device_t)(struct ucred *cred,
172 		    struct mount *mp, struct cdev *dev,
173 		    struct devfs_dirent *de, struct label *delabel);
174 typedef void	(*mpo_devfs_create_directory_t)(struct mount *mp,
175 		    char *dirname, int dirnamelen, struct devfs_dirent *de,
176 		    struct label *delabel);
177 typedef void	(*mpo_devfs_create_symlink_t)(struct ucred *cred,
178 		    struct mount *mp, struct devfs_dirent *dd,
179 		    struct label *ddlabel, struct devfs_dirent *de,
180 		    struct label *delabel);
181 typedef void	(*mpo_devfs_destroy_label_t)(struct label *label);
182 typedef void	(*mpo_devfs_init_label_t)(struct label *label);
183 typedef void	(*mpo_devfs_update_t)(struct mount *mp,
184 		    struct devfs_dirent *de, struct label *delabel,
185 		    struct vnode *vp, struct label *vplabel);
186 typedef void	(*mpo_devfs_vnode_associate_t)(struct mount *mp,
187 		    struct label *mplabel, struct devfs_dirent *de,
188 		    struct label *delabel, struct vnode *vp,
189 		    struct label *vplabel);
190 
191 typedef int	(*mpo_ifnet_check_relabel_t)(struct ucred *cred,
192 		    struct ifnet *ifp, struct label *ifplabel,
193 		    struct label *newlabel);
194 typedef int	(*mpo_ifnet_check_transmit_t)(struct ifnet *ifp,
195 		    struct label *ifplabel, struct mbuf *m,
196 		    struct label *mlabel);
197 typedef void	(*mpo_ifnet_copy_label_t)(struct label *src,
198 		    struct label *dest);
199 typedef void	(*mpo_ifnet_create_t)(struct ifnet *ifp,
200 		    struct label *ifplabel);
201 typedef void	(*mpo_ifnet_create_mbuf_t)(struct ifnet *ifp,
202 		    struct label *ifplabel, struct mbuf *m,
203 		    struct label *mlabel);
204 typedef void	(*mpo_ifnet_destroy_label_t)(struct label *label);
205 typedef int	(*mpo_ifnet_externalize_label_t)(struct label *label,
206 		    char *element_name, struct sbuf *sb, int *claimed);
207 typedef void	(*mpo_ifnet_init_label_t)(struct label *label);
208 typedef int	(*mpo_ifnet_internalize_label_t)(struct label *label,
209 		    char *element_name, char *element_data, int *claimed);
210 typedef void	(*mpo_ifnet_relabel_t)(struct ucred *cred, struct ifnet *ifp,
211 		    struct label *ifplabel, struct label *newlabel);
212 
213 typedef int	(*mpo_inpcb_check_deliver_t)(struct inpcb *inp,
214 		    struct label *inplabel, struct mbuf *m,
215 		    struct label *mlabel);
216 typedef int	(*mpo_inpcb_check_visible_t)(struct ucred *cred,
217 		    struct inpcb *inp, struct label *inplabel);
218 typedef void	(*mpo_inpcb_create_t)(struct socket *so,
219 		    struct label *solabel, struct inpcb *inp,
220 		    struct label *inplabel);
221 typedef void	(*mpo_inpcb_create_mbuf_t)(struct inpcb *inp,
222 		    struct label *inplabel, struct mbuf *m,
223 		    struct label *mlabel);
224 typedef void	(*mpo_inpcb_destroy_label_t)(struct label *label);
225 typedef int	(*mpo_inpcb_init_label_t)(struct label *label, int flag);
226 typedef void	(*mpo_inpcb_sosetlabel_t)(struct socket *so,
227 		    struct label *label, struct inpcb *inp,
228 		    struct label *inplabel);
229 
230 typedef void	(*mpo_ip6q_create_t)(struct mbuf *m, struct label *mlabel,
231 		    struct ip6q *q6, struct label *q6label);
232 typedef void	(*mpo_ip6q_destroy_label_t)(struct label *label);
233 typedef int	(*mpo_ip6q_init_label_t)(struct label *label, int flag);
234 typedef int	(*mpo_ip6q_match_t)(struct mbuf *m, struct label *mlabel,
235 		    struct ip6q *q6, struct label *q6label);
236 typedef void	(*mpo_ip6q_reassemble)(struct ip6q *q6, struct label *q6label,
237 		    struct mbuf *m, struct label *mlabel);
238 typedef void	(*mpo_ip6q_update_t)(struct mbuf *m, struct label *mlabel,
239 		    struct ip6q *q6, struct label *q6label);
240 
241 typedef void	(*mpo_ipq_create_t)(struct mbuf *m, struct label *mlabel,
242 		    struct ipq *q, struct label *qlabel);
243 typedef void	(*mpo_ipq_destroy_label_t)(struct label *label);
244 typedef int	(*mpo_ipq_init_label_t)(struct label *label, int flag);
245 typedef int	(*mpo_ipq_match_t)(struct mbuf *m, struct label *mlabel,
246 		    struct ipq *q, struct label *qlabel);
247 typedef void	(*mpo_ipq_reassemble)(struct ipq *q, struct label *qlabel,
248 		    struct mbuf *m, struct label *mlabel);
249 typedef void	(*mpo_ipq_update_t)(struct mbuf *m, struct label *mlabel,
250 		    struct ipq *q, struct label *qlabel);
251 
252 typedef int	(*mpo_kenv_check_dump_t)(struct ucred *cred);
253 typedef int	(*mpo_kenv_check_get_t)(struct ucred *cred, char *name);
254 typedef int	(*mpo_kenv_check_set_t)(struct ucred *cred, char *name,
255 		    char *value);
256 typedef int	(*mpo_kenv_check_unset_t)(struct ucred *cred, char *name);
257 
258 typedef int	(*mpo_kld_check_load_t)(struct ucred *cred, struct vnode *vp,
259 		    struct label *vplabel);
260 typedef int	(*mpo_kld_check_stat_t)(struct ucred *cred);
261 
262 typedef void	(*mpo_mbuf_copy_label_t)(struct label *src,
263 		    struct label *dest);
264 typedef void	(*mpo_mbuf_destroy_label_t)(struct label *label);
265 typedef int	(*mpo_mbuf_init_label_t)(struct label *label, int flag);
266 
267 typedef int	(*mpo_mount_check_stat_t)(struct ucred *cred,
268 		    struct mount *mp, struct label *mplabel);
269 typedef void	(*mpo_mount_create_t)(struct ucred *cred, struct mount *mp,
270 		    struct label *mplabel);
271 typedef void	(*mpo_mount_destroy_label_t)(struct label *label);
272 typedef void	(*mpo_mount_init_label_t)(struct label *label);
273 
274 typedef void	(*mpo_netinet_arp_send_t)(struct ifnet *ifp,
275 		    struct label *ifplabel, struct mbuf *m,
276 		    struct label *mlabel);
277 typedef void	(*mpo_netinet_firewall_reply_t)(struct mbuf *mrecv,
278 		    struct label *mrecvlabel, struct mbuf *msend,
279 		    struct label *msendlabel);
280 typedef	void	(*mpo_netinet_firewall_send_t)(struct mbuf *m,
281 		    struct label *mlabel);
282 typedef void	(*mpo_netinet_fragment_t)(struct mbuf *m,
283 		    struct label *mlabel, struct mbuf *frag,
284 		    struct label *fraglabel);
285 typedef void	(*mpo_netinet_icmp_reply_t)(struct mbuf *mrecv,
286 		    struct label *mrecvlabel, struct mbuf *msend,
287 		    struct label *msendlabel);
288 typedef void	(*mpo_netinet_icmp_replyinplace_t)(struct mbuf *m,
289 		    struct label *mlabel);
290 typedef void	(*mpo_netinet_igmp_send_t)(struct ifnet *ifp,
291 		    struct label *ifplabel, struct mbuf *m,
292 		    struct label *mlabel);
293 typedef void	(*mpo_netinet_tcp_reply_t)(struct mbuf *m,
294 		    struct label *mlabel);
295 
296 typedef void	(*mpo_netinet6_nd6_send_t)(struct ifnet *ifp,
297 		    struct label *ifplabel, struct mbuf *m,
298 		    struct label *mlabel);
299 
300 typedef int	(*mpo_pipe_check_ioctl_t)(struct ucred *cred,
301 		    struct pipepair *pp, struct label *pplabel,
302 		    unsigned long cmd, void *data);
303 typedef int	(*mpo_pipe_check_poll_t)(struct ucred *cred,
304 		    struct pipepair *pp, struct label *pplabel);
305 typedef int	(*mpo_pipe_check_read_t)(struct ucred *cred,
306 		    struct pipepair *pp, struct label *pplabel);
307 typedef int	(*mpo_pipe_check_relabel_t)(struct ucred *cred,
308 		    struct pipepair *pp, struct label *pplabel,
309 		    struct label *newlabel);
310 typedef int	(*mpo_pipe_check_stat_t)(struct ucred *cred,
311 		    struct pipepair *pp, struct label *pplabel);
312 typedef int	(*mpo_pipe_check_write_t)(struct ucred *cred,
313 		    struct pipepair *pp, struct label *pplabel);
314 typedef void	(*mpo_pipe_copy_label_t)(struct label *src,
315 		    struct label *dest);
316 typedef void	(*mpo_pipe_create_t)(struct ucred *cred, struct pipepair *pp,
317 		    struct label *pplabel);
318 typedef void	(*mpo_pipe_destroy_label_t)(struct label *label);
319 typedef int	(*mpo_pipe_externalize_label_t)(struct label *label,
320 		    char *element_name, struct sbuf *sb, int *claimed);
321 typedef void	(*mpo_pipe_init_label_t)(struct label *label);
322 typedef int	(*mpo_pipe_internalize_label_t)(struct label *label,
323 		    char *element_name, char *element_data, int *claimed);
324 typedef void	(*mpo_pipe_relabel_t)(struct ucred *cred, struct pipepair *pp,
325 		    struct label *oldlabel, struct label *newlabel);
326 
327 typedef int	(*mpo_posixsem_check_getvalue_t)(struct ucred *active_cred,
328 		    struct ucred *file_cred, struct ksem *ks,
329 		    struct label *kslabel);
330 typedef int	(*mpo_posixsem_check_open_t)(struct ucred *cred,
331 		    struct ksem *ks, struct label *kslabel);
332 typedef int	(*mpo_posixsem_check_post_t)(struct ucred *active_cred,
333 		    struct ucred *file_cred, struct ksem *ks,
334 		    struct label *kslabel);
335 typedef int	(*mpo_posixsem_check_setmode_t)(struct ucred *cred,
336 		    struct ksem *ks, struct label *shmlabel,
337 		    mode_t mode);
338 typedef int	(*mpo_posixsem_check_setowner_t)(struct ucred *cred,
339 		    struct ksem *ks, struct label *shmlabel,
340 		    uid_t uid, gid_t gid);
341 typedef int	(*mpo_posixsem_check_stat_t)(struct ucred *active_cred,
342 		    struct ucred *file_cred, struct ksem *ks,
343 		    struct label *kslabel);
344 typedef int	(*mpo_posixsem_check_unlink_t)(struct ucred *cred,
345 		    struct ksem *ks, struct label *kslabel);
346 typedef int	(*mpo_posixsem_check_wait_t)(struct ucred *active_cred,
347 		    struct ucred *file_cred, struct ksem *ks,
348 		    struct label *kslabel);
349 typedef void	(*mpo_posixsem_create_t)(struct ucred *cred,
350 		    struct ksem *ks, struct label *kslabel);
351 typedef void    (*mpo_posixsem_destroy_label_t)(struct label *label);
352 typedef void    (*mpo_posixsem_init_label_t)(struct label *label);
353 
354 typedef int	(*mpo_posixshm_check_create_t)(struct ucred *cred,
355 		    const char *path);
356 typedef int	(*mpo_posixshm_check_mmap_t)(struct ucred *cred,
357 		    struct shmfd *shmfd, struct label *shmlabel, int prot,
358 		    int flags);
359 typedef int	(*mpo_posixshm_check_open_t)(struct ucred *cred,
360 		    struct shmfd *shmfd, struct label *shmlabel,
361 		    accmode_t accmode);
362 typedef int	(*mpo_posixshm_check_read_t)(struct ucred *active_cred,
363 		    struct ucred *file_cred, struct shmfd *shmfd,
364 		    struct label *shmlabel);
365 typedef int	(*mpo_posixshm_check_setmode_t)(struct ucred *cred,
366 		    struct shmfd *shmfd, struct label *shmlabel,
367 		    mode_t mode);
368 typedef int	(*mpo_posixshm_check_setowner_t)(struct ucred *cred,
369 		    struct shmfd *shmfd, struct label *shmlabel,
370 		    uid_t uid, gid_t gid);
371 typedef int	(*mpo_posixshm_check_stat_t)(struct ucred *active_cred,
372 		    struct ucred *file_cred, struct shmfd *shmfd,
373 		    struct label *shmlabel);
374 typedef int	(*mpo_posixshm_check_truncate_t)(struct ucred *active_cred,
375 		    struct ucred *file_cred, struct shmfd *shmfd,
376 		    struct label *shmlabel);
377 typedef int	(*mpo_posixshm_check_unlink_t)(struct ucred *cred,
378 		    struct shmfd *shmfd, struct label *shmlabel);
379 typedef int	(*mpo_posixshm_check_write_t)(struct ucred *active_cred,
380 		    struct ucred *file_cred, struct shmfd *shmfd,
381 		    struct label *shmlabel);
382 typedef void	(*mpo_posixshm_create_t)(struct ucred *cred,
383 		    struct shmfd *shmfd, struct label *shmlabel);
384 typedef void	(*mpo_posixshm_destroy_label_t)(struct label *label);
385 typedef void	(*mpo_posixshm_init_label_t)(struct label *label);
386 
387 typedef int	(*mpo_priv_check_t)(struct ucred *cred, int priv);
388 typedef int	(*mpo_priv_grant_t)(struct ucred *cred, int priv);
389 
390 typedef int	(*mpo_proc_check_debug_t)(struct ucred *cred,
391 		    struct proc *p);
392 typedef int	(*mpo_proc_check_sched_t)(struct ucred *cred,
393 		    struct proc *p);
394 typedef int	(*mpo_proc_check_signal_t)(struct ucred *cred,
395 		    struct proc *proc, int signum);
396 typedef int	(*mpo_proc_check_wait_t)(struct ucred *cred,
397 		    struct proc *proc);
398 typedef void	(*mpo_proc_destroy_label_t)(struct label *label);
399 typedef void	(*mpo_proc_init_label_t)(struct label *label);
400 
401 typedef int	(*mpo_socket_check_accept_t)(struct ucred *cred,
402 		    struct socket *so, struct label *solabel);
403 typedef int	(*mpo_socket_check_bind_t)(struct ucred *cred,
404 		    struct socket *so, struct label *solabel,
405 		    struct sockaddr *sa);
406 typedef int	(*mpo_socket_check_connect_t)(struct ucred *cred,
407 		    struct socket *so, struct label *solabel,
408 		    struct sockaddr *sa);
409 typedef int	(*mpo_socket_check_create_t)(struct ucred *cred, int domain,
410 		    int type, int protocol);
411 typedef int	(*mpo_socket_check_deliver_t)(struct socket *so,
412 		    struct label *solabel, struct mbuf *m,
413 		    struct label *mlabel);
414 typedef int	(*mpo_socket_check_listen_t)(struct ucred *cred,
415 		    struct socket *so, struct label *solabel);
416 typedef int	(*mpo_socket_check_poll_t)(struct ucred *cred,
417 		    struct socket *so, struct label *solabel);
418 typedef int	(*mpo_socket_check_receive_t)(struct ucred *cred,
419 		    struct socket *so, struct label *solabel);
420 typedef int	(*mpo_socket_check_relabel_t)(struct ucred *cred,
421 		    struct socket *so, struct label *solabel,
422 		    struct label *newlabel);
423 typedef int	(*mpo_socket_check_send_t)(struct ucred *cred,
424 		    struct socket *so, struct label *solabel);
425 typedef int	(*mpo_socket_check_stat_t)(struct ucred *cred,
426 		    struct socket *so, struct label *solabel);
427 typedef int	(*mpo_socket_check_visible_t)(struct ucred *cred,
428 		    struct socket *so, struct label *solabel);
429 typedef void	(*mpo_socket_copy_label_t)(struct label *src,
430 		    struct label *dest);
431 typedef void	(*mpo_socket_create_t)(struct ucred *cred, struct socket *so,
432 		    struct label *solabel);
433 typedef void	(*mpo_socket_create_mbuf_t)(struct socket *so,
434 		    struct label *solabel, struct mbuf *m,
435 		    struct label *mlabel);
436 typedef void	(*mpo_socket_destroy_label_t)(struct label *label);
437 typedef int	(*mpo_socket_externalize_label_t)(struct label *label,
438 		    char *element_name, struct sbuf *sb, int *claimed);
439 typedef int	(*mpo_socket_init_label_t)(struct label *label, int flag);
440 typedef int	(*mpo_socket_internalize_label_t)(struct label *label,
441 		    char *element_name, char *element_data, int *claimed);
442 typedef void	(*mpo_socket_newconn_t)(struct socket *oldso,
443 		    struct label *oldsolabel, struct socket *newso,
444 		    struct label *newsolabel);
445 typedef void	(*mpo_socket_relabel_t)(struct ucred *cred, struct socket *so,
446 		    struct label *oldlabel, struct label *newlabel);
447 
448 typedef void	(*mpo_socketpeer_destroy_label_t)(struct label *label);
449 typedef int	(*mpo_socketpeer_externalize_label_t)(struct label *label,
450 		    char *element_name, struct sbuf *sb, int *claimed);
451 typedef int	(*mpo_socketpeer_init_label_t)(struct label *label,
452 		    int flag);
453 typedef void	(*mpo_socketpeer_set_from_mbuf_t)(struct mbuf *m,
454 		    struct label *mlabel, struct socket *so,
455 		    struct label *sopeerlabel);
456 typedef void	(*mpo_socketpeer_set_from_socket_t)(struct socket *oldso,
457 		    struct label *oldsolabel, struct socket *newso,
458 		    struct label *newsopeerlabel);
459 
460 typedef void	(*mpo_syncache_create_t)(struct label *label,
461 		    struct inpcb *inp);
462 typedef void	(*mpo_syncache_create_mbuf_t)(struct label *sc_label,
463 		    struct mbuf *m, struct label *mlabel);
464 typedef void	(*mpo_syncache_destroy_label_t)(struct label *label);
465 typedef int	(*mpo_syncache_init_label_t)(struct label *label, int flag);
466 
467 typedef int	(*mpo_system_check_acct_t)(struct ucred *cred,
468 		    struct vnode *vp, struct label *vplabel);
469 typedef int	(*mpo_system_check_audit_t)(struct ucred *cred, void *record,
470 		    int length);
471 typedef int	(*mpo_system_check_auditctl_t)(struct ucred *cred,
472 		    struct vnode *vp, struct label *vplabel);
473 typedef int	(*mpo_system_check_auditon_t)(struct ucred *cred, int cmd);
474 typedef int	(*mpo_system_check_reboot_t)(struct ucred *cred, int howto);
475 typedef int	(*mpo_system_check_swapon_t)(struct ucred *cred,
476 		    struct vnode *vp, struct label *vplabel);
477 typedef int	(*mpo_system_check_swapoff_t)(struct ucred *cred,
478 		    struct vnode *vp, struct label *vplabel);
479 typedef int	(*mpo_system_check_sysctl_t)(struct ucred *cred,
480 		    struct sysctl_oid *oidp, void *arg1, int arg2,
481 		    struct sysctl_req *req);
482 
483 typedef void	(*mpo_sysvmsg_cleanup_t)(struct label *msglabel);
484 typedef void	(*mpo_sysvmsg_create_t)(struct ucred *cred,
485 		    struct msqid_kernel *msqkptr, struct label *msqlabel,
486 		    struct msg *msgptr, struct label *msglabel);
487 typedef void	(*mpo_sysvmsg_destroy_label_t)(struct label *label);
488 typedef void	(*mpo_sysvmsg_init_label_t)(struct label *label);
489 
490 typedef int	(*mpo_sysvmsq_check_msgmsq_t)(struct ucred *cred,
491 		    struct msg *msgptr, struct label *msglabel,
492 		    struct msqid_kernel *msqkptr, struct label *msqklabel);
493 typedef int	(*mpo_sysvmsq_check_msgrcv_t)(struct ucred *cred,
494 		    struct msg *msgptr, struct label *msglabel);
495 typedef int	(*mpo_sysvmsq_check_msgrmid_t)(struct ucred *cred,
496 		    struct msg *msgptr, struct label *msglabel);
497 typedef int	(*mpo_sysvmsq_check_msqget_t)(struct ucred *cred,
498 		    struct msqid_kernel *msqkptr, struct label *msqklabel);
499 typedef int	(*mpo_sysvmsq_check_msqctl_t)(struct ucred *cred,
500 		    struct msqid_kernel *msqkptr, struct label *msqklabel,
501 		    int cmd);
502 typedef int	(*mpo_sysvmsq_check_msqrcv_t)(struct ucred *cred,
503 		    struct msqid_kernel *msqkptr, struct label *msqklabel);
504 typedef int	(*mpo_sysvmsq_check_msqsnd_t)(struct ucred *cred,
505 		    struct msqid_kernel *msqkptr, struct label *msqklabel);
506 typedef void	(*mpo_sysvmsq_cleanup_t)(struct label *msqlabel);
507 typedef void	(*mpo_sysvmsq_create_t)(struct ucred *cred,
508 		    struct msqid_kernel *msqkptr, struct label *msqlabel);
509 typedef void	(*mpo_sysvmsq_destroy_label_t)(struct label *label);
510 typedef void	(*mpo_sysvmsq_init_label_t)(struct label *label);
511 
512 typedef int	(*mpo_sysvsem_check_semctl_t)(struct ucred *cred,
513 		    struct semid_kernel *semakptr, struct label *semaklabel,
514 		    int cmd);
515 typedef int	(*mpo_sysvsem_check_semget_t)(struct ucred *cred,
516 		    struct semid_kernel *semakptr, struct label *semaklabel);
517 typedef int	(*mpo_sysvsem_check_semop_t)(struct ucred *cred,
518 		    struct semid_kernel *semakptr, struct label *semaklabel,
519 		    size_t accesstype);
520 typedef void	(*mpo_sysvsem_cleanup_t)(struct label *semalabel);
521 typedef void	(*mpo_sysvsem_create_t)(struct ucred *cred,
522 		    struct semid_kernel *semakptr, struct label *semalabel);
523 typedef void	(*mpo_sysvsem_destroy_label_t)(struct label *label);
524 typedef void	(*mpo_sysvsem_init_label_t)(struct label *label);
525 
526 typedef int	(*mpo_sysvshm_check_shmat_t)(struct ucred *cred,
527 		    struct shmid_kernel *shmsegptr,
528 		    struct label *shmseglabel, int shmflg);
529 typedef int	(*mpo_sysvshm_check_shmctl_t)(struct ucred *cred,
530 		    struct shmid_kernel *shmsegptr,
531 		    struct label *shmseglabel, int cmd);
532 typedef int	(*mpo_sysvshm_check_shmdt_t)(struct ucred *cred,
533 		    struct shmid_kernel *shmsegptr,
534 		    struct label *shmseglabel);
535 typedef int	(*mpo_sysvshm_check_shmget_t)(struct ucred *cred,
536 		    struct shmid_kernel *shmsegptr,
537 		    struct label *shmseglabel, int shmflg);
538 typedef void	(*mpo_sysvshm_cleanup_t)(struct label *shmlabel);
539 typedef void	(*mpo_sysvshm_create_t)(struct ucred *cred,
540 		    struct shmid_kernel *shmsegptr, struct label *shmlabel);
541 typedef void	(*mpo_sysvshm_destroy_label_t)(struct label *label);
542 typedef void	(*mpo_sysvshm_init_label_t)(struct label *label);
543 
544 typedef void	(*mpo_thread_userret_t)(struct thread *thread);
545 
546 typedef int	(*mpo_vnode_associate_extattr_t)(struct mount *mp,
547 		    struct label *mplabel, struct vnode *vp,
548 		    struct label *vplabel);
549 typedef void	(*mpo_vnode_associate_singlelabel_t)(struct mount *mp,
550 		    struct label *mplabel, struct vnode *vp,
551 		    struct label *vplabel);
552 typedef int	(*mpo_vnode_check_access_t)(struct ucred *cred,
553 		    struct vnode *vp, struct label *vplabel,
554 		    accmode_t accmode);
555 typedef int	(*mpo_vnode_check_chdir_t)(struct ucred *cred,
556 		    struct vnode *dvp, struct label *dvplabel);
557 typedef int	(*mpo_vnode_check_chroot_t)(struct ucred *cred,
558 		    struct vnode *dvp, struct label *dvplabel);
559 typedef int	(*mpo_vnode_check_create_t)(struct ucred *cred,
560 		    struct vnode *dvp, struct label *dvplabel,
561 		    struct componentname *cnp, struct vattr *vap);
562 typedef int	(*mpo_vnode_check_deleteacl_t)(struct ucred *cred,
563 		    struct vnode *vp, struct label *vplabel,
564 		    acl_type_t type);
565 typedef int	(*mpo_vnode_check_deleteextattr_t)(struct ucred *cred,
566 		    struct vnode *vp, struct label *vplabel,
567 		    int attrnamespace, const char *name);
568 typedef int	(*mpo_vnode_check_exec_t)(struct ucred *cred,
569 		    struct vnode *vp, struct label *vplabel,
570 		    struct image_params *imgp, struct label *execlabel);
571 typedef int	(*mpo_vnode_check_getacl_t)(struct ucred *cred,
572 		    struct vnode *vp, struct label *vplabel,
573 		    acl_type_t type);
574 typedef int	(*mpo_vnode_check_getextattr_t)(struct ucred *cred,
575 		    struct vnode *vp, struct label *vplabel,
576 		    int attrnamespace, const char *name);
577 typedef int	(*mpo_vnode_check_link_t)(struct ucred *cred,
578 		    struct vnode *dvp, struct label *dvplabel,
579 		    struct vnode *vp, struct label *vplabel,
580 		    struct componentname *cnp);
581 typedef int	(*mpo_vnode_check_listextattr_t)(struct ucred *cred,
582 		    struct vnode *vp, struct label *vplabel,
583 		    int attrnamespace);
584 typedef int	(*mpo_vnode_check_lookup_t)(struct ucred *cred,
585 		    struct vnode *dvp, struct label *dvplabel,
586 		    struct componentname *cnp);
587 typedef int	(*mpo_vnode_check_mmap_t)(struct ucred *cred,
588 		    struct vnode *vp, struct label *label, int prot,
589 		    int flags);
590 typedef void	(*mpo_vnode_check_mmap_downgrade_t)(struct ucred *cred,
591 		    struct vnode *vp, struct label *vplabel, int *prot);
592 typedef int	(*mpo_vnode_check_mprotect_t)(struct ucred *cred,
593 		    struct vnode *vp, struct label *vplabel, int prot);
594 typedef int	(*mpo_vnode_check_open_t)(struct ucred *cred,
595 		    struct vnode *vp, struct label *vplabel,
596 		    accmode_t accmode);
597 typedef int	(*mpo_vnode_check_poll_t)(struct ucred *active_cred,
598 		    struct ucred *file_cred, struct vnode *vp,
599 		    struct label *vplabel);
600 typedef int	(*mpo_vnode_check_read_t)(struct ucred *active_cred,
601 		    struct ucred *file_cred, struct vnode *vp,
602 		    struct label *vplabel);
603 typedef int	(*mpo_vnode_check_readdir_t)(struct ucred *cred,
604 		    struct vnode *dvp, struct label *dvplabel);
605 typedef int	(*mpo_vnode_check_readlink_t)(struct ucred *cred,
606 		    struct vnode *vp, struct label *vplabel);
607 typedef int	(*mpo_vnode_check_relabel_t)(struct ucred *cred,
608 		    struct vnode *vp, struct label *vplabel,
609 		    struct label *newlabel);
610 typedef int	(*mpo_vnode_check_rename_from_t)(struct ucred *cred,
611 		    struct vnode *dvp, struct label *dvplabel,
612 		    struct vnode *vp, struct label *vplabel,
613 		    struct componentname *cnp);
614 typedef int	(*mpo_vnode_check_rename_to_t)(struct ucred *cred,
615 		    struct vnode *dvp, struct label *dvplabel,
616 		    struct vnode *vp, struct label *vplabel, int samedir,
617 		    struct componentname *cnp);
618 typedef int	(*mpo_vnode_check_revoke_t)(struct ucred *cred,
619 		    struct vnode *vp, struct label *vplabel);
620 typedef int	(*mpo_vnode_check_setacl_t)(struct ucred *cred,
621 		    struct vnode *vp, struct label *vplabel, acl_type_t type,
622 		    struct acl *acl);
623 typedef int	(*mpo_vnode_check_setextattr_t)(struct ucred *cred,
624 		    struct vnode *vp, struct label *vplabel,
625 		    int attrnamespace, const char *name);
626 typedef int	(*mpo_vnode_check_setflags_t)(struct ucred *cred,
627 		    struct vnode *vp, struct label *vplabel, u_long flags);
628 typedef int	(*mpo_vnode_check_setmode_t)(struct ucred *cred,
629 		    struct vnode *vp, struct label *vplabel, mode_t mode);
630 typedef int	(*mpo_vnode_check_setowner_t)(struct ucred *cred,
631 		    struct vnode *vp, struct label *vplabel, uid_t uid,
632 		    gid_t gid);
633 typedef int	(*mpo_vnode_check_setutimes_t)(struct ucred *cred,
634 		    struct vnode *vp, struct label *vplabel,
635 		    struct timespec atime, struct timespec mtime);
636 typedef int	(*mpo_vnode_check_stat_t)(struct ucred *active_cred,
637 		    struct ucred *file_cred, struct vnode *vp,
638 		    struct label *vplabel);
639 typedef int	(*mpo_vnode_check_unlink_t)(struct ucred *cred,
640 		    struct vnode *dvp, struct label *dvplabel,
641 		    struct vnode *vp, struct label *vplabel,
642 		    struct componentname *cnp);
643 typedef int	(*mpo_vnode_check_write_t)(struct ucred *active_cred,
644 		    struct ucred *file_cred, struct vnode *vp,
645 		    struct label *vplabel);
646 typedef void	(*mpo_vnode_copy_label_t)(struct label *src,
647 		    struct label *dest);
648 typedef int	(*mpo_vnode_create_extattr_t)(struct ucred *cred,
649 		    struct mount *mp, struct label *mplabel,
650 		    struct vnode *dvp, struct label *dvplabel,
651 		    struct vnode *vp, struct label *vplabel,
652 		    struct componentname *cnp);
653 typedef void	(*mpo_vnode_destroy_label_t)(struct label *label);
654 typedef void	(*mpo_vnode_execve_transition_t)(struct ucred *old,
655 		    struct ucred *new, struct vnode *vp,
656 		    struct label *vplabel, struct label *interpvplabel,
657 		    struct image_params *imgp, struct label *execlabel);
658 typedef int	(*mpo_vnode_execve_will_transition_t)(struct ucred *old,
659 		    struct vnode *vp, struct label *vplabel,
660 		    struct label *interpvplabel, struct image_params *imgp,
661 		    struct label *execlabel);
662 typedef int	(*mpo_vnode_externalize_label_t)(struct label *label,
663 		    char *element_name, struct sbuf *sb, int *claimed);
664 typedef void	(*mpo_vnode_init_label_t)(struct label *label);
665 typedef int	(*mpo_vnode_internalize_label_t)(struct label *label,
666 		    char *element_name, char *element_data, int *claimed);
667 typedef void	(*mpo_vnode_relabel_t)(struct ucred *cred, struct vnode *vp,
668 		    struct label *vplabel, struct label *label);
669 typedef int	(*mpo_vnode_setlabel_extattr_t)(struct ucred *cred,
670 		    struct vnode *vp, struct label *vplabel,
671 		    struct label *intlabel);
672 
673 struct mac_policy_ops {
674 	/*
675 	 * Policy module operations.
676 	 */
677 	mpo_destroy_t				mpo_destroy;
678 	mpo_init_t				mpo_init;
679 
680 	/*
681 	 * General policy-directed security system call so that policies may
682 	 * implement new services without reserving explicit system call
683 	 * numbers.
684 	 */
685 	mpo_syscall_t				mpo_syscall;
686 
687 	/*
688 	 * Label operations.  Initialize label storage, destroy label
689 	 * storage, recycle for re-use without init/destroy, copy a label to
690 	 * initialized storage, and externalize/internalize from/to
691 	 * initialized storage.
692 	 */
693 	mpo_bpfdesc_check_receive_t		mpo_bpfdesc_check_receive;
694 	mpo_bpfdesc_create_t			mpo_bpfdesc_create;
695 	mpo_bpfdesc_create_mbuf_t		mpo_bpfdesc_create_mbuf;
696 	mpo_bpfdesc_destroy_label_t		mpo_bpfdesc_destroy_label;
697 	mpo_bpfdesc_init_label_t		mpo_bpfdesc_init_label;
698 
699 	mpo_cred_associate_nfsd_t		mpo_cred_associate_nfsd;
700 	mpo_cred_check_relabel_t		mpo_cred_check_relabel;
701 	mpo_cred_check_setaudit_t		mpo_cred_check_setaudit;
702 	mpo_cred_check_setaudit_addr_t		mpo_cred_check_setaudit_addr;
703 	mpo_cred_check_setauid_t		mpo_cred_check_setauid;
704 	mpo_cred_check_setuid_t			mpo_cred_check_setuid;
705 	mpo_cred_check_seteuid_t		mpo_cred_check_seteuid;
706 	mpo_cred_check_setgid_t			mpo_cred_check_setgid;
707 	mpo_cred_check_setegid_t		mpo_cred_check_setegid;
708 	mpo_cred_check_setgroups_t		mpo_cred_check_setgroups;
709 	mpo_cred_check_setreuid_t		mpo_cred_check_setreuid;
710 	mpo_cred_check_setregid_t		mpo_cred_check_setregid;
711 	mpo_cred_check_setresuid_t		mpo_cred_check_setresuid;
712 	mpo_cred_check_setresgid_t		mpo_cred_check_setresgid;
713 	mpo_cred_check_visible_t		mpo_cred_check_visible;
714 	mpo_cred_copy_label_t			mpo_cred_copy_label;
715 	mpo_cred_create_swapper_t		mpo_cred_create_swapper;
716 	mpo_cred_create_init_t			mpo_cred_create_init;
717 	mpo_cred_destroy_label_t		mpo_cred_destroy_label;
718 	mpo_cred_externalize_label_t		mpo_cred_externalize_label;
719 	mpo_cred_init_label_t			mpo_cred_init_label;
720 	mpo_cred_internalize_label_t		mpo_cred_internalize_label;
721 	mpo_cred_relabel_t			mpo_cred_relabel;
722 
723 	mpo_devfs_create_device_t		mpo_devfs_create_device;
724 	mpo_devfs_create_directory_t		mpo_devfs_create_directory;
725 	mpo_devfs_create_symlink_t		mpo_devfs_create_symlink;
726 	mpo_devfs_destroy_label_t		mpo_devfs_destroy_label;
727 	mpo_devfs_init_label_t			mpo_devfs_init_label;
728 	mpo_devfs_update_t			mpo_devfs_update;
729 	mpo_devfs_vnode_associate_t		mpo_devfs_vnode_associate;
730 
731 	mpo_ifnet_check_relabel_t		mpo_ifnet_check_relabel;
732 	mpo_ifnet_check_transmit_t		mpo_ifnet_check_transmit;
733 	mpo_ifnet_copy_label_t			mpo_ifnet_copy_label;
734 	mpo_ifnet_create_t			mpo_ifnet_create;
735 	mpo_ifnet_create_mbuf_t			mpo_ifnet_create_mbuf;
736 	mpo_ifnet_destroy_label_t		mpo_ifnet_destroy_label;
737 	mpo_ifnet_externalize_label_t		mpo_ifnet_externalize_label;
738 	mpo_ifnet_init_label_t			mpo_ifnet_init_label;
739 	mpo_ifnet_internalize_label_t		mpo_ifnet_internalize_label;
740 	mpo_ifnet_relabel_t			mpo_ifnet_relabel;
741 
742 	mpo_inpcb_check_deliver_t		mpo_inpcb_check_deliver;
743 	mpo_inpcb_check_visible_t		mpo_inpcb_check_visible;
744 	mpo_inpcb_create_t			mpo_inpcb_create;
745 	mpo_inpcb_create_mbuf_t			mpo_inpcb_create_mbuf;
746 	mpo_inpcb_destroy_label_t		mpo_inpcb_destroy_label;
747 	mpo_inpcb_init_label_t			mpo_inpcb_init_label;
748 	mpo_inpcb_sosetlabel_t			mpo_inpcb_sosetlabel;
749 
750 	mpo_ip6q_create_t			mpo_ip6q_create;
751 	mpo_ip6q_destroy_label_t		mpo_ip6q_destroy_label;
752 	mpo_ip6q_init_label_t			mpo_ip6q_init_label;
753 	mpo_ip6q_match_t			mpo_ip6q_match;
754 	mpo_ip6q_reassemble			mpo_ip6q_reassemble;
755 	mpo_ip6q_update_t			mpo_ip6q_update;
756 
757 	mpo_ipq_create_t			mpo_ipq_create;
758 	mpo_ipq_destroy_label_t			mpo_ipq_destroy_label;
759 	mpo_ipq_init_label_t			mpo_ipq_init_label;
760 	mpo_ipq_match_t				mpo_ipq_match;
761 	mpo_ipq_reassemble			mpo_ipq_reassemble;
762 	mpo_ipq_update_t			mpo_ipq_update;
763 
764 	mpo_kenv_check_dump_t			mpo_kenv_check_dump;
765 	mpo_kenv_check_get_t			mpo_kenv_check_get;
766 	mpo_kenv_check_set_t			mpo_kenv_check_set;
767 	mpo_kenv_check_unset_t			mpo_kenv_check_unset;
768 
769 	mpo_kld_check_load_t			mpo_kld_check_load;
770 	mpo_kld_check_stat_t			mpo_kld_check_stat;
771 
772 	mpo_mbuf_copy_label_t			mpo_mbuf_copy_label;
773 	mpo_mbuf_destroy_label_t		mpo_mbuf_destroy_label;
774 	mpo_mbuf_init_label_t			mpo_mbuf_init_label;
775 
776 	mpo_mount_check_stat_t			mpo_mount_check_stat;
777 	mpo_mount_create_t			mpo_mount_create;
778 	mpo_mount_destroy_label_t		mpo_mount_destroy_label;
779 	mpo_mount_init_label_t			mpo_mount_init_label;
780 
781 	mpo_netinet_arp_send_t			mpo_netinet_arp_send;
782 	mpo_netinet_firewall_reply_t		mpo_netinet_firewall_reply;
783 	mpo_netinet_firewall_send_t		mpo_netinet_firewall_send;
784 	mpo_netinet_fragment_t			mpo_netinet_fragment;
785 	mpo_netinet_icmp_reply_t		mpo_netinet_icmp_reply;
786 	mpo_netinet_icmp_replyinplace_t		mpo_netinet_icmp_replyinplace;
787 	mpo_netinet_igmp_send_t			mpo_netinet_igmp_send;
788 	mpo_netinet_tcp_reply_t			mpo_netinet_tcp_reply;
789 
790 	mpo_netinet6_nd6_send_t			mpo_netinet6_nd6_send;
791 
792 	mpo_pipe_check_ioctl_t			mpo_pipe_check_ioctl;
793 	mpo_pipe_check_poll_t			mpo_pipe_check_poll;
794 	mpo_pipe_check_read_t			mpo_pipe_check_read;
795 	mpo_pipe_check_relabel_t		mpo_pipe_check_relabel;
796 	mpo_pipe_check_stat_t			mpo_pipe_check_stat;
797 	mpo_pipe_check_write_t			mpo_pipe_check_write;
798 	mpo_pipe_copy_label_t			mpo_pipe_copy_label;
799 	mpo_pipe_create_t			mpo_pipe_create;
800 	mpo_pipe_destroy_label_t		mpo_pipe_destroy_label;
801 	mpo_pipe_externalize_label_t		mpo_pipe_externalize_label;
802 	mpo_pipe_init_label_t			mpo_pipe_init_label;
803 	mpo_pipe_internalize_label_t		mpo_pipe_internalize_label;
804 	mpo_pipe_relabel_t			mpo_pipe_relabel;
805 
806 	mpo_posixsem_check_getvalue_t		mpo_posixsem_check_getvalue;
807 	mpo_posixsem_check_open_t		mpo_posixsem_check_open;
808 	mpo_posixsem_check_post_t		mpo_posixsem_check_post;
809 	mpo_posixsem_check_setmode_t		mpo_posixsem_check_setmode;
810 	mpo_posixsem_check_setowner_t		mpo_posixsem_check_setowner;
811 	mpo_posixsem_check_stat_t		mpo_posixsem_check_stat;
812 	mpo_posixsem_check_unlink_t		mpo_posixsem_check_unlink;
813 	mpo_posixsem_check_wait_t		mpo_posixsem_check_wait;
814 	mpo_posixsem_create_t			mpo_posixsem_create;
815 	mpo_posixsem_destroy_label_t		mpo_posixsem_destroy_label;
816 	mpo_posixsem_init_label_t		mpo_posixsem_init_label;
817 
818 	mpo_posixshm_check_create_t		mpo_posixshm_check_create;
819 	mpo_posixshm_check_mmap_t		mpo_posixshm_check_mmap;
820 	mpo_posixshm_check_open_t		mpo_posixshm_check_open;
821 	mpo_posixshm_check_read_t		mpo_posixshm_check_read;
822 	mpo_posixshm_check_setmode_t		mpo_posixshm_check_setmode;
823 	mpo_posixshm_check_setowner_t		mpo_posixshm_check_setowner;
824 	mpo_posixshm_check_stat_t		mpo_posixshm_check_stat;
825 	mpo_posixshm_check_truncate_t		mpo_posixshm_check_truncate;
826 	mpo_posixshm_check_unlink_t		mpo_posixshm_check_unlink;
827 	mpo_posixshm_check_write_t		mpo_posixshm_check_write;
828 	mpo_posixshm_create_t			mpo_posixshm_create;
829 	mpo_posixshm_destroy_label_t		mpo_posixshm_destroy_label;
830 	mpo_posixshm_init_label_t		mpo_posixshm_init_label;
831 
832 	mpo_priv_check_t			mpo_priv_check;
833 	mpo_priv_grant_t			mpo_priv_grant;
834 
835 	mpo_proc_check_debug_t			mpo_proc_check_debug;
836 	mpo_proc_check_sched_t			mpo_proc_check_sched;
837 	mpo_proc_check_signal_t			mpo_proc_check_signal;
838 	mpo_proc_check_wait_t			mpo_proc_check_wait;
839 	mpo_proc_destroy_label_t		mpo_proc_destroy_label;
840 	mpo_proc_init_label_t			mpo_proc_init_label;
841 
842 	mpo_socket_check_accept_t		mpo_socket_check_accept;
843 	mpo_socket_check_bind_t			mpo_socket_check_bind;
844 	mpo_socket_check_connect_t		mpo_socket_check_connect;
845 	mpo_socket_check_create_t		mpo_socket_check_create;
846 	mpo_socket_check_deliver_t		mpo_socket_check_deliver;
847 	mpo_socket_check_listen_t		mpo_socket_check_listen;
848 	mpo_socket_check_poll_t			mpo_socket_check_poll;
849 	mpo_socket_check_receive_t		mpo_socket_check_receive;
850 	mpo_socket_check_relabel_t		mpo_socket_check_relabel;
851 	mpo_socket_check_send_t			mpo_socket_check_send;
852 	mpo_socket_check_stat_t			mpo_socket_check_stat;
853 	mpo_socket_check_visible_t		mpo_socket_check_visible;
854 	mpo_socket_copy_label_t			mpo_socket_copy_label;
855 	mpo_socket_create_t			mpo_socket_create;
856 	mpo_socket_create_mbuf_t		mpo_socket_create_mbuf;
857 	mpo_socket_destroy_label_t		mpo_socket_destroy_label;
858 	mpo_socket_externalize_label_t		mpo_socket_externalize_label;
859 	mpo_socket_init_label_t			mpo_socket_init_label;
860 	mpo_socket_internalize_label_t		mpo_socket_internalize_label;
861 	mpo_socket_newconn_t			mpo_socket_newconn;
862 	mpo_socket_relabel_t			mpo_socket_relabel;
863 
864 	mpo_socketpeer_destroy_label_t		mpo_socketpeer_destroy_label;
865 	mpo_socketpeer_externalize_label_t	mpo_socketpeer_externalize_label;
866 	mpo_socketpeer_init_label_t		mpo_socketpeer_init_label;
867 	mpo_socketpeer_set_from_mbuf_t		mpo_socketpeer_set_from_mbuf;
868 	mpo_socketpeer_set_from_socket_t	mpo_socketpeer_set_from_socket;
869 
870 	mpo_syncache_init_label_t		mpo_syncache_init_label;
871 	mpo_syncache_destroy_label_t		mpo_syncache_destroy_label;
872 	mpo_syncache_create_t			mpo_syncache_create;
873 	mpo_syncache_create_mbuf_t		mpo_syncache_create_mbuf;
874 
875 	mpo_system_check_acct_t			mpo_system_check_acct;
876 	mpo_system_check_audit_t		mpo_system_check_audit;
877 	mpo_system_check_auditctl_t		mpo_system_check_auditctl;
878 	mpo_system_check_auditon_t		mpo_system_check_auditon;
879 	mpo_system_check_reboot_t		mpo_system_check_reboot;
880 	mpo_system_check_swapon_t		mpo_system_check_swapon;
881 	mpo_system_check_swapoff_t		mpo_system_check_swapoff;
882 	mpo_system_check_sysctl_t		mpo_system_check_sysctl;
883 
884 	mpo_sysvmsg_cleanup_t			mpo_sysvmsg_cleanup;
885 	mpo_sysvmsg_create_t			mpo_sysvmsg_create;
886 	mpo_sysvmsg_destroy_label_t		mpo_sysvmsg_destroy_label;
887 	mpo_sysvmsg_init_label_t		mpo_sysvmsg_init_label;
888 
889 	mpo_sysvmsq_check_msgmsq_t		mpo_sysvmsq_check_msgmsq;
890 	mpo_sysvmsq_check_msgrcv_t		mpo_sysvmsq_check_msgrcv;
891 	mpo_sysvmsq_check_msgrmid_t		mpo_sysvmsq_check_msgrmid;
892 	mpo_sysvmsq_check_msqctl_t		mpo_sysvmsq_check_msqctl;
893 	mpo_sysvmsq_check_msqget_t		mpo_sysvmsq_check_msqget;
894 	mpo_sysvmsq_check_msqrcv_t		mpo_sysvmsq_check_msqrcv;
895 	mpo_sysvmsq_check_msqsnd_t		mpo_sysvmsq_check_msqsnd;
896 	mpo_sysvmsq_cleanup_t			mpo_sysvmsq_cleanup;
897 	mpo_sysvmsq_create_t			mpo_sysvmsq_create;
898 	mpo_sysvmsq_destroy_label_t		mpo_sysvmsq_destroy_label;
899 	mpo_sysvmsq_init_label_t		mpo_sysvmsq_init_label;
900 
901 	mpo_sysvsem_check_semctl_t		mpo_sysvsem_check_semctl;
902 	mpo_sysvsem_check_semget_t		mpo_sysvsem_check_semget;
903 	mpo_sysvsem_check_semop_t		mpo_sysvsem_check_semop;
904 	mpo_sysvsem_cleanup_t			mpo_sysvsem_cleanup;
905 	mpo_sysvsem_create_t			mpo_sysvsem_create;
906 	mpo_sysvsem_destroy_label_t		mpo_sysvsem_destroy_label;
907 	mpo_sysvsem_init_label_t		mpo_sysvsem_init_label;
908 
909 	mpo_sysvshm_check_shmat_t		mpo_sysvshm_check_shmat;
910 	mpo_sysvshm_check_shmctl_t		mpo_sysvshm_check_shmctl;
911 	mpo_sysvshm_check_shmdt_t		mpo_sysvshm_check_shmdt;
912 	mpo_sysvshm_check_shmget_t		mpo_sysvshm_check_shmget;
913 	mpo_sysvshm_cleanup_t			mpo_sysvshm_cleanup;
914 	mpo_sysvshm_create_t			mpo_sysvshm_create;
915 	mpo_sysvshm_destroy_label_t		mpo_sysvshm_destroy_label;
916 	mpo_sysvshm_init_label_t		mpo_sysvshm_init_label;
917 
918 	mpo_thread_userret_t			mpo_thread_userret;
919 
920 	mpo_vnode_check_access_t		mpo_vnode_check_access;
921 	mpo_vnode_check_chdir_t			mpo_vnode_check_chdir;
922 	mpo_vnode_check_chroot_t		mpo_vnode_check_chroot;
923 	mpo_vnode_check_create_t		mpo_vnode_check_create;
924 	mpo_vnode_check_deleteacl_t		mpo_vnode_check_deleteacl;
925 	mpo_vnode_check_deleteextattr_t		mpo_vnode_check_deleteextattr;
926 	mpo_vnode_check_exec_t			mpo_vnode_check_exec;
927 	mpo_vnode_check_getacl_t		mpo_vnode_check_getacl;
928 	mpo_vnode_check_getextattr_t		mpo_vnode_check_getextattr;
929 	mpo_vnode_check_link_t			mpo_vnode_check_link;
930 	mpo_vnode_check_listextattr_t		mpo_vnode_check_listextattr;
931 	mpo_vnode_check_lookup_t		mpo_vnode_check_lookup;
932 	mpo_vnode_check_mmap_t			mpo_vnode_check_mmap;
933 	mpo_vnode_check_mmap_downgrade_t	mpo_vnode_check_mmap_downgrade;
934 	mpo_vnode_check_mprotect_t		mpo_vnode_check_mprotect;
935 	mpo_vnode_check_open_t			mpo_vnode_check_open;
936 	mpo_vnode_check_poll_t			mpo_vnode_check_poll;
937 	mpo_vnode_check_read_t			mpo_vnode_check_read;
938 	mpo_vnode_check_readdir_t		mpo_vnode_check_readdir;
939 	mpo_vnode_check_readlink_t		mpo_vnode_check_readlink;
940 	mpo_vnode_check_relabel_t		mpo_vnode_check_relabel;
941 	mpo_vnode_check_rename_from_t		mpo_vnode_check_rename_from;
942 	mpo_vnode_check_rename_to_t		mpo_vnode_check_rename_to;
943 	mpo_vnode_check_revoke_t		mpo_vnode_check_revoke;
944 	mpo_vnode_check_setacl_t		mpo_vnode_check_setacl;
945 	mpo_vnode_check_setextattr_t		mpo_vnode_check_setextattr;
946 	mpo_vnode_check_setflags_t		mpo_vnode_check_setflags;
947 	mpo_vnode_check_setmode_t		mpo_vnode_check_setmode;
948 	mpo_vnode_check_setowner_t		mpo_vnode_check_setowner;
949 	mpo_vnode_check_setutimes_t		mpo_vnode_check_setutimes;
950 	mpo_vnode_check_stat_t			mpo_vnode_check_stat;
951 	mpo_vnode_check_unlink_t		mpo_vnode_check_unlink;
952 	mpo_vnode_check_write_t			mpo_vnode_check_write;
953 	mpo_vnode_associate_extattr_t		mpo_vnode_associate_extattr;
954 	mpo_vnode_associate_singlelabel_t	mpo_vnode_associate_singlelabel;
955 	mpo_vnode_destroy_label_t		mpo_vnode_destroy_label;
956 	mpo_vnode_copy_label_t			mpo_vnode_copy_label;
957 	mpo_vnode_create_extattr_t		mpo_vnode_create_extattr;
958 	mpo_vnode_execve_transition_t		mpo_vnode_execve_transition;
959 	mpo_vnode_execve_will_transition_t	mpo_vnode_execve_will_transition;
960 	mpo_vnode_externalize_label_t		mpo_vnode_externalize_label;
961 	mpo_vnode_init_label_t			mpo_vnode_init_label;
962 	mpo_vnode_internalize_label_t		mpo_vnode_internalize_label;
963 	mpo_vnode_relabel_t			mpo_vnode_relabel;
964 	mpo_vnode_setlabel_extattr_t		mpo_vnode_setlabel_extattr;
965 };
966 
967 /*
968  * struct mac_policy_conf is the registration structure for policies, and is
969  * provided to the MAC Framework using MAC_POLICY_SET() to invoke a SYSINIT
970  * to register the policy.  In general, the fields are immutable, with the
971  * exception of the "security field", run-time flags, and policy list entry,
972  * which are managed by the MAC Framework.  Be careful when modifying this
973  * structure, as its layout is statically compiled into all policies.
974  */
975 struct mac_policy_conf {
976 	char				*mpc_name;	/* policy name */
977 	char				*mpc_fullname;	/* policy full name */
978 	struct mac_policy_ops		*mpc_ops;	/* policy operations */
979 	int				 mpc_loadtime_flags;	/* flags */
980 	int				*mpc_field_off; /* security field */
981 	int				 mpc_runtime_flags; /* flags */
982 	int				 _mpc_spare1;	/* Spare. */
983 	uint64_t			 _mpc_spare2;	/* Spare. */
984 	uint64_t			 _mpc_spare3;	/* Spare. */
985 	void				*_mpc_spare4;	/* Spare. */
986 	LIST_ENTRY(mac_policy_conf)	 mpc_list;	/* global list */
987 };
988 
989 /* Flags for the mpc_loadtime_flags field. */
990 #define	MPC_LOADTIME_FLAG_NOTLATE	0x00000001
991 #define	MPC_LOADTIME_FLAG_UNLOADOK	0x00000002
992 
993 /* Flags for the mpc_runtime_flags field. */
994 #define	MPC_RUNTIME_FLAG_REGISTERED	0x00000001
995 
996 /*-
997  * The TrustedBSD MAC Framework has a major version number, MAC_VERSION,
998  * which defines the ABI of the Framework present in the kernel (and depended
999  * on by policy modules compiled against that kernel).  Currently,
1000  * MAC_POLICY_SET() requires that the kernel and module ABI version numbers
1001  * exactly match.  The following major versions have been defined to date:
1002  *
1003  *   MAC version             FreeBSD versions
1004  *   1                       5.x
1005  *   2                       6.x
1006  *   3                       7.x
1007  *   4                       8.x
1008  */
1009 #define	MAC_VERSION	4
1010 
1011 #define	MAC_POLICY_SET(mpops, mpname, mpfullname, mpflags, privdata_wanted) \
1012 	static struct mac_policy_conf mpname##_mac_policy_conf = {	\
1013 		.mpc_name = #mpname,					\
1014 		.mpc_fullname = mpfullname,				\
1015 		.mpc_ops = mpops,					\
1016 		.mpc_loadtime_flags = mpflags,				\
1017 		.mpc_field_off = privdata_wanted,			\
1018 	};								\
1019 	static moduledata_t mpname##_mod = {				\
1020 		#mpname,						\
1021 		mac_policy_modevent,					\
1022 		&mpname##_mac_policy_conf				\
1023 	};								\
1024 	MODULE_DEPEND(mpname, kernel_mac_support, MAC_VERSION,		\
1025 	    MAC_VERSION, MAC_VERSION);					\
1026 	DECLARE_MODULE(mpname, mpname##_mod, SI_SUB_MAC_POLICY,		\
1027 	    SI_ORDER_MIDDLE)
1028 
1029 int	mac_policy_modevent(module_t mod, int type, void *data);
1030 
1031 /*
1032  * Policy interface to map a struct label pointer to per-policy data.
1033  * Typically, policies wrap this in their own accessor macro that casts a
1034  * uintptr_t to a policy-specific data type.
1035  */
1036 intptr_t	mac_label_get(struct label *l, int slot);
1037 void		mac_label_set(struct label *l, int slot, intptr_t v);
1038 
1039 #endif /* !_SECURITY_MAC_MAC_POLICY_H_ */
1040