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