xref: /freebsd/sys/security/mac/mac_policy.h (revision c98323078dede7579020518ec84cdcb478e5c142)
1 /*-
2  * Copyright (c) 1999-2002 Robert N. M. Watson
3  * Copyright (c) 2001-2004 Networks Associates Technology, Inc.
4  * All rights reserved.
5  *
6  * This software was developed by Robert Watson for the TrustedBSD Project.
7  *
8  * This software was developed for the FreeBSD Project in part by Network
9  * Associates Laboratories, the Security Research Division of Network
10  * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
11  * as part of the DARPA CHATS research program.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright
19  *    notice, this list of conditions and the following disclaimer in the
20  *    documentation and/or other materials provided with the distribution.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  * $FreeBSD$
35  */
36 /*
37  * Kernel interface for MAC policy modules.
38  */
39 #ifndef _SYS_MAC_POLICY_H_
40 #define _SYS_MAC_POLICY_H_
41 
42 /*-
43  * Pluggable access control policy definition structure.
44  *
45  * List of operations that are performed as part of the implementation
46  * of a MAC policy.  Policy implementors declare operations with a
47  * mac_policy_ops structure, and using the MAC_POLICY_SET() macro.
48  * If an entry point is not declared, then then the policy will be ignored
49  * during evaluation of that event or check.
50  *
51  * Operations are sorted first by general class of operation, then
52  * alphabetically.
53  */
54 struct acl;
55 struct bpf_d;
56 struct componentname;
57 struct devfs_dirent;
58 struct ifnet;
59 struct image_params;
60 struct inpcb;
61 struct ipq;
62 struct label;
63 struct mac_policy_conf;
64 struct mbuf;
65 struct mount;
66 struct pipepair;
67 struct proc;
68 struct sbuf;
69 struct sockaddr;
70 struct socket;
71 struct sysctl_oid;
72 struct sysctl_req;
73 struct thread;
74 struct ucred;
75 struct uio;
76 struct vattr;
77 struct vnode;
78 struct mac_policy_ops {
79 	/*
80 	 * Policy module operations.
81 	 */
82 	void	(*mpo_destroy)(struct mac_policy_conf *mpc);
83 	void	(*mpo_init)(struct mac_policy_conf *mpc);
84 
85 	/*
86 	 * General policy-directed security system call so that policies
87 	 * may implement new services without reserving explicit
88 	 * system call numbers.
89 	 */
90 	int	(*mpo_syscall)(struct thread *td, int call, void *arg);
91 
92 	/*
93 	 * Label operations.
94 	 */
95 	void	(*mpo_init_bpfdesc_label)(struct label *label);
96 	void	(*mpo_init_cred_label)(struct label *label);
97 	void	(*mpo_init_devfsdirent_label)(struct label *label);
98 	void	(*mpo_init_ifnet_label)(struct label *label);
99 	int	(*mpo_init_inpcb_label)(struct label *label, int flag);
100 	int	(*mpo_init_ipq_label)(struct label *label, int flag);
101 	int	(*mpo_init_mbuf_label)(struct label *label, int flag);
102 	void	(*mpo_init_mount_label)(struct label *label);
103 	void	(*mpo_init_mount_fs_label)(struct label *label);
104 	int	(*mpo_init_socket_label)(struct label *label, int flag);
105 	int	(*mpo_init_socket_peer_label)(struct label *label, int flag);
106 	void	(*mpo_init_pipe_label)(struct label *label);
107 	void	(*mpo_init_proc_label)(struct label *label);
108 	void	(*mpo_init_vnode_label)(struct label *label);
109 	void	(*mpo_destroy_bpfdesc_label)(struct label *label);
110 	void	(*mpo_destroy_cred_label)(struct label *label);
111 	void	(*mpo_destroy_devfsdirent_label)(struct label *label);
112 	void	(*mpo_destroy_ifnet_label)(struct label *label);
113 	void	(*mpo_destroy_inpcb_label)(struct label *label);
114 	void	(*mpo_destroy_ipq_label)(struct label *label);
115 	void	(*mpo_destroy_mbuf_label)(struct label *label);
116 	void	(*mpo_destroy_mount_label)(struct label *label);
117 	void	(*mpo_destroy_mount_fs_label)(struct label *label);
118 	void	(*mpo_destroy_socket_label)(struct label *label);
119 	void	(*mpo_destroy_socket_peer_label)(struct label *label);
120 	void	(*mpo_destroy_pipe_label)(struct label *label);
121 	void	(*mpo_destroy_proc_label)(struct label *label);
122 	void	(*mpo_destroy_vnode_label)(struct label *label);
123 	void	(*mpo_copy_cred_label)(struct label *src,
124 		    struct label *dest);
125 	void	(*mpo_copy_ifnet_label)(struct label *src,
126 		    struct label *dest);
127 	void	(*mpo_copy_mbuf_label)(struct label *src,
128 		    struct label *dest);
129 	void	(*mpo_copy_pipe_label)(struct label *src,
130 		    struct label *dest);
131 	void	(*mpo_copy_socket_label)(struct label *src,
132 		    struct label *dest);
133 	void	(*mpo_copy_vnode_label)(struct label *src,
134 		    struct label *dest);
135 	int	(*mpo_externalize_cred_label)(struct label *label,
136 		    char *element_name, struct sbuf *sb, int *claimed);
137 	int	(*mpo_externalize_ifnet_label)(struct label *label,
138 		    char *element_name, struct sbuf *sb, int *claimed);
139 	int	(*mpo_externalize_pipe_label)(struct label *label,
140 		    char *element_name, struct sbuf *sb, int *claimed);
141 	int	(*mpo_externalize_socket_label)(struct label *label,
142 		    char *element_name, struct sbuf *sb, int *claimed);
143 	int	(*mpo_externalize_socket_peer_label)(struct label *label,
144 		    char *element_name, struct sbuf *sb, int *claimed);
145 	int	(*mpo_externalize_vnode_label)(struct label *label,
146 		    char *element_name, struct sbuf *sb, int *claimed);
147 	int	(*mpo_internalize_cred_label)(struct label *label,
148 		    char *element_name, char *element_data, int *claimed);
149 	int	(*mpo_internalize_ifnet_label)(struct label *label,
150 		    char *element_name, char *element_data, int *claimed);
151 	int	(*mpo_internalize_pipe_label)(struct label *label,
152 		    char *element_name, char *element_data, int *claimed);
153 	int	(*mpo_internalize_socket_label)(struct label *label,
154 		    char *element_name, char *element_data, int *claimed);
155 	int	(*mpo_internalize_vnode_label)(struct label *label,
156 		    char *element_name, char *element_data, int *claimed);
157 
158 	/*
159 	 * Labeling event operations: file system objects, and things that
160 	 * look a lot like file system objects.
161 	 */
162 	void	(*mpo_associate_vnode_devfs)(struct mount *mp,
163 		    struct label *fslabel, struct devfs_dirent *de,
164 		    struct label *delabel, struct vnode *vp,
165 		    struct label *vlabel);
166 	int	(*mpo_associate_vnode_extattr)(struct mount *mp,
167 		    struct label *fslabel, struct vnode *vp,
168 		    struct label *vlabel);
169 	void	(*mpo_associate_vnode_singlelabel)(struct mount *mp,
170 		    struct label *fslabel, struct vnode *vp,
171 		    struct label *vlabel);
172 	void	(*mpo_create_devfs_device)(struct mount *mp, struct cdev *dev,
173 		    struct devfs_dirent *de, struct label *label);
174 	void	(*mpo_create_devfs_directory)(struct mount *mp, char *dirname,
175 		    int dirnamelen, struct devfs_dirent *de,
176 		    struct label *label);
177 	void	(*mpo_create_devfs_symlink)(struct ucred *cred,
178 		    struct mount *mp, struct devfs_dirent *dd,
179 		    struct label *ddlabel, struct devfs_dirent *de,
180 		    struct label *delabel);
181 	int	(*mpo_create_vnode_extattr)(struct ucred *cred,
182 		    struct mount *mp, struct label *fslabel,
183 		    struct vnode *dvp, struct label *dlabel,
184 		    struct vnode *vp, struct label *vlabel,
185 		    struct componentname *cnp);
186 	void	(*mpo_create_mount)(struct ucred *cred, struct mount *mp,
187 		    struct label *mntlabel, struct label *fslabel);
188 	void	(*mpo_create_root_mount)(struct ucred *cred, struct mount *mp,
189 		    struct label *mountlabel, struct label *fslabel);
190 	void	(*mpo_relabel_vnode)(struct ucred *cred, struct vnode *vp,
191 		    struct label *vnodelabel, struct label *label);
192 	int	(*mpo_setlabel_vnode_extattr)(struct ucred *cred,
193 		    struct vnode *vp, struct label *vlabel,
194 		    struct label *intlabel);
195 	void	(*mpo_update_devfsdirent)(struct mount *mp,
196 		    struct devfs_dirent *devfs_dirent,
197 		    struct label *direntlabel, struct vnode *vp,
198 		    struct label *vnodelabel);
199 
200 	/*
201 	 * Labeling event operations: IPC objects.
202 	 */
203 	void	(*mpo_create_mbuf_from_socket)(struct socket *so,
204 		    struct label *socketlabel, struct mbuf *m,
205 		    struct label *mbuflabel);
206 	void	(*mpo_create_socket)(struct ucred *cred, struct socket *so,
207 		    struct label *socketlabel);
208 	void	(*mpo_create_socket_from_socket)(struct socket *oldsocket,
209 		    struct label *oldsocketlabel, struct socket *newsocket,
210 		    struct label *newsocketlabel);
211 	void	(*mpo_relabel_socket)(struct ucred *cred, struct socket *so,
212 		    struct label *oldlabel, struct label *newlabel);
213 	void	(*mpo_relabel_pipe)(struct ucred *cred, struct pipepair *pp,
214 		    struct label *oldlabel, struct label *newlabel);
215 	void	(*mpo_set_socket_peer_from_mbuf)(struct mbuf *mbuf,
216 		    struct label *mbuflabel, struct socket *so,
217 		    struct label *socketpeerlabel);
218 	void	(*mpo_set_socket_peer_from_socket)(struct socket *oldsocket,
219 		    struct label *oldsocketlabel, struct socket *newsocket,
220 		    struct label *newsocketpeerlabel);
221 	void	(*mpo_create_pipe)(struct ucred *cred, struct pipepair *pp,
222 		    struct label *pipelabel);
223 
224 	/*
225 	 * Labeling event operations: network objects.
226 	 */
227 	void	(*mpo_create_bpfdesc)(struct ucred *cred, struct bpf_d *bpf_d,
228 		    struct label *bpflabel);
229 	void	(*mpo_create_ifnet)(struct ifnet *ifnet,
230 		    struct label *ifnetlabel);
231 	void	(*mpo_create_inpcb_from_socket)(struct socket *so,
232 		    struct label *solabel, struct inpcb *inp,
233 		    struct label *inplabel);
234 	void	(*mpo_create_ipq)(struct mbuf *fragment,
235 		    struct label *fragmentlabel, struct ipq *ipq,
236 		    struct label *ipqlabel);
237 	void	(*mpo_create_datagram_from_ipq)
238 		    (struct ipq *ipq, struct label *ipqlabel,
239 		    struct mbuf *datagram, struct label *datagramlabel);
240 	void	(*mpo_create_fragment)(struct mbuf *datagram,
241 		    struct label *datagramlabel, struct mbuf *fragment,
242 		    struct label *fragmentlabel);
243 	void	(*mpo_create_mbuf_from_inpcb)(struct inpcb *inp,
244 		    struct label *inplabel, struct mbuf *m,
245 		    struct label *mlabel);
246 	void	(*mpo_create_mbuf_from_mbuf)(struct mbuf *oldmbuf,
247 		    struct label *oldlabel, struct mbuf *newmbuf,
248 		    struct label *newlabel);
249 	void	(*mpo_create_mbuf_linklayer)(struct ifnet *ifnet,
250 		    struct label *ifnetlabel, struct mbuf *mbuf,
251 		    struct label *mbuflabel);
252 	void	(*mpo_create_mbuf_from_bpfdesc)(struct bpf_d *bpf_d,
253 		    struct label *bpflabel, struct mbuf *mbuf,
254 		    struct label *mbuflabel);
255 	void	(*mpo_create_mbuf_from_ifnet)(struct ifnet *ifnet,
256 		    struct label *ifnetlabel, struct mbuf *mbuf,
257 		    struct label *mbuflabel);
258 	void	(*mpo_create_mbuf_multicast_encap)(struct mbuf *oldmbuf,
259 		    struct label *oldmbuflabel, struct ifnet *ifnet,
260 		    struct label *ifnetlabel, struct mbuf *newmbuf,
261 		    struct label *newmbuflabel);
262 	void	(*mpo_create_mbuf_netlayer)(struct mbuf *oldmbuf,
263 		    struct label *oldmbuflabel, struct mbuf *newmbuf,
264 		    struct label *newmbuflabel);
265 	int	(*mpo_fragment_match)(struct mbuf *fragment,
266 		    struct label *fragmentlabel, struct ipq *ipq,
267 		    struct label *ipqlabel);
268 	void	(*mpo_reflect_mbuf_icmp)(struct mbuf *m,
269 		    struct label *mlabel);
270 	void	(*mpo_reflect_mbuf_tcp)(struct mbuf *m, struct label *mlabel);
271 	void	(*mpo_relabel_ifnet)(struct ucred *cred, struct ifnet *ifnet,
272 		    struct label *ifnetlabel, struct label *newlabel);
273 	void	(*mpo_update_ipq)(struct mbuf *fragment,
274 		    struct label *fragmentlabel, struct ipq *ipq,
275 		    struct label *ipqlabel);
276 	void	(*mpo_inpcb_sosetlabel)(struct socket *so,
277 		    struct label *label, struct inpcb *inp,
278 		    struct label *inplabel);
279 
280 	/*
281 	 * Labeling event operations: processes.
282 	 */
283 	void	(*mpo_execve_transition)(struct ucred *old, struct ucred *new,
284 		    struct vnode *vp, struct label *vnodelabel,
285 		    struct label *interpvnodelabel,
286 		    struct image_params *imgp, struct label *execlabel);
287 	int	(*mpo_execve_will_transition)(struct ucred *old,
288 		    struct vnode *vp, struct label *vnodelabel,
289 		    struct label *interpvnodelabel,
290 		    struct image_params *imgp, struct label *execlabel);
291 	void	(*mpo_create_proc0)(struct ucred *cred);
292 	void	(*mpo_create_proc1)(struct ucred *cred);
293 	void	(*mpo_relabel_cred)(struct ucred *cred,
294 		    struct label *newlabel);
295 	void	(*mpo_thread_userret)(struct thread *thread);
296 
297 	/*
298 	 * Access control checks.
299 	 */
300 	int	(*mpo_check_bpfdesc_receive)(struct bpf_d *bpf_d,
301 		    struct label *bpflabel, struct ifnet *ifnet,
302 		    struct label *ifnetlabel);
303 	int	(*mpo_check_cred_relabel)(struct ucred *cred,
304 		    struct label *newlabel);
305 	int	(*mpo_check_cred_visible)(struct ucred *u1, struct ucred *u2);
306 	int	(*mpo_check_ifnet_relabel)(struct ucred *cred,
307 		    struct ifnet *ifnet, struct label *ifnetlabel,
308 		    struct label *newlabel);
309 	int	(*mpo_check_ifnet_transmit)(struct ifnet *ifnet,
310 		    struct label *ifnetlabel, struct mbuf *m,
311 		    struct label *mbuflabel);
312 	int	(*mpo_check_inpcb_deliver)(struct inpcb *inp,
313 		    struct label *inplabel, struct mbuf *m,
314 		    struct label *mlabel);
315 	int	(*mpo_check_kenv_dump)(struct ucred *cred);
316 	int	(*mpo_check_kenv_get)(struct ucred *cred, char *name);
317 	int	(*mpo_check_kenv_set)(struct ucred *cred, char *name,
318 		    char *value);
319 	int	(*mpo_check_kenv_unset)(struct ucred *cred, char *name);
320 	int	(*mpo_check_kld_load)(struct ucred *cred, struct vnode *vp,
321 		    struct label *vlabel);
322 	int	(*mpo_check_kld_stat)(struct ucred *cred);
323 	int	(*mpo_check_kld_unload)(struct ucred *cred);
324 	int	(*mpo_check_mount_stat)(struct ucred *cred, struct mount *mp,
325 		    struct label *mntlabel);
326 	int	(*mpo_check_pipe_ioctl)(struct ucred *cred,
327 		    struct pipepair *pp, struct label *pipelabel,
328 		    unsigned long cmd, void *data);
329 	int	(*mpo_check_pipe_poll)(struct ucred *cred,
330 		    struct pipepair *pp, struct label *pipelabel);
331 	int	(*mpo_check_pipe_read)(struct ucred *cred,
332 		    struct pipepair *pp, struct label *pipelabel);
333 	int	(*mpo_check_pipe_relabel)(struct ucred *cred,
334 		    struct pipepair *pp, struct label *pipelabel,
335 		    struct label *newlabel);
336 	int	(*mpo_check_pipe_stat)(struct ucred *cred,
337 		    struct pipepair *pp, struct label *pipelabel);
338 	int	(*mpo_check_pipe_write)(struct ucred *cred,
339 		    struct pipepair *pp, struct label *pipelabel);
340 	int	(*mpo_check_proc_debug)(struct ucred *cred,
341 		    struct proc *proc);
342 	int	(*mpo_check_proc_sched)(struct ucred *cred,
343 		    struct proc *proc);
344 	int	(*mpo_check_proc_signal)(struct ucred *cred,
345 		    struct proc *proc, int signum);
346 	int	(*mpo_check_socket_bind)(struct ucred *cred,
347 		    struct socket *so, struct label *socketlabel,
348 		    struct sockaddr *sockaddr);
349 	int	(*mpo_check_socket_connect)(struct ucred *cred,
350 		    struct socket *so, struct label *socketlabel,
351 		    struct sockaddr *sockaddr);
352 	int	(*mpo_check_socket_deliver)(struct socket *so,
353 		    struct label *socketlabel, struct mbuf *m,
354 		    struct label *mbuflabel);
355 	int	(*mpo_check_socket_listen)(struct ucred *cred,
356 		    struct socket *so, struct label *socketlabel);
357 	int	(*mpo_check_socket_receive)(struct ucred *cred,
358 		    struct socket *so, struct label *socketlabel);
359 	int	(*mpo_check_socket_relabel)(struct ucred *cred,
360 		    struct socket *so, struct label *socketlabel,
361 		    struct label *newlabel);
362 	int	(*mpo_check_socket_send)(struct ucred *cred,
363 		    struct socket *so, struct label *socketlabel);
364 	int	(*mpo_check_socket_visible)(struct ucred *cred,
365 		    struct socket *so, struct label *socketlabel);
366 	int	(*mpo_check_sysarch_ioperm)(struct ucred *cred);
367 	int	(*mpo_check_system_acct)(struct ucred *cred,
368 		    struct vnode *vp, struct label *vlabel);
369 	int	(*mpo_check_system_nfsd)(struct ucred *cred);
370 	int	(*mpo_check_system_reboot)(struct ucred *cred, int howto);
371 	int	(*mpo_check_system_settime)(struct ucred *cred);
372 	int	(*mpo_check_system_swapon)(struct ucred *cred,
373 		    struct vnode *vp, struct label *label);
374 	int	(*mpo_check_system_swapoff)(struct ucred *cred,
375 		    struct vnode *vp, struct label *label);
376 	int	(*mpo_check_system_sysctl)(struct ucred *cred,
377 		    struct sysctl_oid *oidp, void *arg1, int arg2,
378 		    struct sysctl_req *req);
379 	int	(*mpo_check_vnode_access)(struct ucred *cred,
380 		    struct vnode *vp, struct label *label, int acc_mode);
381 	int	(*mpo_check_vnode_chdir)(struct ucred *cred,
382 		    struct vnode *dvp, struct label *dlabel);
383 	int	(*mpo_check_vnode_chroot)(struct ucred *cred,
384 		    struct vnode *dvp, struct label *dlabel);
385 	int	(*mpo_check_vnode_create)(struct ucred *cred,
386 		    struct vnode *dvp, struct label *dlabel,
387 		    struct componentname *cnp, struct vattr *vap);
388 	int	(*mpo_check_vnode_delete)(struct ucred *cred,
389 		    struct vnode *dvp, struct label *dlabel,
390 		    struct vnode *vp, struct label *label,
391 		    struct componentname *cnp);
392 	int	(*mpo_check_vnode_deleteacl)(struct ucred *cred,
393 		    struct vnode *vp, struct label *label, acl_type_t type);
394 	int	(*mpo_check_vnode_deleteextattr)(struct ucred *cred,
395 		    struct vnode *vp, struct label *label, int attrnamespace,
396 		    const char *name);
397 	int	(*mpo_check_vnode_exec)(struct ucred *cred, struct vnode *vp,
398 		    struct label *label, struct image_params *imgp,
399 		    struct label *execlabel);
400 	int	(*mpo_check_vnode_getacl)(struct ucred *cred,
401 		    struct vnode *vp, struct label *label, acl_type_t type);
402 	int	(*mpo_check_vnode_getextattr)(struct ucred *cred,
403 		    struct vnode *vp, struct label *label, int attrnamespace,
404 		    const char *name, struct uio *uio);
405 	int	(*mpo_check_vnode_link)(struct ucred *cred, struct vnode *dvp,
406 		    struct label *dlabel, struct vnode *vp,
407 		    struct label *label, struct componentname *cnp);
408 	int	(*mpo_check_vnode_listextattr)(struct ucred *cred,
409 		    struct vnode *vp, struct label *label, int attrnamespace);
410 	int	(*mpo_check_vnode_lookup)(struct ucred *cred,
411 		    struct vnode *dvp, struct label *dlabel,
412 		    struct componentname *cnp);
413 	int	(*mpo_check_vnode_mmap)(struct ucred *cred, struct vnode *vp,
414 		    struct label *label, int prot);
415 	void	(*mpo_check_vnode_mmap_downgrade)(struct ucred *cred,
416 		    struct vnode *vp, struct label *label, int *prot);
417 	int	(*mpo_check_vnode_mprotect)(struct ucred *cred,
418 		    struct vnode *vp, struct label *label, int prot);
419 	int	(*mpo_check_vnode_open)(struct ucred *cred, struct vnode *vp,
420 		    struct label *label, int acc_mode);
421 	int	(*mpo_check_vnode_poll)(struct ucred *active_cred,
422 		    struct ucred *file_cred, struct vnode *vp,
423 		    struct label *label);
424 	int	(*mpo_check_vnode_read)(struct ucred *active_cred,
425 		    struct ucred *file_cred, struct vnode *vp,
426 		    struct label *label);
427 	int	(*mpo_check_vnode_readdir)(struct ucred *cred,
428 		    struct vnode *dvp, struct label *dlabel);
429 	int	(*mpo_check_vnode_readlink)(struct ucred *cred,
430 		    struct vnode *vp, struct label *label);
431 	int	(*mpo_check_vnode_relabel)(struct ucred *cred,
432 		    struct vnode *vp, struct label *vnodelabel,
433 		    struct label *newlabel);
434 	int	(*mpo_check_vnode_rename_from)(struct ucred *cred,
435 		    struct vnode *dvp, struct label *dlabel, struct vnode *vp,
436 		    struct label *label, struct componentname *cnp);
437 	int	(*mpo_check_vnode_rename_to)(struct ucred *cred,
438 		    struct vnode *dvp, struct label *dlabel, struct vnode *vp,
439 		    struct label *label, int samedir,
440 		    struct componentname *cnp);
441 	int	(*mpo_check_vnode_revoke)(struct ucred *cred,
442 		    struct vnode *vp, struct label *label);
443 	int	(*mpo_check_vnode_setacl)(struct ucred *cred,
444 		    struct vnode *vp, struct label *label, acl_type_t type,
445 		    struct acl *acl);
446 	int	(*mpo_check_vnode_setextattr)(struct ucred *cred,
447 		    struct vnode *vp, struct label *label, int attrnamespace,
448 		    const char *name, struct uio *uio);
449 	int	(*mpo_check_vnode_setflags)(struct ucred *cred,
450 		    struct vnode *vp, struct label *label, u_long flags);
451 	int	(*mpo_check_vnode_setmode)(struct ucred *cred,
452 		    struct vnode *vp, struct label *label, mode_t mode);
453 	int	(*mpo_check_vnode_setowner)(struct ucred *cred,
454 		    struct vnode *vp, struct label *label, uid_t uid,
455 		    gid_t gid);
456 	int	(*mpo_check_vnode_setutimes)(struct ucred *cred,
457 		    struct vnode *vp, struct label *label,
458 		    struct timespec atime, struct timespec mtime);
459 	int	(*mpo_check_vnode_stat)(struct ucred *active_cred,
460 		    struct ucred *file_cred, struct vnode *vp,
461 		    struct label *label);
462 	int	(*mpo_check_vnode_write)(struct ucred *active_cred,
463 		    struct ucred *file_cred, struct vnode *vp,
464 		    struct label *label);
465 };
466 
467 struct mac_policy_conf {
468 	char				*mpc_name;	/* policy name */
469 	char				*mpc_fullname;	/* policy full name */
470 	struct mac_policy_ops		*mpc_ops;	/* policy operations */
471 	int				 mpc_loadtime_flags;	/* flags */
472 	int				*mpc_field_off; /* security field */
473 	int				 mpc_runtime_flags; /* flags */
474 	LIST_ENTRY(mac_policy_conf)	 mpc_list;	/* global list */
475 };
476 
477 /* Flags for the mpc_loadtime_flags field. */
478 #define	MPC_LOADTIME_FLAG_NOTLATE	0x00000001
479 #define	MPC_LOADTIME_FLAG_UNLOADOK	0x00000002
480 #define	MPC_LOADTIME_FLAG_LABELMBUFS	0x00000004
481 
482 /* Flags for the mpc_runtime_flags field. */
483 #define	MPC_RUNTIME_FLAG_REGISTERED	0x00000001
484 
485 #define	MAC_POLICY_SET(mpops, mpname, mpfullname, mpflags, privdata_wanted) \
486 	static struct mac_policy_conf mpname##_mac_policy_conf = {	\
487 		#mpname,						\
488 		mpfullname,						\
489 		mpops,							\
490 		mpflags,						\
491 		privdata_wanted,					\
492 		0,							\
493 	};								\
494 	static moduledata_t mpname##_mod = {				\
495 		#mpname,						\
496 		mac_policy_modevent,					\
497 		&mpname##_mac_policy_conf				\
498 	};								\
499 	MODULE_DEPEND(mpname, kernel_mac_support, 1, 1, 1);		\
500 	DECLARE_MODULE(mpname, mpname##_mod, SI_SUB_MAC_POLICY,		\
501 	    SI_ORDER_MIDDLE)
502 
503 int	mac_policy_modevent(module_t mod, int type, void *data);
504 
505 #define	LABEL_TO_SLOT(l, s)	(l)->l_perpolicy[s]
506 
507 #endif /* !_SYS_MAC_POLICY_H_ */
508