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