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