xref: /freebsd/sys/security/mac/mac_framework.h (revision 6be3386466ab79a84b48429ae66244f21526d3df)
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 ksem;
69 struct label;
70 struct m_tag;
71 struct mac;
72 struct mbuf;
73 struct mount;
74 struct msg;
75 struct msqid_kernel;
76 struct proc;
77 struct semid_kernel;
78 struct shmfd;
79 struct shmid_kernel;
80 struct sockaddr;
81 struct socket;
82 struct sysctl_oid;
83 struct sysctl_req;
84 struct pipepair;
85 struct thread;
86 struct timespec;
87 struct ucred;
88 struct vattr;
89 struct vnode;
90 struct vop_setlabel_args;
91 
92 #include <sys/acl.h>			/* XXX acl_type_t */
93 #include <sys/types.h>			/* accmode_t */
94 
95 /*
96  * Entry points to the TrustedBSD MAC Framework from the remainder of the
97  * kernel: entry points are named based on a principle object type and an
98  * action relating to it.  They are sorted alphabetically first by object
99  * type and then action.  In some situations, the principle object type is
100  * obvious, and in other cases, less so as multiple objects may be inolved
101  * in the operation.
102  */
103 int	mac_bpfdesc_check_receive(struct bpf_d *d, struct ifnet *ifp);
104 void	mac_bpfdesc_create(struct ucred *cred, struct bpf_d *d);
105 void	mac_bpfdesc_create_mbuf(struct bpf_d *d, struct mbuf *m);
106 void	mac_bpfdesc_destroy(struct bpf_d *);
107 void	mac_bpfdesc_init(struct bpf_d *);
108 
109 void	mac_cred_associate_nfsd(struct ucred *cred);
110 int	mac_cred_check_setaudit(struct ucred *cred, struct auditinfo *ai);
111 int	mac_cred_check_setaudit_addr(struct ucred *cred,
112 	    struct auditinfo_addr *aia);
113 int	mac_cred_check_setauid(struct ucred *cred, uid_t auid);
114 int	mac_cred_check_setegid(struct ucred *cred, gid_t egid);
115 int	mac_cred_check_seteuid(struct ucred *cred, uid_t euid);
116 int	mac_cred_check_setgid(struct ucred *cred, gid_t gid);
117 int	mac_cred_check_setgroups(struct ucred *cred, int ngroups,
118 	    gid_t *gidset);
119 int	mac_cred_check_setregid(struct ucred *cred, gid_t rgid, gid_t egid);
120 int	mac_cred_check_setresgid(struct ucred *cred, gid_t rgid, gid_t egid,
121 	    gid_t sgid);
122 int	mac_cred_check_setresuid(struct ucred *cred, uid_t ruid, uid_t euid,
123 	    uid_t suid);
124 int	mac_cred_check_setreuid(struct ucred *cred, uid_t ruid, uid_t euid);
125 int	mac_cred_check_setuid(struct ucred *cred, uid_t uid);
126 int	mac_cred_check_visible(struct ucred *cr1, struct ucred *cr2);
127 void	mac_cred_copy(struct ucred *cr1, struct ucred *cr2);
128 void	mac_cred_create_init(struct ucred *cred);
129 void	mac_cred_create_swapper(struct ucred *cred);
130 void	mac_cred_destroy(struct ucred *);
131 void	mac_cred_init(struct ucred *);
132 
133 void	mac_devfs_create_device(struct ucred *cred, struct mount *mp,
134 	    struct cdev *dev, struct devfs_dirent *de);
135 void	mac_devfs_create_directory(struct mount *mp, char *dirname,
136 	    int dirnamelen, struct devfs_dirent *de);
137 void	mac_devfs_create_symlink(struct ucred *cred, struct mount *mp,
138 	    struct devfs_dirent *dd, struct devfs_dirent *de);
139 void	mac_devfs_destroy(struct devfs_dirent *);
140 void	mac_devfs_init(struct devfs_dirent *);
141 void	mac_devfs_update(struct mount *mp, struct devfs_dirent *de,
142 	    struct vnode *vp);
143 void	mac_devfs_vnode_associate(struct mount *mp, struct devfs_dirent *de,
144 	    struct vnode *vp);
145 
146 int	mac_ifnet_check_transmit(struct ifnet *ifp, struct mbuf *m);
147 void	mac_ifnet_create(struct ifnet *ifp);
148 void	mac_ifnet_create_mbuf(struct ifnet *ifp, struct mbuf *m);
149 void	mac_ifnet_destroy(struct ifnet *);
150 void	mac_ifnet_init(struct ifnet *);
151 int	mac_ifnet_ioctl_get(struct ucred *cred, struct ifreq *ifr,
152 	    struct ifnet *ifp);
153 int	mac_ifnet_ioctl_set(struct ucred *cred, struct ifreq *ifr,
154 	    struct ifnet *ifp);
155 
156 int	mac_inpcb_check_deliver(struct inpcb *inp, struct mbuf *m);
157 int	mac_inpcb_check_visible(struct ucred *cred, struct inpcb *inp);
158 void	mac_inpcb_create(struct socket *so, struct inpcb *inp);
159 void	mac_inpcb_create_mbuf(struct inpcb *inp, struct mbuf *m);
160 void	mac_inpcb_destroy(struct inpcb *);
161 int	mac_inpcb_init(struct inpcb *, int);
162 void	mac_inpcb_sosetlabel(struct socket *so, struct inpcb *inp);
163 
164 void	mac_ip6q_create(struct mbuf *m, struct ip6q *q6);
165 void	mac_ip6q_destroy(struct ip6q *q6);
166 int	mac_ip6q_init(struct ip6q *q6, int);
167 int	mac_ip6q_match(struct mbuf *m, struct ip6q *q6);
168 void	mac_ip6q_reassemble(struct ip6q *q6, struct mbuf *m);
169 void	mac_ip6q_update(struct mbuf *m, struct ip6q *q6);
170 
171 void	mac_ipq_create(struct mbuf *m, struct ipq *q);
172 void	mac_ipq_destroy(struct ipq *q);
173 int	mac_ipq_init(struct ipq *q, int);
174 int	mac_ipq_match(struct mbuf *m, struct ipq *q);
175 void	mac_ipq_reassemble(struct ipq *q, struct mbuf *m);
176 void	mac_ipq_update(struct mbuf *m, struct ipq *q);
177 
178 int	mac_kenv_check_dump(struct ucred *cred);
179 int	mac_kenv_check_get(struct ucred *cred, char *name);
180 int	mac_kenv_check_set(struct ucred *cred, char *name, char *value);
181 int	mac_kenv_check_unset(struct ucred *cred, char *name);
182 
183 int	mac_kld_check_load(struct ucred *cred, struct vnode *vp);
184 int	mac_kld_check_stat(struct ucred *cred);
185 
186 void	mac_mbuf_copy(struct mbuf *, struct mbuf *);
187 int	mac_mbuf_init(struct mbuf *, int);
188 
189 void	mac_mbuf_tag_copy(struct m_tag *, struct m_tag *);
190 void	mac_mbuf_tag_destroy(struct m_tag *);
191 int	mac_mbuf_tag_init(struct m_tag *, int);
192 
193 int	mac_mount_check_stat(struct ucred *cred, struct mount *mp);
194 void	mac_mount_create(struct ucred *cred, struct mount *mp);
195 void	mac_mount_destroy(struct mount *);
196 void	mac_mount_init(struct mount *);
197 
198 void	mac_netinet_arp_send(struct ifnet *ifp, struct mbuf *m);
199 void	mac_netinet_firewall_reply(struct mbuf *mrecv, struct mbuf *msend);
200 void	mac_netinet_firewall_send(struct mbuf *m);
201 void	mac_netinet_fragment(struct mbuf *m, struct mbuf *frag);
202 void	mac_netinet_icmp_reply(struct mbuf *mrecv, struct mbuf *msend);
203 void	mac_netinet_icmp_replyinplace(struct mbuf *m);
204 void	mac_netinet_igmp_send(struct ifnet *ifp, struct mbuf *m);
205 void	mac_netinet_tcp_reply(struct mbuf *m);
206 
207 void	mac_netinet6_nd6_send(struct ifnet *ifp, struct mbuf *m);
208 
209 int	mac_pipe_check_ioctl(struct ucred *cred, struct pipepair *pp,
210 	    unsigned long cmd, void *data);
211 int	mac_pipe_check_poll_impl(struct ucred *cred, struct pipepair *pp);
212 #ifdef MAC
213 extern bool mac_pipe_check_poll_fp_flag;
214 #else
215 #define mac_pipe_check_poll_fp_flag 0
216 #endif
217 #define mac_pipe_check_poll_enabled() __predict_false(mac_pipe_check_poll_fp_flag)
218 static inline int
219 mac_pipe_check_poll(struct ucred *cred, struct pipepair *pp)
220 {
221 
222 	if (mac_pipe_check_poll_enabled())
223 		return (mac_pipe_check_poll_impl(cred, pp));
224 	return (0);
225 }
226 
227 #ifdef MAC
228 extern bool mac_pipe_check_stat_fp_flag;
229 #else
230 #define mac_pipe_check_stat_fp_flag 0
231 #endif
232 #define mac_pipe_check_stat_enabled() __predict_false(mac_pipe_check_stat_fp_flag)
233 int	mac_pipe_check_stat(struct ucred *cred, struct pipepair *pp);
234 int	mac_pipe_check_read(struct ucred *cred, struct pipepair *pp);
235 int	mac_pipe_check_write(struct ucred *cred, struct pipepair *pp);
236 void	mac_pipe_create(struct ucred *cred, struct pipepair *pp);
237 void	mac_pipe_destroy(struct pipepair *);
238 void	mac_pipe_init(struct pipepair *);
239 int	mac_pipe_label_set(struct ucred *cred, struct pipepair *pp,
240 	    struct label *label);
241 
242 int	mac_posixsem_check_getvalue(struct ucred *active_cred,
243 	    struct ucred *file_cred, struct ksem *ks);
244 int	mac_posixsem_check_open(struct ucred *cred, struct ksem *ks);
245 int	mac_posixsem_check_post(struct ucred *active_cred,
246 	    struct ucred *file_cred, struct ksem *ks);
247 int	mac_posixsem_check_setmode(struct ucred *cred, struct ksem *ks,
248 	    mode_t mode);
249 int	mac_posixsem_check_setowner(struct ucred *cred, struct ksem *ks,
250 	    uid_t uid, gid_t gid);
251 int	mac_posixsem_check_stat(struct ucred *active_cred,
252 	    struct ucred *file_cred, struct ksem *ks);
253 int	mac_posixsem_check_unlink(struct ucred *cred, struct ksem *ks);
254 int	mac_posixsem_check_wait(struct ucred *active_cred,
255 	    struct ucred *file_cred, struct ksem *ks);
256 void 	mac_posixsem_create(struct ucred *cred, struct ksem *ks);
257 void	mac_posixsem_destroy(struct ksem *);
258 void	mac_posixsem_init(struct ksem *);
259 
260 int	mac_posixshm_check_create(struct ucred *cred, const char *path);
261 int	mac_posixshm_check_mmap(struct ucred *cred, struct shmfd *shmfd,
262 	    int prot, int flags);
263 int	mac_posixshm_check_open(struct ucred *cred, struct shmfd *shmfd,
264 	    accmode_t accmode);
265 int	mac_posixshm_check_read(struct ucred *active_cred,
266 	    struct ucred *file_cred, struct shmfd *shmfd);
267 int	mac_posixshm_check_setmode(struct ucred *cred, struct shmfd *shmfd,
268 	    mode_t mode);
269 int	mac_posixshm_check_setowner(struct ucred *cred, struct shmfd *shmfd,
270 	    uid_t uid, gid_t gid);
271 int	mac_posixshm_check_stat(struct ucred *active_cred,
272 	    struct ucred *file_cred, struct shmfd *shmfd);
273 int	mac_posixshm_check_truncate(struct ucred *active_cred,
274 	    struct ucred *file_cred, struct shmfd *shmfd);
275 int	mac_posixshm_check_unlink(struct ucred *cred, struct shmfd *shmfd);
276 int	mac_posixshm_check_write(struct ucred *active_cred,
277 	    struct ucred *file_cred, struct shmfd *shmfd);
278 void 	mac_posixshm_create(struct ucred *cred, struct shmfd *shmfd);
279 void	mac_posixshm_destroy(struct shmfd *);
280 void	mac_posixshm_init(struct shmfd *);
281 
282 int	mac_priv_check_impl(struct ucred *cred, int priv);
283 #ifdef MAC
284 extern bool mac_priv_check_fp_flag;
285 #else
286 #define mac_priv_check_fp_flag 0
287 #endif
288 #define mac_priv_check_enabled()	__predict_false(mac_priv_check_fp_flag)
289 static inline int
290 mac_priv_check(struct ucred *cred, int priv)
291 {
292 
293 	if (mac_priv_check_enabled())
294 		return (mac_priv_check_impl(cred, priv));
295 	return (0);
296 }
297 
298 int	mac_priv_grant_impl(struct ucred *cred, int priv);
299 #ifdef MAC
300 extern bool mac_priv_grant_fp_flag;
301 #else
302 #define mac_priv_grant_fp_flag 0
303 #endif
304 #define mac_priv_grant_enabled()	__predict_false(mac_priv_grant_fp_flag)
305 static inline int
306 mac_priv_grant(struct ucred *cred, int priv)
307 {
308 
309 	if (mac_priv_grant_enabled())
310 		return (mac_priv_grant_impl(cred, priv));
311 	return (EPERM);
312 }
313 
314 int	mac_proc_check_debug(struct ucred *cred, struct proc *p);
315 int	mac_proc_check_sched(struct ucred *cred, struct proc *p);
316 int	mac_proc_check_signal(struct ucred *cred, struct proc *p,
317 	    int signum);
318 int	mac_proc_check_wait(struct ucred *cred, struct proc *p);
319 void	mac_proc_destroy(struct proc *);
320 void	mac_proc_init(struct proc *);
321 void	mac_proc_vm_revoke(struct thread *td);
322 int	mac_execve_enter(struct image_params *imgp, struct mac *mac_p);
323 void	mac_execve_exit(struct image_params *imgp);
324 void	mac_execve_interpreter_enter(struct vnode *interpvp,
325 	    struct label **interplabel);
326 void	mac_execve_interpreter_exit(struct label *interpvplabel);
327 
328 int	mac_socket_check_accept(struct ucred *cred, struct socket *so);
329 int	mac_socket_check_bind(struct ucred *cred, struct socket *so,
330 	    struct sockaddr *sa);
331 int	mac_socket_check_connect(struct ucred *cred, struct socket *so,
332 	    struct sockaddr *sa);
333 int	mac_socket_check_create(struct ucred *cred, int domain, int type,
334 	    int proto);
335 int	mac_socket_check_deliver(struct socket *so, struct mbuf *m);
336 int	mac_socket_check_listen(struct ucred *cred, struct socket *so);
337 int	mac_socket_check_poll(struct ucred *cred, struct socket *so);
338 int	mac_socket_check_receive(struct ucred *cred, struct socket *so);
339 int	mac_socket_check_send(struct ucred *cred, struct socket *so);
340 int	mac_socket_check_stat(struct ucred *cred, struct socket *so);
341 int	mac_socket_check_visible(struct ucred *cred, struct socket *so);
342 void	mac_socket_create_mbuf(struct socket *so, struct mbuf *m);
343 void	mac_socket_create(struct ucred *cred, struct socket *so);
344 void	mac_socket_destroy(struct socket *);
345 int	mac_socket_init(struct socket *, int);
346 void	mac_socket_newconn(struct socket *oldso, struct socket *newso);
347 int	mac_getsockopt_label(struct ucred *cred, struct socket *so,
348 	    struct mac *extmac);
349 int	mac_getsockopt_peerlabel(struct ucred *cred, struct socket *so,
350 	    struct mac *extmac);
351 int	mac_setsockopt_label(struct ucred *cred, struct socket *so,
352 	    struct mac *extmac);
353 
354 void	mac_socketpeer_set_from_mbuf(struct mbuf *m, struct socket *so);
355 void	mac_socketpeer_set_from_socket(struct socket *oldso,
356 	    struct socket *newso);
357 
358 void	mac_syncache_create(struct label *l, struct inpcb *inp);
359 void	mac_syncache_create_mbuf(struct label *l, struct mbuf *m);
360 void	mac_syncache_destroy(struct label **l);
361 int	mac_syncache_init(struct label **l);
362 
363 int	mac_system_check_acct(struct ucred *cred, struct vnode *vp);
364 int	mac_system_check_audit(struct ucred *cred, void *record, int length);
365 int	mac_system_check_auditctl(struct ucred *cred, struct vnode *vp);
366 int	mac_system_check_auditon(struct ucred *cred, int cmd);
367 int	mac_system_check_reboot(struct ucred *cred, int howto);
368 int	mac_system_check_swapon(struct ucred *cred, struct vnode *vp);
369 int	mac_system_check_swapoff(struct ucred *cred, struct vnode *vp);
370 int	mac_system_check_sysctl(struct ucred *cred, struct sysctl_oid *oidp,
371 	    void *arg1, int arg2, struct sysctl_req *req);
372 
373 void	mac_sysvmsg_cleanup(struct msg *msgptr);
374 void	mac_sysvmsg_create(struct ucred *cred, struct msqid_kernel *msqkptr,
375 	    struct msg *msgptr);
376 void	mac_sysvmsg_destroy(struct msg *);
377 void	mac_sysvmsg_init(struct msg *);
378 
379 int	mac_sysvmsq_check_msgmsq(struct ucred *cred, struct msg *msgptr,
380 	    struct msqid_kernel *msqkptr);
381 int	mac_sysvmsq_check_msgrcv(struct ucred *cred, struct msg *msgptr);
382 int	mac_sysvmsq_check_msgrmid(struct ucred *cred, struct msg *msgptr);
383 int	mac_sysvmsq_check_msqctl(struct ucred *cred,
384 	    struct msqid_kernel *msqkptr, int cmd);
385 int	mac_sysvmsq_check_msqget(struct ucred *cred,
386 	    struct msqid_kernel *msqkptr);
387 int	mac_sysvmsq_check_msqrcv(struct ucred *cred,
388 	    struct msqid_kernel *msqkptr);
389 int	mac_sysvmsq_check_msqsnd(struct ucred *cred,
390 	    struct msqid_kernel *msqkptr);
391 void	mac_sysvmsq_cleanup(struct msqid_kernel *msqkptr);
392 void	mac_sysvmsq_create(struct ucred *cred, struct msqid_kernel *msqkptr);
393 void	mac_sysvmsq_destroy(struct msqid_kernel *);
394 void	mac_sysvmsq_init(struct msqid_kernel *);
395 
396 int	mac_sysvsem_check_semctl(struct ucred *cred,
397 	    struct semid_kernel *semakptr, int cmd);
398 int	mac_sysvsem_check_semget(struct ucred *cred,
399 	   struct semid_kernel *semakptr);
400 int	mac_sysvsem_check_semop(struct ucred *cred,
401 	    struct semid_kernel *semakptr, size_t accesstype);
402 void	mac_sysvsem_cleanup(struct semid_kernel *semakptr);
403 void	mac_sysvsem_create(struct ucred *cred,
404 	    struct semid_kernel *semakptr);
405 void	mac_sysvsem_destroy(struct semid_kernel *);
406 void	mac_sysvsem_init(struct semid_kernel *);
407 
408 int	mac_sysvshm_check_shmat(struct ucred *cred,
409 	    struct shmid_kernel *shmsegptr, int shmflg);
410 int	mac_sysvshm_check_shmctl(struct ucred *cred,
411 	    struct shmid_kernel *shmsegptr, int cmd);
412 int	mac_sysvshm_check_shmdt(struct ucred *cred,
413 	    struct shmid_kernel *shmsegptr);
414 int	mac_sysvshm_check_shmget(struct ucred *cred,
415 	    struct shmid_kernel *shmsegptr, int shmflg);
416 void	mac_sysvshm_cleanup(struct shmid_kernel *shmsegptr);
417 void	mac_sysvshm_create(struct ucred *cred,
418 	    struct shmid_kernel *shmsegptr);
419 void	mac_sysvshm_destroy(struct shmid_kernel *);
420 void	mac_sysvshm_init(struct shmid_kernel *);
421 
422 void	mac_thread_userret(struct thread *td);
423 
424 #if defined(MAC) && defined(DEBUG_VFS_LOCKS)
425 void	mac_vnode_assert_locked(struct vnode *vp, const char *func);
426 #else
427 #define mac_vnode_assert_locked(vp, func) do { } while (0)
428 #endif
429 
430 int	mac_vnode_associate_extattr(struct mount *mp, struct vnode *vp);
431 void	mac_vnode_associate_singlelabel(struct mount *mp, struct vnode *vp);
432 int	mac_vnode_check_access_impl(struct ucred *cred, struct vnode *dvp,
433 	    accmode_t accmode);
434 extern bool mac_vnode_check_access_fp_flag;
435 #define mac_vnode_check_access_enabled() __predict_false(mac_vnode_check_access_fp_flag)
436 static inline int
437 mac_vnode_check_access(struct ucred *cred, struct vnode *dvp,
438     accmode_t accmode)
439 {
440 
441 	mac_vnode_assert_locked(dvp, "mac_vnode_check_access");
442 	if (mac_vnode_check_access_enabled())
443                 return (mac_vnode_check_access_impl(cred, dvp, accmode));
444 	return (0);
445 }
446 int	mac_vnode_check_chdir(struct ucred *cred, struct vnode *dvp);
447 int	mac_vnode_check_chroot(struct ucred *cred, struct vnode *dvp);
448 int	mac_vnode_check_create(struct ucred *cred, struct vnode *dvp,
449 	    struct componentname *cnp, struct vattr *vap);
450 int	mac_vnode_check_deleteacl(struct ucred *cred, struct vnode *vp,
451 	    acl_type_t type);
452 int	mac_vnode_check_deleteextattr(struct ucred *cred, struct vnode *vp,
453 	    int attrnamespace, const char *name);
454 int	mac_vnode_check_exec(struct ucred *cred, struct vnode *vp,
455 	    struct image_params *imgp);
456 int	mac_vnode_check_getacl(struct ucred *cred, struct vnode *vp,
457 	    acl_type_t type);
458 int	mac_vnode_check_getextattr(struct ucred *cred, struct vnode *vp,
459 	    int attrnamespace, const char *name);
460 int	mac_vnode_check_link(struct ucred *cred, struct vnode *dvp,
461 	    struct vnode *vp, struct componentname *cnp);
462 int	mac_vnode_check_listextattr(struct ucred *cred, struct vnode *vp,
463 	    int attrnamespace);
464 
465 int	mac_vnode_check_lookup_impl(struct ucred *cred, struct vnode *dvp,
466  	    struct componentname *cnp);
467 #ifdef MAC
468 extern bool mac_vnode_check_lookup_fp_flag;
469 #else
470 #define mac_vnode_check_lookup_fp_flag 0
471 #endif
472 #define mac_vnode_check_lookup_enabled() __predict_false(mac_vnode_check_lookup_fp_flag)
473 static inline int
474 mac_vnode_check_lookup(struct ucred *cred, struct vnode *dvp,
475     struct componentname *cnp)
476 {
477 
478 	mac_vnode_assert_locked(dvp, "mac_vnode_check_lookup");
479 	if (mac_vnode_check_lookup_enabled())
480                 return (mac_vnode_check_lookup_impl(cred, dvp, cnp));
481 	return (0);
482 }
483 
484 int	mac_vnode_check_mmap_impl(struct ucred *cred, struct vnode *vp, int prot,
485 	    int flags);
486 #ifdef MAC
487 extern bool mac_vnode_check_mmap_fp_flag;
488 #else
489 #define mac_vnode_check_mmap_fp_flag 0
490 #endif
491 #define mac_vnode_check_mmap_enabled() __predict_false(mac_vnode_check_mmap_fp_flag)
492 static inline int
493 mac_vnode_check_mmap(struct ucred *cred, struct vnode *vp, int prot,
494     int flags)
495 {
496 
497 	mac_vnode_assert_locked(vp, "mac_vnode_check_mmap");
498 	if (mac_vnode_check_mmap_enabled())
499 		return (mac_vnode_check_mmap_impl(cred, vp, prot, flags));
500 	return (0);
501 }
502 
503 int	mac_vnode_check_open_impl(struct ucred *cred, struct vnode *vp,
504 	    accmode_t accmode);
505 #ifdef MAC
506 extern bool mac_vnode_check_open_fp_flag;
507 #else
508 #define mac_vnode_check_open_fp_flag 0
509 #endif
510 #define mac_vnode_check_open_enabled() __predict_false(mac_vnode_check_open_fp_flag)
511 static inline int
512 mac_vnode_check_open(struct ucred *cred, struct vnode *vp,
513     accmode_t accmode)
514 {
515 
516 	mac_vnode_assert_locked(vp, "mac_vnode_check_open");
517 	if (mac_vnode_check_open_enabled())
518 		return (mac_vnode_check_open_impl(cred, vp, accmode));
519 	return (0);
520 }
521 
522 int	mac_vnode_check_mprotect(struct ucred *cred, struct vnode *vp,
523 	    int prot);
524 
525 #define mac_vnode_check_poll_enabled() __predict_false(mac_vnode_check_poll_fp_flag)
526 #ifdef MAC
527 extern bool mac_vnode_check_poll_fp_flag;
528 int	mac_vnode_check_poll(struct ucred *active_cred,
529 	    struct ucred *file_cred, struct vnode *vp);
530 #else
531 #define mac_vnode_check_poll_fp_flag	0
532 static inline int
533 mac_vnode_check_poll(struct ucred *active_cred, struct ucred *file_cred,
534     struct vnode *vp)
535 {
536 
537 	return (0);
538 }
539 #endif
540 int	mac_vnode_check_readdir(struct ucred *cred, struct vnode *vp);
541 int	mac_vnode_check_readlink_impl(struct ucred *cred, struct vnode *dvp);
542 #ifdef MAC
543 extern bool mac_vnode_check_readlink_fp_flag;
544 #else
545 #define mac_vnode_check_readlink_fp_flag 0
546 #endif
547 #define mac_vnode_check_readlink_enabled() __predict_false(mac_vnode_check_readlink_fp_flag)
548 static inline int
549 mac_vnode_check_readlink(struct ucred *cred, struct vnode *vp)
550 {
551 
552 	mac_vnode_assert_locked(vp, "mac_vnode_check_readlink");
553 	if (mac_vnode_check_readlink_enabled())
554 		return (mac_vnode_check_readlink_impl(cred, vp));
555 	return (0);
556 }
557 #define mac_vnode_check_rename_from_enabled() __predict_false(mac_vnode_check_rename_from_fp_flag)
558 #ifdef MAC
559 extern bool mac_vnode_check_rename_from_fp_flag;
560 #endif
561 int	mac_vnode_check_rename_from(struct ucred *cred, struct vnode *dvp,
562 	    struct vnode *vp, struct componentname *cnp);
563 int	mac_vnode_check_rename_to(struct ucred *cred, struct vnode *dvp,
564 	    struct vnode *vp, int samedir, struct componentname *cnp);
565 int	mac_vnode_check_revoke(struct ucred *cred, struct vnode *vp);
566 int	mac_vnode_check_setacl(struct ucred *cred, struct vnode *vp,
567 	    acl_type_t type, struct acl *acl);
568 int	mac_vnode_check_setextattr(struct ucred *cred, struct vnode *vp,
569 	    int attrnamespace, const char *name);
570 int	mac_vnode_check_setflags(struct ucred *cred, struct vnode *vp,
571 	    u_long flags);
572 int	mac_vnode_check_setmode(struct ucred *cred, struct vnode *vp,
573 	    mode_t mode);
574 int	mac_vnode_check_setowner(struct ucred *cred, struct vnode *vp,
575 	    uid_t uid, gid_t gid);
576 int	mac_vnode_check_setutimes(struct ucred *cred, struct vnode *vp,
577 	    struct timespec atime, struct timespec mtime);
578 
579 int	mac_vnode_check_stat_impl(struct ucred *active_cred,
580 	    struct ucred *file_cred, struct vnode *vp);
581 #ifdef MAC
582 extern bool mac_vnode_check_stat_fp_flag;
583 #else
584 #define mac_vnode_check_stat_fp_flag 0
585 #endif
586 #define mac_vnode_check_stat_enabled()	__predict_false(mac_vnode_check_stat_fp_flag)
587 static inline int
588 mac_vnode_check_stat(struct ucred *active_cred, struct ucred *file_cred,
589     struct vnode *vp)
590 {
591 
592 	mac_vnode_assert_locked(vp, "mac_vnode_check_stat");
593 	if (mac_vnode_check_stat_enabled())
594 		return (mac_vnode_check_stat_impl(active_cred, file_cred, vp));
595 	return (0);
596 }
597 
598 int	mac_vnode_check_read_impl(struct ucred *active_cred,
599 	    struct ucred *file_cred, struct vnode *vp);
600 #ifdef MAC
601 extern bool mac_vnode_check_read_fp_flag;
602 #else
603 #define mac_vnode_check_read_fp_flag 0
604 #endif
605 #define mac_vnode_check_read_enabled() __predict_false(mac_vnode_check_read_fp_flag)
606 static inline int
607 mac_vnode_check_read(struct ucred *active_cred, struct ucred *file_cred,
608     struct vnode *vp)
609 {
610 
611 	mac_vnode_assert_locked(vp, "mac_vnode_check_read");
612 	if (mac_vnode_check_read_enabled())
613 		return (mac_vnode_check_read_impl(active_cred, file_cred, vp));
614 	return (0);
615 }
616 
617 int	mac_vnode_check_write_impl(struct ucred *active_cred,
618 	    struct ucred *file_cred, struct vnode *vp);
619 #ifdef MAC
620 extern bool mac_vnode_check_write_fp_flag;
621 #else
622 #define mac_vnode_check_write_fp_flag 0
623 #endif
624 #define mac_vnode_check_write_enabled() __predict_false(mac_vnode_check_write_fp_flag)
625 static inline int
626 mac_vnode_check_write(struct ucred *active_cred, struct ucred *file_cred,
627     struct vnode *vp)
628 {
629 
630 	mac_vnode_assert_locked(vp, "mac_vnode_check_write");
631 	if (mac_vnode_check_write_enabled())
632 		return (mac_vnode_check_write_impl(active_cred, file_cred, vp));
633 	return (0);
634 }
635 
636 int	mac_vnode_check_unlink(struct ucred *cred, struct vnode *dvp,
637 	    struct vnode *vp, struct componentname *cnp);
638 void	mac_vnode_copy_label(struct label *, struct label *);
639 void	mac_vnode_init(struct vnode *);
640 int	mac_vnode_create_extattr(struct ucred *cred, struct mount *mp,
641 	    struct vnode *dvp, struct vnode *vp, struct componentname *cnp);
642 void	mac_vnode_destroy(struct vnode *);
643 void	mac_vnode_execve_transition(struct ucred *oldcred,
644 	    struct ucred *newcred, struct vnode *vp,
645 	    struct label *interpvplabel, struct image_params *imgp);
646 int	mac_vnode_execve_will_transition(struct ucred *cred,
647 	    struct vnode *vp, struct label *interpvplabel,
648 	    struct image_params *imgp);
649 void	mac_vnode_relabel(struct ucred *cred, struct vnode *vp,
650 	    struct label *newlabel);
651 
652 /*
653  * Calls to help various file systems implement labeling functionality using
654  * their existing EA implementation.
655  */
656 int	vop_stdsetlabel_ea(struct vop_setlabel_args *ap);
657 
658 #endif /* !_SECURITY_MAC_MAC_FRAMEWORK_H_ */
659