xref: /freebsd/sys/security/mac/mac_framework.h (revision 535af610a4fdace6d50960c0ad9be0597eea7a1b)
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  * All rights reserved.
6  *
7  * This software was developed by Robert Watson for the TrustedBSD Project.
8  *
9  * This software was developed for the FreeBSD Project in part by Network
10  * Associates Laboratories, the Security Research Division of Network
11  * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
12  * as part of the DARPA CHATS research program.
13  *
14  * This software was enhanced by SPARTA ISSO under SPAWAR contract
15  * N66001-04-C-6019 ("SEFOS").
16  *
17  * This software was developed at the University of Cambridge Computer
18  * Laboratory with support from a grant from Google, Inc.
19  *
20  * Redistribution and use in source and binary forms, with or without
21  * modification, are permitted provided that the following conditions
22  * are met:
23  * 1. Redistributions of source code must retain the above copyright
24  *    notice, this list of conditions and the following disclaimer.
25  * 2. Redistributions in binary form must reproduce the above copyright
26  *    notice, this list of conditions and the following disclaimer in the
27  *    documentation and/or other materials provided with the distribution.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
30  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
33  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39  * SUCH DAMAGE.
40  *
41  * $FreeBSD$
42  */
43 
44 /*
45  * Kernel interface for Mandatory Access Control -- how kernel services
46  * interact with the TrustedBSD MAC Framework.
47  */
48 
49 #ifndef _SECURITY_MAC_MAC_FRAMEWORK_H_
50 #define	_SECURITY_MAC_MAC_FRAMEWORK_H_
51 
52 #ifndef _KERNEL
53 #error "no user-serviceable parts inside"
54 #endif
55 
56 struct auditinfo;
57 struct auditinfo_addr;
58 struct bpf_d;
59 struct cdev;
60 struct componentname;
61 struct devfs_dirent;
62 struct ifnet;
63 struct ifreq;
64 struct image_params;
65 struct inpcb;
66 struct ip6q;
67 struct ipq;
68 struct kdb_dbbe;
69 struct ksem;
70 struct label;
71 struct m_tag;
72 struct mac;
73 struct mbuf;
74 struct mount;
75 struct msg;
76 struct msqid_kernel;
77 struct proc;
78 struct semid_kernel;
79 struct shmfd;
80 struct shmid_kernel;
81 struct sockaddr;
82 struct socket;
83 struct sysctl_oid;
84 struct sysctl_req;
85 struct pipepair;
86 struct thread;
87 struct timespec;
88 struct ucred;
89 struct vattr;
90 struct vnode;
91 struct vop_setlabel_args;
92 
93 struct in_addr;
94 struct in6_addr;
95 
96 #include <sys/acl.h>			/* XXX acl_type_t */
97 #include <sys/types.h>			/* accmode_t */
98 
99 #include <ddb/ddb.h>			/* db_expr_t */
100 
101 /*
102  * Entry points to the TrustedBSD MAC Framework from the remainder of the
103  * kernel: entry points are named based on a principle object type and an
104  * action relating to it.  They are sorted alphabetically first by object
105  * type and then action.  In some situations, the principle object type is
106  * obvious, and in other cases, less so as multiple objects may be inolved
107  * in the operation.
108  */
109 int	mac_bpfdesc_check_receive(struct bpf_d *d, struct ifnet *ifp);
110 void	mac_bpfdesc_create(struct ucred *cred, struct bpf_d *d);
111 void	mac_bpfdesc_create_mbuf(struct bpf_d *d, struct mbuf *m);
112 void	mac_bpfdesc_destroy(struct bpf_d *);
113 void	mac_bpfdesc_init(struct bpf_d *);
114 
115 void	mac_cred_associate_nfsd(struct ucred *cred);
116 int	mac_cred_check_setaudit(struct ucred *cred, struct auditinfo *ai);
117 int	mac_cred_check_setaudit_addr(struct ucred *cred,
118 	    struct auditinfo_addr *aia);
119 int	mac_cred_check_setauid(struct ucred *cred, uid_t auid);
120 int	mac_cred_check_setegid(struct ucred *cred, gid_t egid);
121 int	mac_cred_check_seteuid(struct ucred *cred, uid_t euid);
122 int	mac_cred_check_setgid(struct ucred *cred, gid_t gid);
123 int	mac_cred_check_setgroups(struct ucred *cred, int ngroups,
124 	    gid_t *gidset);
125 int	mac_cred_check_setregid(struct ucred *cred, gid_t rgid, gid_t egid);
126 int	mac_cred_check_setresgid(struct ucred *cred, gid_t rgid, gid_t egid,
127 	    gid_t sgid);
128 int	mac_cred_check_setresuid(struct ucred *cred, uid_t ruid, uid_t euid,
129 	    uid_t suid);
130 int	mac_cred_check_setreuid(struct ucred *cred, uid_t ruid, uid_t euid);
131 int	mac_cred_check_setuid(struct ucred *cred, uid_t uid);
132 int	mac_cred_check_visible(struct ucred *cr1, struct ucred *cr2);
133 void	mac_cred_copy(struct ucred *cr1, struct ucred *cr2);
134 void	mac_cred_create_init(struct ucred *cred);
135 void	mac_cred_create_swapper(struct ucred *cred);
136 void	mac_cred_destroy(struct ucred *);
137 void	mac_cred_init(struct ucred *);
138 
139 int	mac_ddb_command_register(struct db_command_table *table,
140 	    struct db_command *cmd);
141 int	mac_ddb_command_exec(struct db_command *cmd, db_expr_t addr,
142 	    bool have_addr, db_expr_t count, char *modif);
143 
144 void	mac_devfs_create_device(struct ucred *cred, struct mount *mp,
145 	    struct cdev *dev, struct devfs_dirent *de);
146 void	mac_devfs_create_directory(struct mount *mp, char *dirname,
147 	    int dirnamelen, struct devfs_dirent *de);
148 void	mac_devfs_create_symlink(struct ucred *cred, struct mount *mp,
149 	    struct devfs_dirent *dd, struct devfs_dirent *de);
150 void	mac_devfs_destroy(struct devfs_dirent *);
151 void	mac_devfs_init(struct devfs_dirent *);
152 void	mac_devfs_update(struct mount *mp, struct devfs_dirent *de,
153 	    struct vnode *vp);
154 void	mac_devfs_vnode_associate(struct mount *mp, struct devfs_dirent *de,
155 	    struct vnode *vp);
156 
157 int	mac_ifnet_check_transmit_impl(struct ifnet *ifp, struct mbuf *m);
158 #ifdef MAC
159 extern bool mac_ifnet_check_transmit_fp_flag;
160 #else
161 #define mac_ifnet_check_transmit_fp_flag false
162 #endif
163 #define mac_ifnet_check_transmit_enabled() __predict_false(mac_ifnet_check_transmit_fp_flag)
164 static inline int
165 mac_ifnet_check_transmit(struct ifnet *ifp, struct mbuf *m)
166 {
167 
168 	if (mac_ifnet_check_transmit_enabled())
169 		return (mac_ifnet_check_transmit_impl(ifp, m));
170 	return (0);
171 }
172 
173 void	mac_ifnet_create(struct ifnet *ifp);
174 
175 void	mac_ifnet_create_mbuf_impl(struct ifnet *ifp, struct mbuf *m);
176 #ifdef MAC
177 extern bool mac_ifnet_create_mbuf_fp_flag;
178 #else
179 #define mac_ifnet_create_mbuf_fp_flag false
180 #endif
181 #define mac_ifnet_create_mbuf_enabled() __predict_false(mac_ifnet_create_mbuf_fp_flag)
182 static inline void
183 mac_ifnet_create_mbuf(struct ifnet *ifp, struct mbuf *m)
184 {
185 
186 	if (mac_ifnet_create_mbuf_enabled())
187 		mac_ifnet_create_mbuf_impl(ifp, m);
188 }
189 
190 void	mac_ifnet_destroy(struct ifnet *);
191 void	mac_ifnet_init(struct ifnet *);
192 int	mac_ifnet_ioctl_get(struct ucred *cred, struct ifreq *ifr,
193 	    struct ifnet *ifp);
194 int	mac_ifnet_ioctl_set(struct ucred *cred, struct ifreq *ifr,
195 	    struct ifnet *ifp);
196 
197 /* Check if the IP address is allowed for the interface. */
198 int	mac_inet_check_add_addr(struct ucred *cred,
199 	    const struct in_addr *ia, struct ifnet *ifp);
200 int	mac_inet6_check_add_addr(struct ucred *cred,
201 	    const struct in6_addr *ia6, struct ifnet *ifp);
202 
203 int	mac_inpcb_check_deliver(struct inpcb *inp, struct mbuf *m);
204 int	mac_inpcb_check_visible(struct ucred *cred, struct inpcb *inp);
205 void	mac_inpcb_create(struct socket *so, struct inpcb *inp);
206 void	mac_inpcb_create_mbuf(struct inpcb *inp, struct mbuf *m);
207 void	mac_inpcb_destroy(struct inpcb *);
208 int	mac_inpcb_init(struct inpcb *, int);
209 void	mac_inpcb_sosetlabel(struct socket *so, struct inpcb *inp);
210 
211 void	mac_ip6q_create(struct mbuf *m, struct ip6q *q6);
212 void	mac_ip6q_destroy(struct ip6q *q6);
213 int	mac_ip6q_init(struct ip6q *q6, int);
214 int	mac_ip6q_match(struct mbuf *m, struct ip6q *q6);
215 void	mac_ip6q_reassemble(struct ip6q *q6, struct mbuf *m);
216 void	mac_ip6q_update(struct mbuf *m, struct ip6q *q6);
217 
218 void	mac_ipq_create(struct mbuf *m, struct ipq *q);
219 void	mac_ipq_destroy(struct ipq *q);
220 int	mac_ipq_init(struct ipq *q, int);
221 int	mac_ipq_match(struct mbuf *m, struct ipq *q);
222 void	mac_ipq_reassemble(struct ipq *q, struct mbuf *m);
223 void	mac_ipq_update(struct mbuf *m, struct ipq *q);
224 
225 int	mac_kdb_check_backend(struct kdb_dbbe *be);
226 int	mac_kdb_grant_backend(struct kdb_dbbe *be);
227 
228 int	mac_kenv_check_dump(struct ucred *cred);
229 int	mac_kenv_check_get(struct ucred *cred, char *name);
230 int	mac_kenv_check_set(struct ucred *cred, char *name, char *value);
231 int	mac_kenv_check_unset(struct ucred *cred, char *name);
232 
233 int	mac_kld_check_load(struct ucred *cred, struct vnode *vp);
234 int	mac_kld_check_stat(struct ucred *cred);
235 
236 void	mac_mbuf_copy(struct mbuf *, struct mbuf *);
237 int	mac_mbuf_init(struct mbuf *, int);
238 
239 void	mac_mbuf_tag_copy(struct m_tag *, struct m_tag *);
240 void	mac_mbuf_tag_destroy(struct m_tag *);
241 int	mac_mbuf_tag_init(struct m_tag *, int);
242 
243 int	mac_mount_check_stat(struct ucred *cred, struct mount *mp);
244 void	mac_mount_create(struct ucred *cred, struct mount *mp);
245 void	mac_mount_destroy(struct mount *);
246 void	mac_mount_init(struct mount *);
247 
248 void	mac_netinet_arp_send(struct ifnet *ifp, struct mbuf *m);
249 void	mac_netinet_firewall_reply(struct mbuf *mrecv, struct mbuf *msend);
250 void	mac_netinet_firewall_send(struct mbuf *m);
251 void	mac_netinet_fragment(struct mbuf *m, struct mbuf *frag);
252 void	mac_netinet_icmp_reply(struct mbuf *mrecv, struct mbuf *msend);
253 void	mac_netinet_icmp_replyinplace(struct mbuf *m);
254 void	mac_netinet_igmp_send(struct ifnet *ifp, struct mbuf *m);
255 void	mac_netinet_tcp_reply(struct mbuf *m);
256 
257 void	mac_netinet6_nd6_send(struct ifnet *ifp, struct mbuf *m);
258 
259 int	mac_pipe_check_ioctl(struct ucred *cred, struct pipepair *pp,
260 	    unsigned long cmd, void *data);
261 int	mac_pipe_check_poll_impl(struct ucred *cred, struct pipepair *pp);
262 #ifdef MAC
263 extern bool mac_pipe_check_poll_fp_flag;
264 #else
265 #define mac_pipe_check_poll_fp_flag false
266 #endif
267 #define mac_pipe_check_poll_enabled() __predict_false(mac_pipe_check_poll_fp_flag)
268 static inline int
269 mac_pipe_check_poll(struct ucred *cred, struct pipepair *pp)
270 {
271 
272 	if (mac_pipe_check_poll_enabled())
273 		return (mac_pipe_check_poll_impl(cred, pp));
274 	return (0);
275 }
276 
277 #ifdef MAC
278 extern bool mac_pipe_check_stat_fp_flag;
279 #else
280 #define mac_pipe_check_stat_fp_flag false
281 #endif
282 #define mac_pipe_check_stat_enabled() __predict_false(mac_pipe_check_stat_fp_flag)
283 int	mac_pipe_check_stat(struct ucred *cred, struct pipepair *pp);
284 int	mac_pipe_check_read_impl(struct ucred *cred, struct pipepair *pp);
285 #ifdef MAC
286 extern bool mac_pipe_check_read_fp_flag;
287 #else
288 #define mac_pipe_check_read_fp_flag false
289 #endif
290 #define mac_pipe_check_read_enabled() __predict_false(mac_pipe_check_read_fp_flag)
291 static inline int
292 mac_pipe_check_read(struct ucred *cred, struct pipepair *pp)
293 {
294 
295 	if (mac_pipe_check_read_enabled())
296 		return (mac_pipe_check_read_impl(cred, pp));
297 	return (0);
298 }
299 
300 int	mac_pipe_check_write(struct ucred *cred, struct pipepair *pp);
301 void	mac_pipe_create(struct ucred *cred, struct pipepair *pp);
302 void	mac_pipe_destroy(struct pipepair *);
303 void	mac_pipe_init(struct pipepair *);
304 int	mac_pipe_label_set(struct ucred *cred, struct pipepair *pp,
305 	    struct label *label);
306 
307 int	mac_posixsem_check_getvalue(struct ucred *active_cred,
308 	    struct ucred *file_cred, struct ksem *ks);
309 int	mac_posixsem_check_open(struct ucred *cred, struct ksem *ks);
310 int	mac_posixsem_check_post(struct ucred *active_cred,
311 	    struct ucred *file_cred, struct ksem *ks);
312 int	mac_posixsem_check_setmode(struct ucred *cred, struct ksem *ks,
313 	    mode_t mode);
314 int	mac_posixsem_check_setowner(struct ucred *cred, struct ksem *ks,
315 	    uid_t uid, gid_t gid);
316 int	mac_posixsem_check_stat(struct ucred *active_cred,
317 	    struct ucred *file_cred, struct ksem *ks);
318 int	mac_posixsem_check_unlink(struct ucred *cred, struct ksem *ks);
319 int	mac_posixsem_check_wait(struct ucred *active_cred,
320 	    struct ucred *file_cred, struct ksem *ks);
321 void 	mac_posixsem_create(struct ucred *cred, struct ksem *ks);
322 void	mac_posixsem_destroy(struct ksem *);
323 void	mac_posixsem_init(struct ksem *);
324 
325 int	mac_posixshm_check_create(struct ucred *cred, const char *path);
326 int	mac_posixshm_check_mmap(struct ucred *cred, struct shmfd *shmfd,
327 	    int prot, int flags);
328 int	mac_posixshm_check_open(struct ucred *cred, struct shmfd *shmfd,
329 	    accmode_t accmode);
330 int	mac_posixshm_check_read(struct ucred *active_cred,
331 	    struct ucred *file_cred, struct shmfd *shmfd);
332 int	mac_posixshm_check_setmode(struct ucred *cred, struct shmfd *shmfd,
333 	    mode_t mode);
334 int	mac_posixshm_check_setowner(struct ucred *cred, struct shmfd *shmfd,
335 	    uid_t uid, gid_t gid);
336 int	mac_posixshm_check_stat(struct ucred *active_cred,
337 	    struct ucred *file_cred, struct shmfd *shmfd);
338 int	mac_posixshm_check_truncate(struct ucred *active_cred,
339 	    struct ucred *file_cred, struct shmfd *shmfd);
340 int	mac_posixshm_check_unlink(struct ucred *cred, struct shmfd *shmfd);
341 int	mac_posixshm_check_write(struct ucred *active_cred,
342 	    struct ucred *file_cred, struct shmfd *shmfd);
343 void 	mac_posixshm_create(struct ucred *cred, struct shmfd *shmfd);
344 void	mac_posixshm_destroy(struct shmfd *);
345 void	mac_posixshm_init(struct shmfd *);
346 
347 int	mac_priv_check_impl(struct ucred *cred, int priv);
348 #ifdef MAC
349 extern bool mac_priv_check_fp_flag;
350 #else
351 #define mac_priv_check_fp_flag false
352 #endif
353 #define mac_priv_check_enabled()	__predict_false(mac_priv_check_fp_flag)
354 static inline int
355 mac_priv_check(struct ucred *cred, int priv)
356 {
357 
358 	if (mac_priv_check_enabled())
359 		return (mac_priv_check_impl(cred, priv));
360 	return (0);
361 }
362 
363 int	mac_priv_grant_impl(struct ucred *cred, int priv);
364 #ifdef MAC
365 extern bool mac_priv_grant_fp_flag;
366 #else
367 #define mac_priv_grant_fp_flag false
368 #endif
369 #define mac_priv_grant_enabled()	__predict_false(mac_priv_grant_fp_flag)
370 static inline int
371 mac_priv_grant(struct ucred *cred, int priv)
372 {
373 
374 	if (mac_priv_grant_enabled())
375 		return (mac_priv_grant_impl(cred, priv));
376 	return (EPERM);
377 }
378 
379 int	mac_proc_check_debug(struct ucred *cred, struct proc *p);
380 int	mac_proc_check_sched(struct ucred *cred, struct proc *p);
381 int	mac_proc_check_signal(struct ucred *cred, struct proc *p,
382 	    int signum);
383 int	mac_proc_check_wait(struct ucred *cred, struct proc *p);
384 void	mac_proc_destroy(struct proc *);
385 void	mac_proc_init(struct proc *);
386 void	mac_proc_vm_revoke(struct thread *td);
387 int	mac_execve_enter(struct image_params *imgp, struct mac *mac_p);
388 void	mac_execve_exit(struct image_params *imgp);
389 void	mac_execve_interpreter_enter(struct vnode *interpvp,
390 	    struct label **interplabel);
391 void	mac_execve_interpreter_exit(struct label *interpvplabel);
392 
393 int	mac_socket_check_accept(struct ucred *cred, struct socket *so);
394 int	mac_socket_check_bind(struct ucred *cred, struct socket *so,
395 	    struct sockaddr *sa);
396 int	mac_socket_check_connect(struct ucred *cred, struct socket *so,
397 	    struct sockaddr *sa);
398 int	mac_socket_check_create(struct ucred *cred, int domain, int type,
399 	    int proto);
400 int	mac_socket_check_deliver(struct socket *so, struct mbuf *m);
401 int	mac_socket_check_listen(struct ucred *cred, struct socket *so);
402 int	mac_socket_check_poll(struct ucred *cred, struct socket *so);
403 int	mac_socket_check_receive(struct ucred *cred, struct socket *so);
404 int	mac_socket_check_send(struct ucred *cred, struct socket *so);
405 int	mac_socket_check_stat(struct ucred *cred, struct socket *so);
406 int	mac_socket_check_visible(struct ucred *cred, struct socket *so);
407 void	mac_socket_create_mbuf(struct socket *so, struct mbuf *m);
408 void	mac_socket_create(struct ucred *cred, struct socket *so);
409 void	mac_socket_destroy(struct socket *);
410 int	mac_socket_init(struct socket *, int);
411 void	mac_socket_newconn(struct socket *oldso, struct socket *newso);
412 int	mac_getsockopt_label(struct ucred *cred, struct socket *so,
413 	    struct mac *extmac);
414 int	mac_getsockopt_peerlabel(struct ucred *cred, struct socket *so,
415 	    struct mac *extmac);
416 int	mac_setsockopt_label(struct ucred *cred, struct socket *so,
417 	    struct mac *extmac);
418 
419 void	mac_socketpeer_set_from_mbuf(struct mbuf *m, struct socket *so);
420 void	mac_socketpeer_set_from_socket(struct socket *oldso,
421 	    struct socket *newso);
422 
423 void	mac_syncache_create(struct label *l, struct inpcb *inp);
424 void	mac_syncache_create_mbuf(struct label *l, struct mbuf *m);
425 void	mac_syncache_destroy(struct label **l);
426 int	mac_syncache_init(struct label **l);
427 
428 int	mac_system_check_acct(struct ucred *cred, struct vnode *vp);
429 int	mac_system_check_audit(struct ucred *cred, void *record, int length);
430 int	mac_system_check_auditctl(struct ucred *cred, struct vnode *vp);
431 int	mac_system_check_auditon(struct ucred *cred, int cmd);
432 int	mac_system_check_reboot(struct ucred *cred, int howto);
433 int	mac_system_check_swapon(struct ucred *cred, struct vnode *vp);
434 int	mac_system_check_swapoff(struct ucred *cred, struct vnode *vp);
435 int	mac_system_check_sysctl(struct ucred *cred, struct sysctl_oid *oidp,
436 	    void *arg1, int arg2, struct sysctl_req *req);
437 
438 void	mac_sysvmsg_cleanup(struct msg *msgptr);
439 void	mac_sysvmsg_create(struct ucred *cred, struct msqid_kernel *msqkptr,
440 	    struct msg *msgptr);
441 void	mac_sysvmsg_destroy(struct msg *);
442 void	mac_sysvmsg_init(struct msg *);
443 
444 int	mac_sysvmsq_check_msgmsq(struct ucred *cred, struct msg *msgptr,
445 	    struct msqid_kernel *msqkptr);
446 int	mac_sysvmsq_check_msgrcv(struct ucred *cred, struct msg *msgptr);
447 int	mac_sysvmsq_check_msgrmid(struct ucred *cred, struct msg *msgptr);
448 int	mac_sysvmsq_check_msqctl(struct ucred *cred,
449 	    struct msqid_kernel *msqkptr, int cmd);
450 int	mac_sysvmsq_check_msqget(struct ucred *cred,
451 	    struct msqid_kernel *msqkptr);
452 int	mac_sysvmsq_check_msqrcv(struct ucred *cred,
453 	    struct msqid_kernel *msqkptr);
454 int	mac_sysvmsq_check_msqsnd(struct ucred *cred,
455 	    struct msqid_kernel *msqkptr);
456 void	mac_sysvmsq_cleanup(struct msqid_kernel *msqkptr);
457 void	mac_sysvmsq_create(struct ucred *cred, struct msqid_kernel *msqkptr);
458 void	mac_sysvmsq_destroy(struct msqid_kernel *);
459 void	mac_sysvmsq_init(struct msqid_kernel *);
460 
461 int	mac_sysvsem_check_semctl(struct ucred *cred,
462 	    struct semid_kernel *semakptr, int cmd);
463 int	mac_sysvsem_check_semget(struct ucred *cred,
464 	   struct semid_kernel *semakptr);
465 int	mac_sysvsem_check_semop(struct ucred *cred,
466 	    struct semid_kernel *semakptr, size_t accesstype);
467 void	mac_sysvsem_cleanup(struct semid_kernel *semakptr);
468 void	mac_sysvsem_create(struct ucred *cred,
469 	    struct semid_kernel *semakptr);
470 void	mac_sysvsem_destroy(struct semid_kernel *);
471 void	mac_sysvsem_init(struct semid_kernel *);
472 
473 int	mac_sysvshm_check_shmat(struct ucred *cred,
474 	    struct shmid_kernel *shmsegptr, int shmflg);
475 int	mac_sysvshm_check_shmctl(struct ucred *cred,
476 	    struct shmid_kernel *shmsegptr, int cmd);
477 int	mac_sysvshm_check_shmdt(struct ucred *cred,
478 	    struct shmid_kernel *shmsegptr);
479 int	mac_sysvshm_check_shmget(struct ucred *cred,
480 	    struct shmid_kernel *shmsegptr, int shmflg);
481 void	mac_sysvshm_cleanup(struct shmid_kernel *shmsegptr);
482 void	mac_sysvshm_create(struct ucred *cred,
483 	    struct shmid_kernel *shmsegptr);
484 void	mac_sysvshm_destroy(struct shmid_kernel *);
485 void	mac_sysvshm_init(struct shmid_kernel *);
486 
487 void	mac_thread_userret(struct thread *td);
488 
489 #if defined(MAC) && defined(DEBUG_VFS_LOCKS)
490 void	mac_vnode_assert_locked(struct vnode *vp, const char *func);
491 #else
492 #define mac_vnode_assert_locked(vp, func) do { } while (0)
493 #endif
494 
495 int	mac_vnode_associate_extattr(struct mount *mp, struct vnode *vp);
496 void	mac_vnode_associate_singlelabel(struct mount *mp, struct vnode *vp);
497 int	mac_vnode_check_access_impl(struct ucred *cred, struct vnode *dvp,
498 	    accmode_t accmode);
499 extern bool mac_vnode_check_access_fp_flag;
500 #define mac_vnode_check_access_enabled() __predict_false(mac_vnode_check_access_fp_flag)
501 static inline int
502 mac_vnode_check_access(struct ucred *cred, struct vnode *dvp,
503     accmode_t accmode)
504 {
505 
506 	mac_vnode_assert_locked(dvp, "mac_vnode_check_access");
507 	if (mac_vnode_check_access_enabled())
508                 return (mac_vnode_check_access_impl(cred, dvp, accmode));
509 	return (0);
510 }
511 int	mac_vnode_check_chdir(struct ucred *cred, struct vnode *dvp);
512 int	mac_vnode_check_chroot(struct ucred *cred, struct vnode *dvp);
513 int	mac_vnode_check_create(struct ucred *cred, struct vnode *dvp,
514 	    struct componentname *cnp, struct vattr *vap);
515 int	mac_vnode_check_deleteacl(struct ucred *cred, struct vnode *vp,
516 	    acl_type_t type);
517 int	mac_vnode_check_deleteextattr(struct ucred *cred, struct vnode *vp,
518 	    int attrnamespace, const char *name);
519 int	mac_vnode_check_exec(struct ucred *cred, struct vnode *vp,
520 	    struct image_params *imgp);
521 int	mac_vnode_check_getacl(struct ucred *cred, struct vnode *vp,
522 	    acl_type_t type);
523 int	mac_vnode_check_getextattr(struct ucred *cred, struct vnode *vp,
524 	    int attrnamespace, const char *name);
525 int	mac_vnode_check_link(struct ucred *cred, struct vnode *dvp,
526 	    struct vnode *vp, struct componentname *cnp);
527 int	mac_vnode_check_listextattr(struct ucred *cred, struct vnode *vp,
528 	    int attrnamespace);
529 
530 int	mac_vnode_check_lookup_impl(struct ucred *cred, struct vnode *dvp,
531  	    struct componentname *cnp);
532 #ifdef MAC
533 extern bool mac_vnode_check_lookup_fp_flag;
534 #else
535 #define mac_vnode_check_lookup_fp_flag false
536 #endif
537 #define mac_vnode_check_lookup_enabled() __predict_false(mac_vnode_check_lookup_fp_flag)
538 static inline int
539 mac_vnode_check_lookup(struct ucred *cred, struct vnode *dvp,
540     struct componentname *cnp)
541 {
542 
543 	mac_vnode_assert_locked(dvp, "mac_vnode_check_lookup");
544 	if (mac_vnode_check_lookup_enabled())
545                 return (mac_vnode_check_lookup_impl(cred, dvp, cnp));
546 	return (0);
547 }
548 
549 int	mac_vnode_check_mmap_impl(struct ucred *cred, struct vnode *vp, int prot,
550 	    int flags);
551 #ifdef MAC
552 extern bool mac_vnode_check_mmap_fp_flag;
553 #else
554 #define mac_vnode_check_mmap_fp_flag false
555 #endif
556 #define mac_vnode_check_mmap_enabled() __predict_false(mac_vnode_check_mmap_fp_flag)
557 static inline int
558 mac_vnode_check_mmap(struct ucred *cred, struct vnode *vp, int prot,
559     int flags)
560 {
561 
562 	mac_vnode_assert_locked(vp, "mac_vnode_check_mmap");
563 	if (mac_vnode_check_mmap_enabled())
564 		return (mac_vnode_check_mmap_impl(cred, vp, prot, flags));
565 	return (0);
566 }
567 
568 int	mac_vnode_check_open_impl(struct ucred *cred, struct vnode *vp,
569 	    accmode_t accmode);
570 #ifdef MAC
571 extern bool mac_vnode_check_open_fp_flag;
572 #else
573 #define mac_vnode_check_open_fp_flag false
574 #endif
575 #define mac_vnode_check_open_enabled() __predict_false(mac_vnode_check_open_fp_flag)
576 static inline int
577 mac_vnode_check_open(struct ucred *cred, struct vnode *vp,
578     accmode_t accmode)
579 {
580 
581 	mac_vnode_assert_locked(vp, "mac_vnode_check_open");
582 	if (mac_vnode_check_open_enabled())
583 		return (mac_vnode_check_open_impl(cred, vp, accmode));
584 	return (0);
585 }
586 
587 int	mac_vnode_check_mprotect(struct ucred *cred, struct vnode *vp,
588 	    int prot);
589 
590 #define mac_vnode_check_poll_enabled() __predict_false(mac_vnode_check_poll_fp_flag)
591 #ifdef MAC
592 extern bool mac_vnode_check_poll_fp_flag;
593 int	mac_vnode_check_poll(struct ucred *active_cred,
594 	    struct ucred *file_cred, struct vnode *vp);
595 #else
596 #define mac_vnode_check_poll_fp_flag	false
597 static inline int
598 mac_vnode_check_poll(struct ucred *active_cred, struct ucred *file_cred,
599     struct vnode *vp)
600 {
601 
602 	return (0);
603 }
604 #endif
605 int	mac_vnode_check_readdir(struct ucred *cred, struct vnode *vp);
606 int	mac_vnode_check_readlink_impl(struct ucred *cred, struct vnode *dvp);
607 #ifdef MAC
608 extern bool mac_vnode_check_readlink_fp_flag;
609 #else
610 #define mac_vnode_check_readlink_fp_flag false
611 #endif
612 #define mac_vnode_check_readlink_enabled() __predict_false(mac_vnode_check_readlink_fp_flag)
613 static inline int
614 mac_vnode_check_readlink(struct ucred *cred, struct vnode *vp)
615 {
616 
617 	mac_vnode_assert_locked(vp, "mac_vnode_check_readlink");
618 	if (mac_vnode_check_readlink_enabled())
619 		return (mac_vnode_check_readlink_impl(cred, vp));
620 	return (0);
621 }
622 #define mac_vnode_check_rename_from_enabled() __predict_false(mac_vnode_check_rename_from_fp_flag)
623 #ifdef MAC
624 extern bool mac_vnode_check_rename_from_fp_flag;
625 #endif
626 int	mac_vnode_check_rename_from(struct ucred *cred, struct vnode *dvp,
627 	    struct vnode *vp, struct componentname *cnp);
628 int	mac_vnode_check_rename_to(struct ucred *cred, struct vnode *dvp,
629 	    struct vnode *vp, int samedir, struct componentname *cnp);
630 int	mac_vnode_check_revoke(struct ucred *cred, struct vnode *vp);
631 int	mac_vnode_check_setacl(struct ucred *cred, struct vnode *vp,
632 	    acl_type_t type, struct acl *acl);
633 int	mac_vnode_check_setextattr(struct ucred *cred, struct vnode *vp,
634 	    int attrnamespace, const char *name);
635 int	mac_vnode_check_setflags(struct ucred *cred, struct vnode *vp,
636 	    u_long flags);
637 int	mac_vnode_check_setmode(struct ucred *cred, struct vnode *vp,
638 	    mode_t mode);
639 int	mac_vnode_check_setowner(struct ucred *cred, struct vnode *vp,
640 	    uid_t uid, gid_t gid);
641 int	mac_vnode_check_setutimes(struct ucred *cred, struct vnode *vp,
642 	    struct timespec atime, struct timespec mtime);
643 
644 int	mac_vnode_check_stat_impl(struct ucred *active_cred,
645 	    struct ucred *file_cred, struct vnode *vp);
646 #ifdef MAC
647 extern bool mac_vnode_check_stat_fp_flag;
648 #else
649 #define mac_vnode_check_stat_fp_flag false
650 #endif
651 #define mac_vnode_check_stat_enabled()	__predict_false(mac_vnode_check_stat_fp_flag)
652 static inline int
653 mac_vnode_check_stat(struct ucred *active_cred, struct ucred *file_cred,
654     struct vnode *vp)
655 {
656 
657 	mac_vnode_assert_locked(vp, "mac_vnode_check_stat");
658 	if (mac_vnode_check_stat_enabled())
659 		return (mac_vnode_check_stat_impl(active_cred, file_cred, vp));
660 	return (0);
661 }
662 
663 int	mac_vnode_check_read_impl(struct ucred *active_cred,
664 	    struct ucred *file_cred, struct vnode *vp);
665 #ifdef MAC
666 extern bool mac_vnode_check_read_fp_flag;
667 #else
668 #define mac_vnode_check_read_fp_flag false
669 #endif
670 #define mac_vnode_check_read_enabled() __predict_false(mac_vnode_check_read_fp_flag)
671 static inline int
672 mac_vnode_check_read(struct ucred *active_cred, struct ucred *file_cred,
673     struct vnode *vp)
674 {
675 
676 	mac_vnode_assert_locked(vp, "mac_vnode_check_read");
677 	if (mac_vnode_check_read_enabled())
678 		return (mac_vnode_check_read_impl(active_cred, file_cred, vp));
679 	return (0);
680 }
681 
682 int	mac_vnode_check_write_impl(struct ucred *active_cred,
683 	    struct ucred *file_cred, struct vnode *vp);
684 #ifdef MAC
685 extern bool mac_vnode_check_write_fp_flag;
686 #else
687 #define mac_vnode_check_write_fp_flag false
688 #endif
689 #define mac_vnode_check_write_enabled() __predict_false(mac_vnode_check_write_fp_flag)
690 static inline int
691 mac_vnode_check_write(struct ucred *active_cred, struct ucred *file_cred,
692     struct vnode *vp)
693 {
694 
695 	mac_vnode_assert_locked(vp, "mac_vnode_check_write");
696 	if (mac_vnode_check_write_enabled())
697 		return (mac_vnode_check_write_impl(active_cred, file_cred, vp));
698 	return (0);
699 }
700 
701 int	mac_vnode_check_unlink(struct ucred *cred, struct vnode *dvp,
702 	    struct vnode *vp, struct componentname *cnp);
703 void	mac_vnode_copy_label(struct label *, struct label *);
704 void	mac_vnode_init(struct vnode *);
705 int	mac_vnode_create_extattr(struct ucred *cred, struct mount *mp,
706 	    struct vnode *dvp, struct vnode *vp, struct componentname *cnp);
707 void	mac_vnode_destroy(struct vnode *);
708 void	mac_vnode_execve_transition(struct ucred *oldcred,
709 	    struct ucred *newcred, struct vnode *vp,
710 	    struct label *interpvplabel, struct image_params *imgp);
711 int	mac_vnode_execve_will_transition(struct ucred *cred,
712 	    struct vnode *vp, struct label *interpvplabel,
713 	    struct image_params *imgp);
714 void	mac_vnode_relabel(struct ucred *cred, struct vnode *vp,
715 	    struct label *newlabel);
716 
717 /*
718  * Calls to help various file systems implement labeling functionality using
719  * their existing EA implementation.
720  */
721 int	vop_stdsetlabel_ea(struct vop_setlabel_args *ap);
722 
723 #endif /* !_SECURITY_MAC_MAC_FRAMEWORK_H_ */
724