xref: /freebsd/sys/security/mac/mac_policy.h (revision 6af83ee0d2941d18880b6aaa2b4facd1d30c6106)
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 msqid_kernel;
67 struct pipepair;
68 struct proc;
69 struct sbuf;
70 struct semid_kernel;
71 struct shmid_kernel;
72 struct sockaddr;
73 struct socket;
74 struct sysctl_oid;
75 struct sysctl_req;
76 struct thread;
77 struct ucred;
78 struct uio;
79 struct vattr;
80 struct vnode;
81 struct mac_policy_ops {
82 	/*
83 	 * Policy module operations.
84 	 */
85 	void	(*mpo_destroy)(struct mac_policy_conf *mpc);
86 	void	(*mpo_init)(struct mac_policy_conf *mpc);
87 
88 	/*
89 	 * General policy-directed security system call so that policies may
90 	 * implement new services without reserving explicit system call
91 	 * numbers.
92 	 */
93 	int	(*mpo_syscall)(struct thread *td, int call, void *arg);
94 
95 	/*
96 	 * Label operations.  Initialize label storage, destroy label
97 	 * storage, recycle for re-use without init/destroy, copy a label to
98 	 * initialized storage, and externalize/internalize from/to
99 	 * initialized storage.
100 	 */
101 	void	(*mpo_init_bpfdesc_label)(struct label *label);
102 	void	(*mpo_init_cred_label)(struct label *label);
103 	void	(*mpo_init_devfsdirent_label)(struct label *label);
104 	void	(*mpo_init_ifnet_label)(struct label *label);
105 	int	(*mpo_init_inpcb_label)(struct label *label, int flag);
106 	void	(*mpo_init_sysv_msgmsg_label)(struct label *label);
107 	void	(*mpo_init_sysv_msgqueue_label)(struct label *label);
108 	void	(*mpo_init_sysv_sema_label)(struct label *label);
109 	void	(*mpo_init_sysv_shm_label)(struct label *label);
110 	int	(*mpo_init_ipq_label)(struct label *label, int flag);
111 	int	(*mpo_init_mbuf_label)(struct label *label, int flag);
112 	void	(*mpo_init_mount_label)(struct label *label);
113 	void	(*mpo_init_mount_fs_label)(struct label *label);
114 	int	(*mpo_init_socket_label)(struct label *label, int flag);
115 	int	(*mpo_init_socket_peer_label)(struct label *label, int flag);
116 	void	(*mpo_init_pipe_label)(struct label *label);
117 	void	(*mpo_init_proc_label)(struct label *label);
118 	void	(*mpo_init_vnode_label)(struct label *label);
119 	void	(*mpo_destroy_bpfdesc_label)(struct label *label);
120 	void	(*mpo_destroy_cred_label)(struct label *label);
121 	void	(*mpo_destroy_devfsdirent_label)(struct label *label);
122 	void	(*mpo_destroy_ifnet_label)(struct label *label);
123 	void	(*mpo_destroy_inpcb_label)(struct label *label);
124 	void	(*mpo_destroy_sysv_msgmsg_label)(struct label *label);
125 	void	(*mpo_destroy_sysv_msgqueue_label)(struct label *label);
126 	void	(*mpo_destroy_sysv_sema_label)(struct label *label);
127 	void	(*mpo_destroy_sysv_shm_label)(struct label *label);
128 	void	(*mpo_destroy_ipq_label)(struct label *label);
129 	void	(*mpo_destroy_mbuf_label)(struct label *label);
130 	void	(*mpo_destroy_mount_label)(struct label *label);
131 	void	(*mpo_destroy_mount_fs_label)(struct label *label);
132 	void	(*mpo_destroy_socket_label)(struct label *label);
133 	void	(*mpo_destroy_socket_peer_label)(struct label *label);
134 	void	(*mpo_destroy_pipe_label)(struct label *label);
135 	void	(*mpo_destroy_proc_label)(struct label *label);
136 	void	(*mpo_destroy_vnode_label)(struct label *label);
137 	void	(*mpo_cleanup_sysv_msgmsg)(struct label *msglabel);
138 	void	(*mpo_cleanup_sysv_msgqueue)(struct label *msqlabel);
139 	void	(*mpo_cleanup_sysv_sema)(struct label *semalabel);
140 	void	(*mpo_cleanup_sysv_shm)(struct label *shmlabel);
141 	void	(*mpo_copy_cred_label)(struct label *src,
142 		    struct label *dest);
143 	void	(*mpo_copy_ifnet_label)(struct label *src,
144 		    struct label *dest);
145 	void	(*mpo_copy_mbuf_label)(struct label *src,
146 		    struct label *dest);
147 	void	(*mpo_copy_pipe_label)(struct label *src,
148 		    struct label *dest);
149 	void	(*mpo_copy_socket_label)(struct label *src,
150 		    struct label *dest);
151 	void	(*mpo_copy_vnode_label)(struct label *src,
152 		    struct label *dest);
153 	int	(*mpo_externalize_cred_label)(struct label *label,
154 		    char *element_name, struct sbuf *sb, int *claimed);
155 	int	(*mpo_externalize_ifnet_label)(struct label *label,
156 		    char *element_name, struct sbuf *sb, int *claimed);
157 	int	(*mpo_externalize_pipe_label)(struct label *label,
158 		    char *element_name, struct sbuf *sb, int *claimed);
159 	int	(*mpo_externalize_socket_label)(struct label *label,
160 		    char *element_name, struct sbuf *sb, int *claimed);
161 	int	(*mpo_externalize_socket_peer_label)(struct label *label,
162 		    char *element_name, struct sbuf *sb, int *claimed);
163 	int	(*mpo_externalize_vnode_label)(struct label *label,
164 		    char *element_name, struct sbuf *sb, int *claimed);
165 	int	(*mpo_internalize_cred_label)(struct label *label,
166 		    char *element_name, char *element_data, int *claimed);
167 	int	(*mpo_internalize_ifnet_label)(struct label *label,
168 		    char *element_name, char *element_data, int *claimed);
169 	int	(*mpo_internalize_pipe_label)(struct label *label,
170 		    char *element_name, char *element_data, int *claimed);
171 	int	(*mpo_internalize_socket_label)(struct label *label,
172 		    char *element_name, char *element_data, int *claimed);
173 	int	(*mpo_internalize_vnode_label)(struct label *label,
174 		    char *element_name, char *element_data, int *claimed);
175 
176 	/*
177 	 * Labeling event operations: file system objects, and things that
178 	 * look a lot like file system objects.
179 	 */
180 	void	(*mpo_associate_vnode_devfs)(struct mount *mp,
181 		    struct label *fslabel, struct devfs_dirent *de,
182 		    struct label *delabel, struct vnode *vp,
183 		    struct label *vlabel);
184 	int	(*mpo_associate_vnode_extattr)(struct mount *mp,
185 		    struct label *fslabel, struct vnode *vp,
186 		    struct label *vlabel);
187 	void	(*mpo_associate_vnode_singlelabel)(struct mount *mp,
188 		    struct label *fslabel, struct vnode *vp,
189 		    struct label *vlabel);
190 	void	(*mpo_create_devfs_device)(struct mount *mp, struct cdev *dev,
191 		    struct devfs_dirent *de, struct label *label);
192 	void	(*mpo_create_devfs_directory)(struct mount *mp, char *dirname,
193 		    int dirnamelen, struct devfs_dirent *de,
194 		    struct label *label);
195 	void	(*mpo_create_devfs_symlink)(struct ucred *cred,
196 		    struct mount *mp, struct devfs_dirent *dd,
197 		    struct label *ddlabel, struct devfs_dirent *de,
198 		    struct label *delabel);
199 	int	(*mpo_create_vnode_extattr)(struct ucred *cred,
200 		    struct mount *mp, struct label *fslabel,
201 		    struct vnode *dvp, struct label *dlabel,
202 		    struct vnode *vp, struct label *vlabel,
203 		    struct componentname *cnp);
204 	void	(*mpo_create_mount)(struct ucred *cred, struct mount *mp,
205 		    struct label *mntlabel, struct label *fslabel);
206 	void	(*mpo_create_root_mount)(struct ucred *cred, struct mount *mp,
207 		    struct label *mountlabel, struct label *fslabel);
208 	void	(*mpo_relabel_vnode)(struct ucred *cred, struct vnode *vp,
209 		    struct label *vnodelabel, struct label *label);
210 	int	(*mpo_setlabel_vnode_extattr)(struct ucred *cred,
211 		    struct vnode *vp, struct label *vlabel,
212 		    struct label *intlabel);
213 	void	(*mpo_update_devfsdirent)(struct mount *mp,
214 		    struct devfs_dirent *devfs_dirent,
215 		    struct label *direntlabel, struct vnode *vp,
216 		    struct label *vnodelabel);
217 
218 	/*
219 	 * Labeling event operations: IPC objects.
220 	 */
221 	void	(*mpo_create_mbuf_from_socket)(struct socket *so,
222 		    struct label *socketlabel, struct mbuf *m,
223 		    struct label *mbuflabel);
224 	void	(*mpo_create_socket)(struct ucred *cred, struct socket *so,
225 		    struct label *socketlabel);
226 	void	(*mpo_create_socket_from_socket)(struct socket *oldsocket,
227 		    struct label *oldsocketlabel, struct socket *newsocket,
228 		    struct label *newsocketlabel);
229 	void	(*mpo_relabel_socket)(struct ucred *cred, struct socket *so,
230 		    struct label *oldlabel, struct label *newlabel);
231 	void	(*mpo_relabel_pipe)(struct ucred *cred, struct pipepair *pp,
232 		    struct label *oldlabel, struct label *newlabel);
233 	void	(*mpo_set_socket_peer_from_mbuf)(struct mbuf *mbuf,
234 		    struct label *mbuflabel, struct socket *so,
235 		    struct label *socketpeerlabel);
236 	void	(*mpo_set_socket_peer_from_socket)(struct socket *oldsocket,
237 		    struct label *oldsocketlabel, struct socket *newsocket,
238 		    struct label *newsocketpeerlabel);
239 	void	(*mpo_create_pipe)(struct ucred *cred, struct pipepair *pp,
240 		    struct label *pipelabel);
241 
242 	/*
243 	 * Labeling event operations: System V IPC primitives.
244 	 */
245 	void	(*mpo_create_sysv_msgmsg)(struct ucred *cred,
246 		    struct msqid_kernel *msqkptr, struct label *msqlabel,
247 		    struct msg *msgptr, struct label *msglabel);
248 	void	(*mpo_create_sysv_msgqueue)(struct ucred *cred,
249 		    struct msqid_kernel *msqkptr, struct label *msqlabel);
250 	void	(*mpo_create_sysv_sema)(struct ucred *cred,
251 		    struct semid_kernel *semakptr, struct label *semalabel);
252 	void	(*mpo_create_sysv_shm)(struct ucred *cred,
253 		    struct shmid_kernel *shmsegptr, struct label *shmlabel);
254 
255 	/*
256 	 * Labeling event operations: network objects.
257 	 */
258 	void	(*mpo_create_bpfdesc)(struct ucred *cred, struct bpf_d *bpf_d,
259 		    struct label *bpflabel);
260 	void	(*mpo_create_ifnet)(struct ifnet *ifnet,
261 		    struct label *ifnetlabel);
262 	void	(*mpo_create_inpcb_from_socket)(struct socket *so,
263 		    struct label *solabel, struct inpcb *inp,
264 		    struct label *inplabel);
265 	void	(*mpo_create_ipq)(struct mbuf *fragment,
266 		    struct label *fragmentlabel, struct ipq *ipq,
267 		    struct label *ipqlabel);
268 	void	(*mpo_create_datagram_from_ipq)
269 		    (struct ipq *ipq, struct label *ipqlabel,
270 		    struct mbuf *datagram, struct label *datagramlabel);
271 	void	(*mpo_create_fragment)(struct mbuf *datagram,
272 		    struct label *datagramlabel, struct mbuf *fragment,
273 		    struct label *fragmentlabel);
274 	void	(*mpo_create_mbuf_from_inpcb)(struct inpcb *inp,
275 		    struct label *inplabel, struct mbuf *m,
276 		    struct label *mlabel);
277 	void	(*mpo_create_mbuf_from_mbuf)(struct mbuf *oldmbuf,
278 		    struct label *oldlabel, struct mbuf *newmbuf,
279 		    struct label *newlabel);
280 	void	(*mpo_create_mbuf_linklayer)(struct ifnet *ifnet,
281 		    struct label *ifnetlabel, struct mbuf *mbuf,
282 		    struct label *mbuflabel);
283 	void	(*mpo_create_mbuf_from_bpfdesc)(struct bpf_d *bpf_d,
284 		    struct label *bpflabel, struct mbuf *mbuf,
285 		    struct label *mbuflabel);
286 	void	(*mpo_create_mbuf_from_ifnet)(struct ifnet *ifnet,
287 		    struct label *ifnetlabel, struct mbuf *mbuf,
288 		    struct label *mbuflabel);
289 	void	(*mpo_create_mbuf_multicast_encap)(struct mbuf *oldmbuf,
290 		    struct label *oldmbuflabel, struct ifnet *ifnet,
291 		    struct label *ifnetlabel, struct mbuf *newmbuf,
292 		    struct label *newmbuflabel);
293 	void	(*mpo_create_mbuf_netlayer)(struct mbuf *oldmbuf,
294 		    struct label *oldmbuflabel, struct mbuf *newmbuf,
295 		    struct label *newmbuflabel);
296 	int	(*mpo_fragment_match)(struct mbuf *fragment,
297 		    struct label *fragmentlabel, struct ipq *ipq,
298 		    struct label *ipqlabel);
299 	void	(*mpo_reflect_mbuf_icmp)(struct mbuf *m,
300 		    struct label *mlabel);
301 	void	(*mpo_reflect_mbuf_tcp)(struct mbuf *m, struct label *mlabel);
302 	void	(*mpo_relabel_ifnet)(struct ucred *cred, struct ifnet *ifnet,
303 		    struct label *ifnetlabel, struct label *newlabel);
304 	void	(*mpo_update_ipq)(struct mbuf *fragment,
305 		    struct label *fragmentlabel, struct ipq *ipq,
306 		    struct label *ipqlabel);
307 	void	(*mpo_inpcb_sosetlabel)(struct socket *so,
308 		    struct label *label, struct inpcb *inp,
309 		    struct label *inplabel);
310 
311 	/*
312 	 * Labeling event operations: processes.
313 	 */
314 	void	(*mpo_execve_transition)(struct ucred *old, struct ucred *new,
315 		    struct vnode *vp, struct label *vnodelabel,
316 		    struct label *interpvnodelabel,
317 		    struct image_params *imgp, struct label *execlabel);
318 	int	(*mpo_execve_will_transition)(struct ucred *old,
319 		    struct vnode *vp, struct label *vnodelabel,
320 		    struct label *interpvnodelabel,
321 		    struct image_params *imgp, struct label *execlabel);
322 	void	(*mpo_create_proc0)(struct ucred *cred);
323 	void	(*mpo_create_proc1)(struct ucred *cred);
324 	void	(*mpo_relabel_cred)(struct ucred *cred,
325 		    struct label *newlabel);
326 	void	(*mpo_thread_userret)(struct thread *thread);
327 
328 	/*
329 	 * Access control checks.
330 	 */
331 	int	(*mpo_check_bpfdesc_receive)(struct bpf_d *bpf_d,
332 		    struct label *bpflabel, struct ifnet *ifnet,
333 		    struct label *ifnetlabel);
334 	int	(*mpo_check_cred_relabel)(struct ucred *cred,
335 		    struct label *newlabel);
336 	int	(*mpo_check_cred_visible)(struct ucred *u1, struct ucred *u2);
337 	int	(*mpo_check_ifnet_relabel)(struct ucred *cred,
338 		    struct ifnet *ifnet, struct label *ifnetlabel,
339 		    struct label *newlabel);
340 	int	(*mpo_check_ifnet_transmit)(struct ifnet *ifnet,
341 		    struct label *ifnetlabel, struct mbuf *m,
342 		    struct label *mbuflabel);
343 	int	(*mpo_check_inpcb_deliver)(struct inpcb *inp,
344 		    struct label *inplabel, struct mbuf *m,
345 		    struct label *mlabel);
346 	int	(*mpo_check_sysv_msgmsq)(struct ucred *cred,
347 		    struct msg *msgptr, struct label *msglabel,
348 		    struct msqid_kernel *msqkptr, struct label *msqklabel);
349 	int	(*mpo_check_sysv_msgrcv)(struct ucred *cred,
350 		    struct msg *msgptr, struct label *msglabel);
351 	int	(*mpo_check_sysv_msgrmid)(struct ucred *cred,
352 		    struct msg *msgptr, struct label *msglabel);
353 	int	(*mpo_check_sysv_msqget)(struct ucred *cred,
354 		    struct msqid_kernel *msqkptr, struct label *msqklabel);
355 	int	(*mpo_check_sysv_msqsnd)(struct ucred *cred,
356 		    struct msqid_kernel *msqkptr, struct label *msqklabel);
357 	int	(*mpo_check_sysv_msqrcv)(struct ucred *cred,
358 		    struct msqid_kernel *msqkptr, struct label *msqklabel);
359 	int	(*mpo_check_sysv_msqctl)(struct ucred *cred,
360 		    struct msqid_kernel *msqkptr, struct label *msqklabel,
361 		    int cmd);
362 	int	(*mpo_check_sysv_semctl)(struct ucred *cred,
363 		    struct semid_kernel *semakptr, struct label *semaklabel,
364 		    int cmd);
365 	int	(*mpo_check_sysv_semget)(struct ucred *cred,
366 		    struct semid_kernel *semakptr, struct label *semaklabel);
367 	int	(*mpo_check_sysv_semop)(struct ucred *cred,
368 		    struct semid_kernel *semakptr, struct label *semaklabel,
369 		    size_t accesstype);
370 	int	(*mpo_check_sysv_shmat)(struct ucred *cred,
371 		    struct shmid_kernel *shmsegptr,
372 		    struct label *shmseglabel, int shmflg);
373 	int	(*mpo_check_sysv_shmctl)(struct ucred *cred,
374 		    struct shmid_kernel *shmsegptr,
375 		    struct label *shmseglabel, int cmd);
376 	int	(*mpo_check_sysv_shmdt)(struct ucred *cred,
377 		    struct shmid_kernel *shmsegptr,
378 		    struct label *shmseglabel);
379 	int	(*mpo_check_sysv_shmget)(struct ucred *cred,
380 		    struct shmid_kernel *shmsegptr,
381 		    struct label *shmseglabel, int shmflg);
382 	int	(*mpo_check_kenv_dump)(struct ucred *cred);
383 	int	(*mpo_check_kenv_get)(struct ucred *cred, char *name);
384 	int	(*mpo_check_kenv_set)(struct ucred *cred, char *name,
385 		    char *value);
386 	int	(*mpo_check_kenv_unset)(struct ucred *cred, char *name);
387 	int	(*mpo_check_kld_load)(struct ucred *cred, struct vnode *vp,
388 		    struct label *vlabel);
389 	int	(*mpo_check_kld_stat)(struct ucred *cred);
390 	int	(*mpo_check_kld_unload)(struct ucred *cred);
391 	int	(*mpo_check_mount_stat)(struct ucred *cred, struct mount *mp,
392 		    struct label *mntlabel);
393 	int	(*mpo_check_pipe_ioctl)(struct ucred *cred,
394 		    struct pipepair *pp, struct label *pipelabel,
395 		    unsigned long cmd, void *data);
396 	int	(*mpo_check_pipe_poll)(struct ucred *cred,
397 		    struct pipepair *pp, struct label *pipelabel);
398 	int	(*mpo_check_pipe_read)(struct ucred *cred,
399 		    struct pipepair *pp, struct label *pipelabel);
400 	int	(*mpo_check_pipe_relabel)(struct ucred *cred,
401 		    struct pipepair *pp, struct label *pipelabel,
402 		    struct label *newlabel);
403 	int	(*mpo_check_pipe_stat)(struct ucred *cred,
404 		    struct pipepair *pp, struct label *pipelabel);
405 	int	(*mpo_check_pipe_write)(struct ucred *cred,
406 		    struct pipepair *pp, struct label *pipelabel);
407 	int	(*mpo_check_proc_debug)(struct ucred *cred,
408 		    struct proc *proc);
409 	int	(*mpo_check_proc_sched)(struct ucred *cred,
410 		    struct proc *proc);
411 	int	(*mpo_check_proc_signal)(struct ucred *cred,
412 		    struct proc *proc, int signum);
413 	int	(*mpo_check_socket_bind)(struct ucred *cred,
414 		    struct socket *so, struct label *socketlabel,
415 		    struct sockaddr *sockaddr);
416 	int	(*mpo_check_socket_connect)(struct ucred *cred,
417 		    struct socket *so, struct label *socketlabel,
418 		    struct sockaddr *sockaddr);
419 	int	(*mpo_check_socket_deliver)(struct socket *so,
420 		    struct label *socketlabel, struct mbuf *m,
421 		    struct label *mbuflabel);
422 	int	(*mpo_check_socket_listen)(struct ucred *cred,
423 		    struct socket *so, struct label *socketlabel);
424 	int	(*mpo_check_socket_receive)(struct ucred *cred,
425 		    struct socket *so, struct label *socketlabel);
426 	int	(*mpo_check_socket_relabel)(struct ucred *cred,
427 		    struct socket *so, struct label *socketlabel,
428 		    struct label *newlabel);
429 	int	(*mpo_check_socket_send)(struct ucred *cred,
430 		    struct socket *so, struct label *socketlabel);
431 	int	(*mpo_check_socket_visible)(struct ucred *cred,
432 		    struct socket *so, struct label *socketlabel);
433 	int	(*mpo_check_sysarch_ioperm)(struct ucred *cred);
434 	int	(*mpo_check_system_acct)(struct ucred *cred,
435 		    struct vnode *vp, struct label *vlabel);
436 	int	(*mpo_check_system_nfsd)(struct ucred *cred);
437 	int	(*mpo_check_system_reboot)(struct ucred *cred, int howto);
438 	int	(*mpo_check_system_settime)(struct ucred *cred);
439 	int	(*mpo_check_system_swapon)(struct ucred *cred,
440 		    struct vnode *vp, struct label *label);
441 	int	(*mpo_check_system_swapoff)(struct ucred *cred,
442 		    struct vnode *vp, struct label *label);
443 	int	(*mpo_check_system_sysctl)(struct ucred *cred,
444 		    struct sysctl_oid *oidp, void *arg1, int arg2,
445 		    struct sysctl_req *req);
446 	int	(*mpo_check_vnode_access)(struct ucred *cred,
447 		    struct vnode *vp, struct label *label, int acc_mode);
448 	int	(*mpo_check_vnode_chdir)(struct ucred *cred,
449 		    struct vnode *dvp, struct label *dlabel);
450 	int	(*mpo_check_vnode_chroot)(struct ucred *cred,
451 		    struct vnode *dvp, struct label *dlabel);
452 	int	(*mpo_check_vnode_create)(struct ucred *cred,
453 		    struct vnode *dvp, struct label *dlabel,
454 		    struct componentname *cnp, struct vattr *vap);
455 	int	(*mpo_check_vnode_delete)(struct ucred *cred,
456 		    struct vnode *dvp, struct label *dlabel,
457 		    struct vnode *vp, struct label *label,
458 		    struct componentname *cnp);
459 	int	(*mpo_check_vnode_deleteacl)(struct ucred *cred,
460 		    struct vnode *vp, struct label *label, acl_type_t type);
461 	int	(*mpo_check_vnode_deleteextattr)(struct ucred *cred,
462 		    struct vnode *vp, struct label *label, int attrnamespace,
463 		    const char *name);
464 	int	(*mpo_check_vnode_exec)(struct ucred *cred, struct vnode *vp,
465 		    struct label *label, struct image_params *imgp,
466 		    struct label *execlabel);
467 	int	(*mpo_check_vnode_getacl)(struct ucred *cred,
468 		    struct vnode *vp, struct label *label, acl_type_t type);
469 	int	(*mpo_check_vnode_getextattr)(struct ucred *cred,
470 		    struct vnode *vp, struct label *label, int attrnamespace,
471 		    const char *name, struct uio *uio);
472 	int	(*mpo_check_vnode_link)(struct ucred *cred, struct vnode *dvp,
473 		    struct label *dlabel, struct vnode *vp,
474 		    struct label *label, struct componentname *cnp);
475 	int	(*mpo_check_vnode_listextattr)(struct ucred *cred,
476 		    struct vnode *vp, struct label *label, int attrnamespace);
477 	int	(*mpo_check_vnode_lookup)(struct ucred *cred,
478 		    struct vnode *dvp, struct label *dlabel,
479 		    struct componentname *cnp);
480 	int	(*mpo_check_vnode_mmap)(struct ucred *cred, struct vnode *vp,
481 		    struct label *label, int prot);
482 	void	(*mpo_check_vnode_mmap_downgrade)(struct ucred *cred,
483 		    struct vnode *vp, struct label *label, int *prot);
484 	int	(*mpo_check_vnode_mprotect)(struct ucred *cred,
485 		    struct vnode *vp, struct label *label, int prot);
486 	int	(*mpo_check_vnode_open)(struct ucred *cred, struct vnode *vp,
487 		    struct label *label, int acc_mode);
488 	int	(*mpo_check_vnode_poll)(struct ucred *active_cred,
489 		    struct ucred *file_cred, struct vnode *vp,
490 		    struct label *label);
491 	int	(*mpo_check_vnode_read)(struct ucred *active_cred,
492 		    struct ucred *file_cred, struct vnode *vp,
493 		    struct label *label);
494 	int	(*mpo_check_vnode_readdir)(struct ucred *cred,
495 		    struct vnode *dvp, struct label *dlabel);
496 	int	(*mpo_check_vnode_readlink)(struct ucred *cred,
497 		    struct vnode *vp, struct label *label);
498 	int	(*mpo_check_vnode_relabel)(struct ucred *cred,
499 		    struct vnode *vp, struct label *vnodelabel,
500 		    struct label *newlabel);
501 	int	(*mpo_check_vnode_rename_from)(struct ucred *cred,
502 		    struct vnode *dvp, struct label *dlabel, struct vnode *vp,
503 		    struct label *label, struct componentname *cnp);
504 	int	(*mpo_check_vnode_rename_to)(struct ucred *cred,
505 		    struct vnode *dvp, struct label *dlabel, struct vnode *vp,
506 		    struct label *label, int samedir,
507 		    struct componentname *cnp);
508 	int	(*mpo_check_vnode_revoke)(struct ucred *cred,
509 		    struct vnode *vp, struct label *label);
510 	int	(*mpo_check_vnode_setacl)(struct ucred *cred,
511 		    struct vnode *vp, struct label *label, acl_type_t type,
512 		    struct acl *acl);
513 	int	(*mpo_check_vnode_setextattr)(struct ucred *cred,
514 		    struct vnode *vp, struct label *label, int attrnamespace,
515 		    const char *name, struct uio *uio);
516 	int	(*mpo_check_vnode_setflags)(struct ucred *cred,
517 		    struct vnode *vp, struct label *label, u_long flags);
518 	int	(*mpo_check_vnode_setmode)(struct ucred *cred,
519 		    struct vnode *vp, struct label *label, mode_t mode);
520 	int	(*mpo_check_vnode_setowner)(struct ucred *cred,
521 		    struct vnode *vp, struct label *label, uid_t uid,
522 		    gid_t gid);
523 	int	(*mpo_check_vnode_setutimes)(struct ucred *cred,
524 		    struct vnode *vp, struct label *label,
525 		    struct timespec atime, struct timespec mtime);
526 	int	(*mpo_check_vnode_stat)(struct ucred *active_cred,
527 		    struct ucred *file_cred, struct vnode *vp,
528 		    struct label *label);
529 	int	(*mpo_check_vnode_write)(struct ucred *active_cred,
530 		    struct ucred *file_cred, struct vnode *vp,
531 		    struct label *label);
532 };
533 
534 /*
535  * struct mac_policy_conf is the registration structure for policies, and is
536  * provided to the MAC Framework using MAC_POLICY_SET() to invoke a SYSINIT
537  * to register the policy.  In general, the fields are immutable, with the
538  * exception of the "security field", run-time flags, and policy list entry,
539  * which are managed by the MAC Framework.  Be careful when modifying this
540  * structure, as its layout is statically compiled into all policies.
541  */
542 struct mac_policy_conf {
543 	char				*mpc_name;	/* policy name */
544 	char				*mpc_fullname;	/* policy full name */
545 	struct mac_policy_ops		*mpc_ops;	/* policy operations */
546 	int				 mpc_loadtime_flags;	/* flags */
547 	int				*mpc_field_off; /* security field */
548 	int				 mpc_runtime_flags; /* flags */
549 	LIST_ENTRY(mac_policy_conf)	 mpc_list;	/* global list */
550 };
551 
552 /* Flags for the mpc_loadtime_flags field. */
553 #define	MPC_LOADTIME_FLAG_NOTLATE	0x00000001
554 #define	MPC_LOADTIME_FLAG_UNLOADOK	0x00000002
555 #define	MPC_LOADTIME_FLAG_LABELMBUFS	0x00000004
556 
557 /* Flags for the mpc_runtime_flags field. */
558 #define	MPC_RUNTIME_FLAG_REGISTERED	0x00000001
559 
560 #define	MAC_POLICY_SET(mpops, mpname, mpfullname, mpflags, privdata_wanted) \
561 	static struct mac_policy_conf mpname##_mac_policy_conf = {	\
562 		#mpname,						\
563 		mpfullname,						\
564 		mpops,							\
565 		mpflags,						\
566 		privdata_wanted,					\
567 		0,							\
568 	};								\
569 	static moduledata_t mpname##_mod = {				\
570 		#mpname,						\
571 		mac_policy_modevent,					\
572 		&mpname##_mac_policy_conf				\
573 	};								\
574 	MODULE_DEPEND(mpname, kernel_mac_support, 2, 2, 2);		\
575 	DECLARE_MODULE(mpname, mpname##_mod, SI_SUB_MAC_POLICY,		\
576 	    SI_ORDER_MIDDLE)
577 
578 int	mac_policy_modevent(module_t mod, int type, void *data);
579 
580 #define	LABEL_TO_SLOT(l, s)	(l)->l_perpolicy[s]
581 
582 #endif /* !_SYS_MAC_POLICY_H_ */
583