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