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