mac_pipe.c revision 104269
1100894Srwatson/*-
2100894Srwatson * Copyright (c) 1999, 2000, 2001, 2002 Robert N. M. Watson
3100894Srwatson * Copyright (c) 2001 Ilmar S. Habibulin
4100894Srwatson * Copyright (c) 2001, 2002 Networks Associates Technology, Inc.
5100894Srwatson * All rights reserved.
6100894Srwatson *
7100894Srwatson * This software was developed by Robert Watson and Ilmar Habibulin for the
8100894Srwatson * TrustedBSD Project.
9100894Srwatson *
10100894Srwatson * This software was developed for the FreeBSD Project in part by NAI Labs,
11100894Srwatson * the Security Research Division of Network Associates, Inc. under
12100894Srwatson * DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA
13100894Srwatson * CHATS research program.
14100894Srwatson *
15100894Srwatson * Redistribution and use in source and binary forms, with or without
16100894Srwatson * modification, are permitted provided that the following conditions
17100894Srwatson * are met:
18100894Srwatson * 1. Redistributions of source code must retain the above copyright
19100894Srwatson *    notice, this list of conditions and the following disclaimer.
20100894Srwatson * 2. Redistributions in binary form must reproduce the above copyright
21100894Srwatson *    notice, this list of conditions and the following disclaimer in the
22100894Srwatson *    documentation and/or other materials provided with the distribution.
23100894Srwatson * 3. The names of the authors may not be used to endorse or promote
24100894Srwatson *    products derived from this software without specific prior written
25100894Srwatson *    permission.
26100894Srwatson *
27100894Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
28100894Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29100894Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30100894Srwatson * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
31100894Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32100894Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33100894Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34100894Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35100894Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36100894Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37100894Srwatson * SUCH DAMAGE.
38100894Srwatson *
39100894Srwatson * $FreeBSD: head/sys/security/mac/mac_pipe.c 104269 2002-10-01 04:30:19Z rwatson $
40100894Srwatson */
41100894Srwatson/*
42100894Srwatson * Developed by the TrustedBSD Project.
43100894Srwatson *
44100894Srwatson * Framework for extensible kernel access control.  Kernel and userland
45100894Srwatson * interface to the framework, policy registration and composition.
46100894Srwatson */
47100894Srwatson
48100894Srwatson#include "opt_mac.h"
49101173Srwatson
50100894Srwatson#include <sys/param.h>
51100979Srwatson#include <sys/extattr.h>
52100979Srwatson#include <sys/kernel.h>
53100979Srwatson#include <sys/lock.h>
54102949Sbde#include <sys/malloc.h>
55100979Srwatson#include <sys/mutex.h>
56100979Srwatson#include <sys/mac.h>
57101712Srwatson#include <sys/module.h>
58100979Srwatson#include <sys/proc.h>
59100979Srwatson#include <sys/systm.h>
60100894Srwatson#include <sys/sysproto.h>
61100894Srwatson#include <sys/sysent.h>
62100979Srwatson#include <sys/vnode.h>
63100979Srwatson#include <sys/mount.h>
64100979Srwatson#include <sys/file.h>
65100979Srwatson#include <sys/namei.h>
66100979Srwatson#include <sys/socket.h>
67100979Srwatson#include <sys/pipe.h>
68100979Srwatson#include <sys/socketvar.h>
69100979Srwatson#include <sys/sysctl.h>
70100894Srwatson
71100979Srwatson#include <vm/vm.h>
72100979Srwatson#include <vm/pmap.h>
73100979Srwatson#include <vm/vm_map.h>
74100979Srwatson#include <vm/vm_object.h>
75100979Srwatson
76100979Srwatson#include <sys/mac_policy.h>
77100979Srwatson
78100979Srwatson#include <fs/devfs/devfs.h>
79100979Srwatson
80100979Srwatson#include <net/bpfdesc.h>
81100979Srwatson#include <net/if.h>
82100979Srwatson#include <net/if_var.h>
83100979Srwatson
84100979Srwatson#include <netinet/in.h>
85100979Srwatson#include <netinet/ip_var.h>
86100979Srwatson
87100979Srwatson#ifdef MAC
88100979Srwatson
89101712Srwatson/*
90101712Srwatson * Declare that the kernel provides MAC support, version 1.  This permits
91101712Srwatson * modules to refuse to be loaded if the necessary support isn't present,
92101712Srwatson * even if it's pre-boot.
93101712Srwatson */
94101712SrwatsonMODULE_VERSION(kernel_mac_support, 1);
95101712Srwatson
96100979SrwatsonSYSCTL_DECL(_security);
97100979Srwatson
98100979SrwatsonSYSCTL_NODE(_security, OID_AUTO, mac, CTLFLAG_RW, 0,
99100979Srwatson    "TrustedBSD MAC policy controls");
100100979Srwatson#ifndef MAC_MAX_POLICIES
101100979Srwatson#define	MAC_MAX_POLICIES	8
102100979Srwatson#endif
103100979Srwatson#if MAC_MAX_POLICIES > 32
104100979Srwatson#error "MAC_MAX_POLICIES too large"
105100979Srwatson#endif
106100979Srwatsonstatic unsigned int mac_max_policies = MAC_MAX_POLICIES;
107100979Srwatsonstatic unsigned int mac_policy_offsets_free = (1 << MAC_MAX_POLICIES) - 1;
108100979SrwatsonSYSCTL_UINT(_security_mac, OID_AUTO, max_policies, CTLFLAG_RD,
109100979Srwatson    &mac_max_policies, 0, "");
110100979Srwatson
111100979Srwatsonstatic int	mac_late = 0;
112100979Srwatson
113100979Srwatsonstatic int	mac_enforce_fs = 1;
114100979SrwatsonSYSCTL_INT(_security_mac, OID_AUTO, enforce_fs, CTLFLAG_RW,
115100979Srwatson    &mac_enforce_fs, 0, "Enforce MAC policy on file system objects");
116100979SrwatsonTUNABLE_INT("security.mac.enforce_fs", &mac_enforce_fs);
117100979Srwatson
118100979Srwatsonstatic int	mac_enforce_network = 1;
119100979SrwatsonSYSCTL_INT(_security_mac, OID_AUTO, enforce_network, CTLFLAG_RW,
120100979Srwatson    &mac_enforce_network, 0, "Enforce MAC policy on network packets");
121100979SrwatsonTUNABLE_INT("security.mac.enforce_network", &mac_enforce_network);
122100979Srwatson
123103513Srwatsonstatic int	mac_enforce_pipe = 1;
124103513SrwatsonSYSCTL_INT(_security_mac, OID_AUTO, enforce_pipe, CTLFLAG_RW,
125103513Srwatson    &mac_enforce_pipe, 0, "Enforce MAC policy on pipe operations");
126104236SrwatsonTUNABLE_INT("security.mac.enforce_pipe", &mac_enforce_pipe);
127103513Srwatson
128100979Srwatsonstatic int	mac_enforce_process = 1;
129100979SrwatsonSYSCTL_INT(_security_mac, OID_AUTO, enforce_process, CTLFLAG_RW,
130100979Srwatson    &mac_enforce_process, 0, "Enforce MAC policy on inter-process operations");
131100979SrwatsonTUNABLE_INT("security.mac.enforce_process", &mac_enforce_process);
132100979Srwatson
133100979Srwatsonstatic int	mac_enforce_socket = 1;
134100979SrwatsonSYSCTL_INT(_security_mac, OID_AUTO, enforce_socket, CTLFLAG_RW,
135100979Srwatson    &mac_enforce_socket, 0, "Enforce MAC policy on socket operations");
136100979SrwatsonTUNABLE_INT("security.mac.enforce_socket", &mac_enforce_socket);
137100979Srwatson
138103514Srwatsonstatic int     mac_enforce_vm = 1;
139103514SrwatsonSYSCTL_INT(_security_mac, OID_AUTO, enforce_vm, CTLFLAG_RW,
140103514Srwatson    &mac_enforce_vm, 0, "Enforce MAC policy on vm operations");
141104236SrwatsonTUNABLE_INT("security.mac.enforce_vm", &mac_enforce_vm);
142103514Srwatson
143100979Srwatsonstatic int	mac_label_size = sizeof(struct mac);
144100979SrwatsonSYSCTL_INT(_security_mac, OID_AUTO, label_size, CTLFLAG_RD,
145100979Srwatson    &mac_label_size, 0, "Pre-compiled MAC label size");
146100979Srwatson
147100979Srwatsonstatic int	mac_cache_fslabel_in_vnode = 1;
148100979SrwatsonSYSCTL_INT(_security_mac, OID_AUTO, cache_fslabel_in_vnode, CTLFLAG_RW,
149100979Srwatson    &mac_cache_fslabel_in_vnode, 0, "Cache mount fslabel in vnode");
150100979SrwatsonTUNABLE_INT("security.mac.cache_fslabel_in_vnode",
151100979Srwatson    &mac_cache_fslabel_in_vnode);
152100979Srwatson
153100979Srwatsonstatic int	mac_vnode_label_cache_hits = 0;
154100979SrwatsonSYSCTL_INT(_security_mac, OID_AUTO, vnode_label_cache_hits, CTLFLAG_RD,
155100979Srwatson    &mac_vnode_label_cache_hits, 0, "Cache hits on vnode labels");
156100979Srwatsonstatic int	mac_vnode_label_cache_misses = 0;
157100979SrwatsonSYSCTL_INT(_security_mac, OID_AUTO, vnode_label_cache_misses, CTLFLAG_RD,
158100979Srwatson    &mac_vnode_label_cache_misses, 0, "Cache misses on vnode labels");
159103136Srwatson
160103136Srwatsonstatic int	mac_mmap_revocation = 1;
161103136SrwatsonSYSCTL_INT(_security_mac, OID_AUTO, mmap_revocation, CTLFLAG_RW,
162103136Srwatson    &mac_mmap_revocation, 0, "Revoke mmap access to files on subject "
163103136Srwatson    "relabel");
164101892Srwatsonstatic int	mac_mmap_revocation_via_cow = 0;
165100979SrwatsonSYSCTL_INT(_security_mac, OID_AUTO, mmap_revocation_via_cow, CTLFLAG_RW,
166100979Srwatson    &mac_mmap_revocation_via_cow, 0, "Revoke mmap access to files via "
167100979Srwatson    "copy-on-write semantics, or by removing all write access");
168100979Srwatson
169101988Srwatson#ifdef MAC_DEBUG
170104268SrwatsonSYSCTL_NODE(_security_mac, OID_AUTO, debug, CTLFLAG_RW, 0,
171104268Srwatson    "TrustedBSD MAC debug info");
172104268Srwatson
173104268Srwatsonstatic int	mac_debug_label_fallback = 0;
174104268SrwatsonSYSCTL_INT(_security_mac_debug, OID_AUTO, label_fallback, CTLFLAG_RW,
175104268Srwatson    &mac_debug_label_fallback, 0, "Filesystems should fall back to fs label"
176104268Srwatson    "when label is corrupted.");
177104268SrwatsonTUNABLE_INT("security.mac.debug_label_fallback",
178104268Srwatson    &mac_debug_label_fallback);
179104268Srwatson
180100979Srwatsonstatic unsigned int nmacmbufs, nmaccreds, nmacifnets, nmacbpfdescs,
181100979Srwatson    nmacsockets, nmacmounts, nmactemp, nmacvnodes, nmacdevfsdirents,
182100979Srwatson    nmacipqs, nmacpipes;
183100979SrwatsonSYSCTL_UINT(_security_mac_debug, OID_AUTO, mbufs, CTLFLAG_RD,
184100979Srwatson    &nmacmbufs, 0, "number of mbufs in use");
185100979SrwatsonSYSCTL_UINT(_security_mac_debug, OID_AUTO, creds, CTLFLAG_RD,
186100979Srwatson    &nmaccreds, 0, "number of ucreds in use");
187100979SrwatsonSYSCTL_UINT(_security_mac_debug, OID_AUTO, ifnets, CTLFLAG_RD,
188100979Srwatson    &nmacifnets, 0, "number of ifnets in use");
189100979SrwatsonSYSCTL_UINT(_security_mac_debug, OID_AUTO, ipqs, CTLFLAG_RD,
190100979Srwatson    &nmacipqs, 0, "number of ipqs in use");
191100979SrwatsonSYSCTL_UINT(_security_mac_debug, OID_AUTO, bpfdescs, CTLFLAG_RD,
192100979Srwatson    &nmacbpfdescs, 0, "number of bpfdescs in use");
193100979SrwatsonSYSCTL_UINT(_security_mac_debug, OID_AUTO, sockets, CTLFLAG_RD,
194100979Srwatson    &nmacsockets, 0, "number of sockets in use");
195100979SrwatsonSYSCTL_UINT(_security_mac_debug, OID_AUTO, pipes, CTLFLAG_RD,
196100979Srwatson    &nmacpipes, 0, "number of pipes in use");
197100979SrwatsonSYSCTL_UINT(_security_mac_debug, OID_AUTO, mounts, CTLFLAG_RD,
198100979Srwatson    &nmacmounts, 0, "number of mounts in use");
199100979SrwatsonSYSCTL_UINT(_security_mac_debug, OID_AUTO, temp, CTLFLAG_RD,
200100979Srwatson    &nmactemp, 0, "number of temporary labels in use");
201100979SrwatsonSYSCTL_UINT(_security_mac_debug, OID_AUTO, vnodes, CTLFLAG_RD,
202100979Srwatson    &nmacvnodes, 0, "number of vnodes in use");
203100979SrwatsonSYSCTL_UINT(_security_mac_debug, OID_AUTO, devfsdirents, CTLFLAG_RD,
204100979Srwatson    &nmacdevfsdirents, 0, "number of devfs dirents inuse");
205101988Srwatson#endif
206100979Srwatson
207100979Srwatsonstatic int	error_select(int error1, int error2);
208100979Srwatsonstatic int	mac_externalize(struct label *label, struct mac *mac);
209100979Srwatsonstatic int	mac_policy_register(struct mac_policy_conf *mpc);
210100979Srwatsonstatic int	mac_policy_unregister(struct mac_policy_conf *mpc);
211100979Srwatson
212100979Srwatsonstatic int	mac_stdcreatevnode_ea(struct vnode *vp);
213100979Srwatsonstatic void	mac_cred_mmapped_drop_perms(struct thread *td,
214100979Srwatson		    struct ucred *cred);
215100979Srwatsonstatic void	mac_cred_mmapped_drop_perms_recurse(struct thread *td,
216100979Srwatson		    struct ucred *cred, struct vm_map *map);
217100979Srwatson
218100979SrwatsonMALLOC_DEFINE(M_MACOPVEC, "macopvec", "MAC policy operation vector");
219100979SrwatsonMALLOC_DEFINE(M_MACPIPELABEL, "macpipelabel", "MAC labels for pipes");
220100979Srwatson
221100979Srwatson/*
222100979Srwatson * mac_policy_list_lock protects the consistency of 'mac_policy_list',
223100979Srwatson * the linked list of attached policy modules.  Read-only consumers of
224100979Srwatson * the list must acquire a shared lock for the duration of their use;
225100979Srwatson * writers must acquire an exclusive lock.  Note that for compound
226100979Srwatson * operations, locks should be held for the entire compound operation,
227100979Srwatson * and that this is not yet done for relabel requests.
228100979Srwatson */
229100979Srwatsonstatic struct mtx mac_policy_list_lock;
230100979Srwatsonstatic LIST_HEAD(, mac_policy_conf) mac_policy_list;
231100979Srwatsonstatic int mac_policy_list_busy;
232100979Srwatson#define	MAC_POLICY_LIST_LOCKINIT()	mtx_init(&mac_policy_list_lock,	\
233100979Srwatson	"mac_policy_list_lock", NULL, MTX_DEF);
234100979Srwatson#define	MAC_POLICY_LIST_LOCK()	mtx_lock(&mac_policy_list_lock);
235100979Srwatson#define	MAC_POLICY_LIST_UNLOCK()	mtx_unlock(&mac_policy_list_lock);
236100979Srwatson
237100979Srwatson#define	MAC_POLICY_LIST_BUSY() do {					\
238100979Srwatson	MAC_POLICY_LIST_LOCK();						\
239100979Srwatson	mac_policy_list_busy++;						\
240100979Srwatson	MAC_POLICY_LIST_UNLOCK();					\
241100979Srwatson} while (0)
242100979Srwatson
243100979Srwatson#define	MAC_POLICY_LIST_UNBUSY() do {					\
244100979Srwatson	MAC_POLICY_LIST_LOCK();						\
245100979Srwatson	mac_policy_list_busy--;						\
246100979Srwatson	if (mac_policy_list_busy < 0)					\
247100979Srwatson		panic("Extra mac_policy_list_busy--");			\
248100979Srwatson	MAC_POLICY_LIST_UNLOCK();					\
249100979Srwatson} while (0)
250100979Srwatson
251100979Srwatson/*
252100979Srwatson * MAC_CHECK performs the designated check by walking the policy
253100979Srwatson * module list and checking with each as to how it feels about the
254100979Srwatson * request.  Note that it returns its value via 'error' in the scope
255100979Srwatson * of the caller.
256100979Srwatson */
257100979Srwatson#define	MAC_CHECK(check, args...) do {					\
258100979Srwatson	struct mac_policy_conf *mpc;					\
259100979Srwatson									\
260100979Srwatson	error = 0;							\
261100979Srwatson	MAC_POLICY_LIST_BUSY();						\
262100979Srwatson	LIST_FOREACH(mpc, &mac_policy_list, mpc_list) {			\
263100979Srwatson		if (mpc->mpc_ops->mpo_ ## check != NULL)		\
264100979Srwatson			error = error_select(				\
265100979Srwatson			    mpc->mpc_ops->mpo_ ## check (args),		\
266100979Srwatson			    error);					\
267100979Srwatson	}								\
268100979Srwatson	MAC_POLICY_LIST_UNBUSY();					\
269100979Srwatson} while (0)
270100979Srwatson
271100979Srwatson/*
272100979Srwatson * MAC_BOOLEAN performs the designated boolean composition by walking
273100979Srwatson * the module list, invoking each instance of the operation, and
274100979Srwatson * combining the results using the passed C operator.  Note that it
275100979Srwatson * returns its value via 'result' in the scope of the caller, which
276100979Srwatson * should be initialized by the caller in a meaningful way to get
277100979Srwatson * a meaningful result.
278100979Srwatson */
279100979Srwatson#define	MAC_BOOLEAN(operation, composition, args...) do {		\
280100979Srwatson	struct mac_policy_conf *mpc;					\
281100979Srwatson									\
282100979Srwatson	MAC_POLICY_LIST_BUSY();						\
283100979Srwatson	LIST_FOREACH(mpc, &mac_policy_list, mpc_list) {			\
284100979Srwatson		if (mpc->mpc_ops->mpo_ ## operation != NULL)		\
285100979Srwatson			result = result composition			\
286100979Srwatson			    mpc->mpc_ops->mpo_ ## operation (args);	\
287100979Srwatson	}								\
288100979Srwatson	MAC_POLICY_LIST_UNBUSY();					\
289100979Srwatson} while (0)
290100979Srwatson
291100979Srwatson/*
292100979Srwatson * MAC_PERFORM performs the designated operation by walking the policy
293100979Srwatson * module list and invoking that operation for each policy.
294100979Srwatson */
295100979Srwatson#define	MAC_PERFORM(operation, args...) do {				\
296100979Srwatson	struct mac_policy_conf *mpc;					\
297100979Srwatson									\
298100979Srwatson	MAC_POLICY_LIST_BUSY();						\
299100979Srwatson	LIST_FOREACH(mpc, &mac_policy_list, mpc_list) {			\
300100979Srwatson		if (mpc->mpc_ops->mpo_ ## operation != NULL)		\
301100979Srwatson			mpc->mpc_ops->mpo_ ## operation (args);		\
302100979Srwatson	}								\
303100979Srwatson	MAC_POLICY_LIST_UNBUSY();					\
304100979Srwatson} while (0)
305100979Srwatson
306100979Srwatson/*
307100979Srwatson * Initialize the MAC subsystem, including appropriate SMP locks.
308100979Srwatson */
309100979Srwatsonstatic void
310100979Srwatsonmac_init(void)
311100979Srwatson{
312100979Srwatson
313100979Srwatson	LIST_INIT(&mac_policy_list);
314100979Srwatson	MAC_POLICY_LIST_LOCKINIT();
315100979Srwatson}
316100979Srwatson
317100979Srwatson/*
318100979Srwatson * For the purposes of modules that want to know if they were loaded
319100979Srwatson * "early", set the mac_late flag once we've processed modules either
320100979Srwatson * linked into the kernel, or loaded before the kernel startup.
321100979Srwatson */
322100979Srwatsonstatic void
323100979Srwatsonmac_late_init(void)
324100979Srwatson{
325100979Srwatson
326100979Srwatson	mac_late = 1;
327100979Srwatson}
328100979Srwatson
329100979Srwatson/*
330100979Srwatson * Allow MAC policy modules to register during boot, etc.
331100979Srwatson */
332100894Srwatsonint
333100979Srwatsonmac_policy_modevent(module_t mod, int type, void *data)
334100979Srwatson{
335100979Srwatson	struct mac_policy_conf *mpc;
336100979Srwatson	int error;
337100979Srwatson
338100979Srwatson	error = 0;
339100979Srwatson	mpc = (struct mac_policy_conf *) data;
340100979Srwatson
341100979Srwatson	switch (type) {
342100979Srwatson	case MOD_LOAD:
343100979Srwatson		if (mpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_NOTLATE &&
344100979Srwatson		    mac_late) {
345100979Srwatson			printf("mac_policy_modevent: can't load %s policy "
346100979Srwatson			    "after booting\n", mpc->mpc_name);
347100979Srwatson			error = EBUSY;
348100979Srwatson			break;
349100979Srwatson		}
350100979Srwatson		error = mac_policy_register(mpc);
351100979Srwatson		break;
352100979Srwatson	case MOD_UNLOAD:
353100979Srwatson		/* Don't unregister the module if it was never registered. */
354100979Srwatson		if ((mpc->mpc_runtime_flags & MPC_RUNTIME_FLAG_REGISTERED)
355100979Srwatson		    != 0)
356100979Srwatson			error = mac_policy_unregister(mpc);
357100979Srwatson		else
358100979Srwatson			error = 0;
359100979Srwatson		break;
360100979Srwatson	default:
361100979Srwatson		break;
362100979Srwatson	}
363100979Srwatson
364100979Srwatson	return (error);
365100979Srwatson}
366100979Srwatson
367100979Srwatsonstatic int
368100979Srwatsonmac_policy_register(struct mac_policy_conf *mpc)
369100979Srwatson{
370100979Srwatson	struct mac_policy_conf *tmpc;
371100979Srwatson	struct mac_policy_op_entry *mpe;
372100979Srwatson	int slot;
373100979Srwatson
374103570Srwatson	MALLOC(mpc->mpc_ops, struct mac_policy_ops *, sizeof(*mpc->mpc_ops),
375103570Srwatson	    M_MACOPVEC, M_WAITOK | M_ZERO);
376100979Srwatson	for (mpe = mpc->mpc_entries; mpe->mpe_constant != MAC_OP_LAST; mpe++) {
377100979Srwatson		switch (mpe->mpe_constant) {
378100979Srwatson		case MAC_OP_LAST:
379100979Srwatson			/*
380100979Srwatson			 * Doesn't actually happen, but this allows checking
381100979Srwatson			 * that all enumerated values are handled.
382100979Srwatson			 */
383100979Srwatson			break;
384100979Srwatson		case MAC_DESTROY:
385100979Srwatson			mpc->mpc_ops->mpo_destroy =
386100979Srwatson			    mpe->mpe_function;
387100979Srwatson			break;
388100979Srwatson		case MAC_INIT:
389100979Srwatson			mpc->mpc_ops->mpo_init =
390100979Srwatson			    mpe->mpe_function;
391100979Srwatson			break;
392102123Srwatson		case MAC_SYSCALL:
393102123Srwatson			mpc->mpc_ops->mpo_syscall =
394102123Srwatson			    mpe->mpe_function;
395102123Srwatson			break;
396100979Srwatson		case MAC_INIT_BPFDESC:
397100979Srwatson			mpc->mpc_ops->mpo_init_bpfdesc =
398100979Srwatson			    mpe->mpe_function;
399100979Srwatson			break;
400100979Srwatson		case MAC_INIT_CRED:
401100979Srwatson			mpc->mpc_ops->mpo_init_cred =
402100979Srwatson			    mpe->mpe_function;
403100979Srwatson			break;
404100979Srwatson		case MAC_INIT_DEVFSDIRENT:
405100979Srwatson			mpc->mpc_ops->mpo_init_devfsdirent =
406100979Srwatson			    mpe->mpe_function;
407100979Srwatson			break;
408100979Srwatson		case MAC_INIT_IFNET:
409100979Srwatson			mpc->mpc_ops->mpo_init_ifnet =
410100979Srwatson			    mpe->mpe_function;
411100979Srwatson			break;
412100979Srwatson		case MAC_INIT_IPQ:
413100979Srwatson			mpc->mpc_ops->mpo_init_ipq =
414100979Srwatson			    mpe->mpe_function;
415100979Srwatson			break;
416100979Srwatson		case MAC_INIT_MBUF:
417100979Srwatson			mpc->mpc_ops->mpo_init_mbuf =
418100979Srwatson			    mpe->mpe_function;
419100979Srwatson			break;
420100979Srwatson		case MAC_INIT_MOUNT:
421100979Srwatson			mpc->mpc_ops->mpo_init_mount =
422100979Srwatson			    mpe->mpe_function;
423100979Srwatson			break;
424100979Srwatson		case MAC_INIT_PIPE:
425100979Srwatson			mpc->mpc_ops->mpo_init_pipe =
426100979Srwatson			    mpe->mpe_function;
427100979Srwatson			break;
428100979Srwatson		case MAC_INIT_SOCKET:
429100979Srwatson			mpc->mpc_ops->mpo_init_socket =
430100979Srwatson			    mpe->mpe_function;
431100979Srwatson			break;
432100979Srwatson		case MAC_INIT_TEMP:
433100979Srwatson			mpc->mpc_ops->mpo_init_temp =
434100979Srwatson			    mpe->mpe_function;
435100979Srwatson			break;
436100979Srwatson		case MAC_INIT_VNODE:
437100979Srwatson			mpc->mpc_ops->mpo_init_vnode =
438100979Srwatson			    mpe->mpe_function;
439100979Srwatson			break;
440100979Srwatson		case MAC_DESTROY_BPFDESC:
441100979Srwatson			mpc->mpc_ops->mpo_destroy_bpfdesc =
442100979Srwatson			    mpe->mpe_function;
443100979Srwatson			break;
444100979Srwatson		case MAC_DESTROY_CRED:
445100979Srwatson			mpc->mpc_ops->mpo_destroy_cred =
446100979Srwatson			    mpe->mpe_function;
447100979Srwatson			break;
448100979Srwatson		case MAC_DESTROY_DEVFSDIRENT:
449100979Srwatson			mpc->mpc_ops->mpo_destroy_devfsdirent =
450100979Srwatson			    mpe->mpe_function;
451100979Srwatson			break;
452100979Srwatson		case MAC_DESTROY_IFNET:
453100979Srwatson			mpc->mpc_ops->mpo_destroy_ifnet =
454100979Srwatson			    mpe->mpe_function;
455100979Srwatson			break;
456100979Srwatson		case MAC_DESTROY_IPQ:
457100979Srwatson			mpc->mpc_ops->mpo_destroy_ipq =
458100979Srwatson			    mpe->mpe_function;
459100979Srwatson			break;
460100979Srwatson		case MAC_DESTROY_MBUF:
461100979Srwatson			mpc->mpc_ops->mpo_destroy_mbuf =
462100979Srwatson			    mpe->mpe_function;
463100979Srwatson			break;
464100979Srwatson		case MAC_DESTROY_MOUNT:
465100979Srwatson			mpc->mpc_ops->mpo_destroy_mount =
466100979Srwatson			    mpe->mpe_function;
467100979Srwatson			break;
468100979Srwatson		case MAC_DESTROY_PIPE:
469100979Srwatson			mpc->mpc_ops->mpo_destroy_pipe =
470100979Srwatson			    mpe->mpe_function;
471100979Srwatson			break;
472100979Srwatson		case MAC_DESTROY_SOCKET:
473100979Srwatson			mpc->mpc_ops->mpo_destroy_socket =
474100979Srwatson			    mpe->mpe_function;
475100979Srwatson			break;
476100979Srwatson		case MAC_DESTROY_TEMP:
477100979Srwatson			mpc->mpc_ops->mpo_destroy_temp =
478100979Srwatson			    mpe->mpe_function;
479100979Srwatson			break;
480100979Srwatson		case MAC_DESTROY_VNODE:
481100979Srwatson			mpc->mpc_ops->mpo_destroy_vnode =
482100979Srwatson			    mpe->mpe_function;
483100979Srwatson			break;
484100979Srwatson		case MAC_EXTERNALIZE:
485100979Srwatson			mpc->mpc_ops->mpo_externalize =
486100979Srwatson			    mpe->mpe_function;
487100979Srwatson			break;
488100979Srwatson		case MAC_INTERNALIZE:
489100979Srwatson			mpc->mpc_ops->mpo_internalize =
490100979Srwatson			    mpe->mpe_function;
491100979Srwatson			break;
492100979Srwatson		case MAC_CREATE_DEVFS_DEVICE:
493100979Srwatson			mpc->mpc_ops->mpo_create_devfs_device =
494100979Srwatson			    mpe->mpe_function;
495100979Srwatson			break;
496100979Srwatson		case MAC_CREATE_DEVFS_DIRECTORY:
497100979Srwatson			mpc->mpc_ops->mpo_create_devfs_directory =
498100979Srwatson			    mpe->mpe_function;
499100979Srwatson			break;
500100979Srwatson		case MAC_CREATE_DEVFS_VNODE:
501100979Srwatson			mpc->mpc_ops->mpo_create_devfs_vnode =
502100979Srwatson			    mpe->mpe_function;
503100979Srwatson			break;
504100979Srwatson		case MAC_STDCREATEVNODE_EA:
505100979Srwatson			mpc->mpc_ops->mpo_stdcreatevnode_ea =
506100979Srwatson			    mpe->mpe_function;
507100979Srwatson			break;
508100979Srwatson		case MAC_CREATE_VNODE:
509100979Srwatson			mpc->mpc_ops->mpo_create_vnode =
510100979Srwatson			    mpe->mpe_function;
511100979Srwatson			break;
512100979Srwatson		case MAC_CREATE_MOUNT:
513100979Srwatson			mpc->mpc_ops->mpo_create_mount =
514100979Srwatson			    mpe->mpe_function;
515100979Srwatson			break;
516100979Srwatson		case MAC_CREATE_ROOT_MOUNT:
517100979Srwatson			mpc->mpc_ops->mpo_create_root_mount =
518100979Srwatson			    mpe->mpe_function;
519100979Srwatson			break;
520100979Srwatson		case MAC_RELABEL_VNODE:
521100979Srwatson			mpc->mpc_ops->mpo_relabel_vnode =
522100979Srwatson			    mpe->mpe_function;
523100979Srwatson			break;
524100979Srwatson		case MAC_UPDATE_DEVFSDIRENT:
525100979Srwatson			mpc->mpc_ops->mpo_update_devfsdirent =
526100979Srwatson			    mpe->mpe_function;
527100979Srwatson			break;
528100979Srwatson		case MAC_UPDATE_PROCFSVNODE:
529100979Srwatson			mpc->mpc_ops->mpo_update_procfsvnode =
530100979Srwatson			    mpe->mpe_function;
531100979Srwatson			break;
532100979Srwatson		case MAC_UPDATE_VNODE_FROM_EXTATTR:
533100979Srwatson			mpc->mpc_ops->mpo_update_vnode_from_extattr =
534100979Srwatson			    mpe->mpe_function;
535100979Srwatson			break;
536100979Srwatson		case MAC_UPDATE_VNODE_FROM_EXTERNALIZED:
537100979Srwatson			mpc->mpc_ops->mpo_update_vnode_from_externalized =
538100979Srwatson			    mpe->mpe_function;
539100979Srwatson			break;
540100979Srwatson		case MAC_UPDATE_VNODE_FROM_MOUNT:
541100979Srwatson			mpc->mpc_ops->mpo_update_vnode_from_mount =
542100979Srwatson			    mpe->mpe_function;
543100979Srwatson			break;
544100979Srwatson		case MAC_CREATE_MBUF_FROM_SOCKET:
545100979Srwatson			mpc->mpc_ops->mpo_create_mbuf_from_socket =
546100979Srwatson			    mpe->mpe_function;
547100979Srwatson			break;
548100979Srwatson		case MAC_CREATE_PIPE:
549100979Srwatson			mpc->mpc_ops->mpo_create_pipe =
550100979Srwatson			    mpe->mpe_function;
551100979Srwatson			break;
552100979Srwatson		case MAC_CREATE_SOCKET:
553100979Srwatson			mpc->mpc_ops->mpo_create_socket =
554100979Srwatson			    mpe->mpe_function;
555100979Srwatson			break;
556100979Srwatson		case MAC_CREATE_SOCKET_FROM_SOCKET:
557100979Srwatson			mpc->mpc_ops->mpo_create_socket_from_socket =
558100979Srwatson			    mpe->mpe_function;
559100979Srwatson			break;
560100979Srwatson		case MAC_RELABEL_PIPE:
561100979Srwatson			mpc->mpc_ops->mpo_relabel_pipe =
562100979Srwatson			    mpe->mpe_function;
563100979Srwatson			break;
564100979Srwatson		case MAC_RELABEL_SOCKET:
565100979Srwatson			mpc->mpc_ops->mpo_relabel_socket =
566100979Srwatson			    mpe->mpe_function;
567100979Srwatson			break;
568100979Srwatson		case MAC_SET_SOCKET_PEER_FROM_MBUF:
569100979Srwatson			mpc->mpc_ops->mpo_set_socket_peer_from_mbuf =
570100979Srwatson			    mpe->mpe_function;
571100979Srwatson			break;
572100979Srwatson		case MAC_SET_SOCKET_PEER_FROM_SOCKET:
573100979Srwatson			mpc->mpc_ops->mpo_set_socket_peer_from_socket =
574100979Srwatson			    mpe->mpe_function;
575100979Srwatson			break;
576100979Srwatson		case MAC_CREATE_BPFDESC:
577100979Srwatson			mpc->mpc_ops->mpo_create_bpfdesc =
578100979Srwatson			    mpe->mpe_function;
579100979Srwatson			break;
580100979Srwatson		case MAC_CREATE_DATAGRAM_FROM_IPQ:
581100979Srwatson			mpc->mpc_ops->mpo_create_datagram_from_ipq =
582100979Srwatson			    mpe->mpe_function;
583100979Srwatson			break;
584100979Srwatson		case MAC_CREATE_FRAGMENT:
585100979Srwatson			mpc->mpc_ops->mpo_create_fragment =
586100979Srwatson			    mpe->mpe_function;
587100979Srwatson			break;
588100979Srwatson		case MAC_CREATE_IFNET:
589100979Srwatson			mpc->mpc_ops->mpo_create_ifnet =
590100979Srwatson			    mpe->mpe_function;
591100979Srwatson			break;
592100979Srwatson		case MAC_CREATE_IPQ:
593100979Srwatson			mpc->mpc_ops->mpo_create_ipq =
594100979Srwatson			    mpe->mpe_function;
595100979Srwatson			break;
596100979Srwatson		case MAC_CREATE_MBUF_FROM_MBUF:
597100979Srwatson			mpc->mpc_ops->mpo_create_mbuf_from_mbuf =
598100979Srwatson			    mpe->mpe_function;
599100979Srwatson			break;
600100979Srwatson		case MAC_CREATE_MBUF_LINKLAYER:
601100979Srwatson			mpc->mpc_ops->mpo_create_mbuf_linklayer =
602100979Srwatson			    mpe->mpe_function;
603100979Srwatson			break;
604100979Srwatson		case MAC_CREATE_MBUF_FROM_BPFDESC:
605100979Srwatson			mpc->mpc_ops->mpo_create_mbuf_from_bpfdesc =
606100979Srwatson			    mpe->mpe_function;
607100979Srwatson			break;
608100979Srwatson		case MAC_CREATE_MBUF_FROM_IFNET:
609100979Srwatson			mpc->mpc_ops->mpo_create_mbuf_from_ifnet =
610100979Srwatson			    mpe->mpe_function;
611100979Srwatson			break;
612100979Srwatson		case MAC_CREATE_MBUF_MULTICAST_ENCAP:
613100979Srwatson			mpc->mpc_ops->mpo_create_mbuf_multicast_encap =
614100979Srwatson			    mpe->mpe_function;
615100979Srwatson			break;
616100979Srwatson		case MAC_CREATE_MBUF_NETLAYER:
617100979Srwatson			mpc->mpc_ops->mpo_create_mbuf_netlayer =
618100979Srwatson			    mpe->mpe_function;
619100979Srwatson			break;
620100979Srwatson		case MAC_FRAGMENT_MATCH:
621100979Srwatson			mpc->mpc_ops->mpo_fragment_match =
622100979Srwatson			    mpe->mpe_function;
623100979Srwatson			break;
624100979Srwatson		case MAC_RELABEL_IFNET:
625100979Srwatson			mpc->mpc_ops->mpo_relabel_ifnet =
626100979Srwatson			    mpe->mpe_function;
627100979Srwatson			break;
628100979Srwatson		case MAC_UPDATE_IPQ:
629100979Srwatson			mpc->mpc_ops->mpo_update_ipq =
630100979Srwatson			    mpe->mpe_function;
631100979Srwatson			break;
632100979Srwatson		case MAC_CREATE_CRED:
633100979Srwatson			mpc->mpc_ops->mpo_create_cred =
634100979Srwatson			    mpe->mpe_function;
635100979Srwatson			break;
636100979Srwatson		case MAC_EXECVE_TRANSITION:
637100979Srwatson			mpc->mpc_ops->mpo_execve_transition =
638100979Srwatson			    mpe->mpe_function;
639100979Srwatson			break;
640100979Srwatson		case MAC_EXECVE_WILL_TRANSITION:
641100979Srwatson			mpc->mpc_ops->mpo_execve_will_transition =
642100979Srwatson			    mpe->mpe_function;
643100979Srwatson			break;
644100979Srwatson		case MAC_CREATE_PROC0:
645100979Srwatson			mpc->mpc_ops->mpo_create_proc0 = mpe->mpe_function;
646100979Srwatson			break;
647100979Srwatson		case MAC_CREATE_PROC1:
648100979Srwatson			mpc->mpc_ops->mpo_create_proc1 = mpe->mpe_function;
649100979Srwatson			break;
650100979Srwatson		case MAC_RELABEL_CRED:
651100979Srwatson			mpc->mpc_ops->mpo_relabel_cred =
652100979Srwatson			    mpe->mpe_function;
653100979Srwatson			break;
654100979Srwatson		case MAC_CHECK_BPFDESC_RECEIVE:
655100979Srwatson			mpc->mpc_ops->mpo_check_bpfdesc_receive =
656100979Srwatson			    mpe->mpe_function;
657100979Srwatson			break;
658100979Srwatson		case MAC_CHECK_CRED_RELABEL:
659100979Srwatson			mpc->mpc_ops->mpo_check_cred_relabel =
660100979Srwatson			    mpe->mpe_function;
661100979Srwatson			break;
662100979Srwatson		case MAC_CHECK_CRED_VISIBLE:
663100979Srwatson			mpc->mpc_ops->mpo_check_cred_visible =
664100979Srwatson			    mpe->mpe_function;
665100979Srwatson			break;
666100979Srwatson		case MAC_CHECK_IFNET_RELABEL:
667100979Srwatson			mpc->mpc_ops->mpo_check_ifnet_relabel =
668100979Srwatson			    mpe->mpe_function;
669100979Srwatson			break;
670100979Srwatson		case MAC_CHECK_IFNET_TRANSMIT:
671100979Srwatson			mpc->mpc_ops->mpo_check_ifnet_transmit =
672100979Srwatson			    mpe->mpe_function;
673100979Srwatson			break;
674100979Srwatson		case MAC_CHECK_MOUNT_STAT:
675100979Srwatson			mpc->mpc_ops->mpo_check_mount_stat =
676100979Srwatson			    mpe->mpe_function;
677100979Srwatson			break;
678100979Srwatson		case MAC_CHECK_PIPE_IOCTL:
679100979Srwatson			mpc->mpc_ops->mpo_check_pipe_ioctl =
680100979Srwatson			    mpe->mpe_function;
681100979Srwatson			break;
682102115Srwatson		case MAC_CHECK_PIPE_POLL:
683102115Srwatson			mpc->mpc_ops->mpo_check_pipe_poll =
684100979Srwatson			    mpe->mpe_function;
685100979Srwatson			break;
686102115Srwatson		case MAC_CHECK_PIPE_READ:
687102115Srwatson			mpc->mpc_ops->mpo_check_pipe_read =
688102115Srwatson			    mpe->mpe_function;
689102115Srwatson			break;
690100979Srwatson		case MAC_CHECK_PIPE_RELABEL:
691100979Srwatson			mpc->mpc_ops->mpo_check_pipe_relabel =
692100979Srwatson			    mpe->mpe_function;
693100979Srwatson			break;
694102115Srwatson		case MAC_CHECK_PIPE_STAT:
695102115Srwatson			mpc->mpc_ops->mpo_check_pipe_stat =
696102115Srwatson			    mpe->mpe_function;
697102115Srwatson			break;
698102115Srwatson		case MAC_CHECK_PIPE_WRITE:
699102115Srwatson			mpc->mpc_ops->mpo_check_pipe_write =
700102115Srwatson			    mpe->mpe_function;
701102115Srwatson			break;
702100979Srwatson		case MAC_CHECK_PROC_DEBUG:
703100979Srwatson			mpc->mpc_ops->mpo_check_proc_debug =
704100979Srwatson			    mpe->mpe_function;
705100979Srwatson			break;
706100979Srwatson		case MAC_CHECK_PROC_SCHED:
707100979Srwatson			mpc->mpc_ops->mpo_check_proc_sched =
708100979Srwatson			    mpe->mpe_function;
709100979Srwatson			break;
710100979Srwatson		case MAC_CHECK_PROC_SIGNAL:
711100979Srwatson			mpc->mpc_ops->mpo_check_proc_signal =
712100979Srwatson			    mpe->mpe_function;
713100979Srwatson			break;
714100979Srwatson		case MAC_CHECK_SOCKET_BIND:
715100979Srwatson			mpc->mpc_ops->mpo_check_socket_bind =
716100979Srwatson			    mpe->mpe_function;
717100979Srwatson			break;
718100979Srwatson		case MAC_CHECK_SOCKET_CONNECT:
719100979Srwatson			mpc->mpc_ops->mpo_check_socket_connect =
720100979Srwatson			    mpe->mpe_function;
721100979Srwatson			break;
722101933Srwatson		case MAC_CHECK_SOCKET_DELIVER:
723101933Srwatson			mpc->mpc_ops->mpo_check_socket_deliver =
724101933Srwatson			    mpe->mpe_function;
725101933Srwatson			break;
726100979Srwatson		case MAC_CHECK_SOCKET_LISTEN:
727100979Srwatson			mpc->mpc_ops->mpo_check_socket_listen =
728100979Srwatson			    mpe->mpe_function;
729100979Srwatson			break;
730100979Srwatson		case MAC_CHECK_SOCKET_RELABEL:
731100979Srwatson			mpc->mpc_ops->mpo_check_socket_relabel =
732100979Srwatson			    mpe->mpe_function;
733100979Srwatson			break;
734100979Srwatson		case MAC_CHECK_SOCKET_VISIBLE:
735100979Srwatson			mpc->mpc_ops->mpo_check_socket_visible =
736100979Srwatson			    mpe->mpe_function;
737100979Srwatson			break;
738100979Srwatson		case MAC_CHECK_VNODE_ACCESS:
739100979Srwatson			mpc->mpc_ops->mpo_check_vnode_access =
740100979Srwatson			    mpe->mpe_function;
741100979Srwatson			break;
742100979Srwatson		case MAC_CHECK_VNODE_CHDIR:
743100979Srwatson			mpc->mpc_ops->mpo_check_vnode_chdir =
744100979Srwatson			    mpe->mpe_function;
745100979Srwatson			break;
746100979Srwatson		case MAC_CHECK_VNODE_CHROOT:
747100979Srwatson			mpc->mpc_ops->mpo_check_vnode_chroot =
748100979Srwatson			    mpe->mpe_function;
749100979Srwatson			break;
750100979Srwatson		case MAC_CHECK_VNODE_CREATE:
751100979Srwatson			mpc->mpc_ops->mpo_check_vnode_create =
752100979Srwatson			    mpe->mpe_function;
753100979Srwatson			break;
754100979Srwatson		case MAC_CHECK_VNODE_DELETE:
755100979Srwatson			mpc->mpc_ops->mpo_check_vnode_delete =
756100979Srwatson			    mpe->mpe_function;
757100979Srwatson			break;
758100979Srwatson		case MAC_CHECK_VNODE_DELETEACL:
759100979Srwatson			mpc->mpc_ops->mpo_check_vnode_deleteacl =
760100979Srwatson			    mpe->mpe_function;
761100979Srwatson			break;
762100979Srwatson		case MAC_CHECK_VNODE_EXEC:
763100979Srwatson			mpc->mpc_ops->mpo_check_vnode_exec =
764100979Srwatson			    mpe->mpe_function;
765100979Srwatson			break;
766100979Srwatson		case MAC_CHECK_VNODE_GETACL:
767100979Srwatson			mpc->mpc_ops->mpo_check_vnode_getacl =
768100979Srwatson			    mpe->mpe_function;
769100979Srwatson			break;
770100979Srwatson		case MAC_CHECK_VNODE_GETEXTATTR:
771100979Srwatson			mpc->mpc_ops->mpo_check_vnode_getextattr =
772100979Srwatson			    mpe->mpe_function;
773100979Srwatson			break;
774100979Srwatson		case MAC_CHECK_VNODE_LOOKUP:
775100979Srwatson			mpc->mpc_ops->mpo_check_vnode_lookup =
776100979Srwatson			    mpe->mpe_function;
777100979Srwatson			break;
778100979Srwatson		case MAC_CHECK_VNODE_MMAP_PERMS:
779100979Srwatson			mpc->mpc_ops->mpo_check_vnode_mmap_perms =
780100979Srwatson			    mpe->mpe_function;
781100979Srwatson			break;
782100979Srwatson		case MAC_CHECK_VNODE_OPEN:
783100979Srwatson			mpc->mpc_ops->mpo_check_vnode_open =
784100979Srwatson			    mpe->mpe_function;
785100979Srwatson			break;
786102112Srwatson		case MAC_CHECK_VNODE_POLL:
787102112Srwatson			mpc->mpc_ops->mpo_check_vnode_poll =
788102112Srwatson			    mpe->mpe_function;
789102112Srwatson			break;
790102112Srwatson		case MAC_CHECK_VNODE_READ:
791102112Srwatson			mpc->mpc_ops->mpo_check_vnode_read =
792102112Srwatson			    mpe->mpe_function;
793102112Srwatson			break;
794100979Srwatson		case MAC_CHECK_VNODE_READDIR:
795100979Srwatson			mpc->mpc_ops->mpo_check_vnode_readdir =
796100979Srwatson			    mpe->mpe_function;
797100979Srwatson			break;
798100979Srwatson		case MAC_CHECK_VNODE_READLINK:
799100979Srwatson			mpc->mpc_ops->mpo_check_vnode_readlink =
800100979Srwatson			    mpe->mpe_function;
801100979Srwatson			break;
802100979Srwatson		case MAC_CHECK_VNODE_RELABEL:
803100979Srwatson			mpc->mpc_ops->mpo_check_vnode_relabel =
804100979Srwatson			    mpe->mpe_function;
805100979Srwatson			break;
806100979Srwatson		case MAC_CHECK_VNODE_RENAME_FROM:
807100979Srwatson			mpc->mpc_ops->mpo_check_vnode_rename_from =
808100979Srwatson			    mpe->mpe_function;
809100979Srwatson			break;
810100979Srwatson		case MAC_CHECK_VNODE_RENAME_TO:
811100979Srwatson			mpc->mpc_ops->mpo_check_vnode_rename_to =
812100979Srwatson			    mpe->mpe_function;
813100979Srwatson			break;
814100979Srwatson		case MAC_CHECK_VNODE_REVOKE:
815100979Srwatson			mpc->mpc_ops->mpo_check_vnode_revoke =
816100979Srwatson			    mpe->mpe_function;
817100979Srwatson			break;
818100979Srwatson		case MAC_CHECK_VNODE_SETACL:
819100979Srwatson			mpc->mpc_ops->mpo_check_vnode_setacl =
820100979Srwatson			    mpe->mpe_function;
821100979Srwatson			break;
822100979Srwatson		case MAC_CHECK_VNODE_SETEXTATTR:
823100979Srwatson			mpc->mpc_ops->mpo_check_vnode_setextattr =
824100979Srwatson			    mpe->mpe_function;
825100979Srwatson			break;
826100979Srwatson		case MAC_CHECK_VNODE_SETFLAGS:
827100979Srwatson			mpc->mpc_ops->mpo_check_vnode_setflags =
828100979Srwatson			    mpe->mpe_function;
829100979Srwatson			break;
830100979Srwatson		case MAC_CHECK_VNODE_SETMODE:
831100979Srwatson			mpc->mpc_ops->mpo_check_vnode_setmode =
832100979Srwatson			    mpe->mpe_function;
833100979Srwatson			break;
834100979Srwatson		case MAC_CHECK_VNODE_SETOWNER:
835100979Srwatson			mpc->mpc_ops->mpo_check_vnode_setowner =
836100979Srwatson			    mpe->mpe_function;
837100979Srwatson			break;
838100979Srwatson		case MAC_CHECK_VNODE_SETUTIMES:
839100979Srwatson			mpc->mpc_ops->mpo_check_vnode_setutimes =
840100979Srwatson			    mpe->mpe_function;
841100979Srwatson			break;
842100979Srwatson		case MAC_CHECK_VNODE_STAT:
843100979Srwatson			mpc->mpc_ops->mpo_check_vnode_stat =
844100979Srwatson			    mpe->mpe_function;
845100979Srwatson			break;
846102112Srwatson		case MAC_CHECK_VNODE_WRITE:
847102112Srwatson			mpc->mpc_ops->mpo_check_vnode_write =
848102112Srwatson			    mpe->mpe_function;
849102112Srwatson			break;
850100979Srwatson/*
851100979Srwatson		default:
852100979Srwatson			printf("MAC policy `%s': unknown operation %d\n",
853100979Srwatson			    mpc->mpc_name, mpe->mpe_constant);
854100979Srwatson			return (EINVAL);
855100979Srwatson*/
856100979Srwatson		}
857100979Srwatson	}
858100979Srwatson	MAC_POLICY_LIST_LOCK();
859100979Srwatson	if (mac_policy_list_busy > 0) {
860100979Srwatson		MAC_POLICY_LIST_UNLOCK();
861100979Srwatson		FREE(mpc->mpc_ops, M_MACOPVEC);
862100979Srwatson		mpc->mpc_ops = NULL;
863100979Srwatson		return (EBUSY);
864100979Srwatson	}
865100979Srwatson	LIST_FOREACH(tmpc, &mac_policy_list, mpc_list) {
866100979Srwatson		if (strcmp(tmpc->mpc_name, mpc->mpc_name) == 0) {
867100979Srwatson			MAC_POLICY_LIST_UNLOCK();
868100979Srwatson			FREE(mpc->mpc_ops, M_MACOPVEC);
869100979Srwatson			mpc->mpc_ops = NULL;
870100979Srwatson			return (EEXIST);
871100979Srwatson		}
872100979Srwatson	}
873100979Srwatson	if (mpc->mpc_field_off != NULL) {
874100979Srwatson		slot = ffs(mac_policy_offsets_free);
875100979Srwatson		if (slot == 0) {
876100979Srwatson			MAC_POLICY_LIST_UNLOCK();
877100979Srwatson			FREE(mpc->mpc_ops, M_MACOPVEC);
878100979Srwatson			mpc->mpc_ops = NULL;
879100979Srwatson			return (ENOMEM);
880100979Srwatson		}
881100979Srwatson		slot--;
882100979Srwatson		mac_policy_offsets_free &= ~(1 << slot);
883100979Srwatson		*mpc->mpc_field_off = slot;
884100979Srwatson	}
885100979Srwatson	mpc->mpc_runtime_flags |= MPC_RUNTIME_FLAG_REGISTERED;
886100979Srwatson	LIST_INSERT_HEAD(&mac_policy_list, mpc, mpc_list);
887100979Srwatson
888100979Srwatson	/* Per-policy initialization. */
889100979Srwatson	if (mpc->mpc_ops->mpo_init != NULL)
890100979Srwatson		(*(mpc->mpc_ops->mpo_init))(mpc);
891100979Srwatson	MAC_POLICY_LIST_UNLOCK();
892100979Srwatson
893100979Srwatson	printf("Security policy loaded: %s (%s)\n", mpc->mpc_fullname,
894100979Srwatson	    mpc->mpc_name);
895100979Srwatson
896100979Srwatson	return (0);
897100979Srwatson}
898100979Srwatson
899100979Srwatsonstatic int
900100979Srwatsonmac_policy_unregister(struct mac_policy_conf *mpc)
901100979Srwatson{
902100979Srwatson
903100979Srwatson#if 0
904100979Srwatson	/*
905100979Srwatson	 * Don't allow unloading modules with private data.
906100979Srwatson	 */
907100979Srwatson	if (mpc->mpc_field_off != NULL)
908100979Srwatson		return (EBUSY);
909100979Srwatson#endif
910100979Srwatson	if ((mpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_UNLOADOK) == 0)
911100979Srwatson		return (EBUSY);
912100979Srwatson	MAC_POLICY_LIST_LOCK();
913100979Srwatson	if (mac_policy_list_busy > 0) {
914100979Srwatson		MAC_POLICY_LIST_UNLOCK();
915100979Srwatson		return (EBUSY);
916100979Srwatson	}
917100979Srwatson	if (mpc->mpc_ops->mpo_destroy != NULL)
918100979Srwatson		(*(mpc->mpc_ops->mpo_destroy))(mpc);
919100979Srwatson
920100979Srwatson	LIST_REMOVE(mpc, mpc_list);
921100979Srwatson	MAC_POLICY_LIST_UNLOCK();
922100979Srwatson
923100979Srwatson	FREE(mpc->mpc_ops, M_MACOPVEC);
924100979Srwatson	mpc->mpc_ops = NULL;
925100979Srwatson
926100979Srwatson	printf("Security policy unload: %s (%s)\n", mpc->mpc_fullname,
927100979Srwatson	    mpc->mpc_name);
928100979Srwatson
929100979Srwatson	return (0);
930100979Srwatson}
931100979Srwatson
932100979Srwatson/*
933100979Srwatson * Define an error value precedence, and given two arguments, selects the
934100979Srwatson * value with the higher precedence.
935100979Srwatson */
936100979Srwatsonstatic int
937100979Srwatsonerror_select(int error1, int error2)
938100979Srwatson{
939100979Srwatson
940100979Srwatson	/* Certain decision-making errors take top priority. */
941100979Srwatson	if (error1 == EDEADLK || error2 == EDEADLK)
942100979Srwatson		return (EDEADLK);
943100979Srwatson
944100979Srwatson	/* Invalid arguments should be reported where possible. */
945100979Srwatson	if (error1 == EINVAL || error2 == EINVAL)
946100979Srwatson		return (EINVAL);
947100979Srwatson
948100979Srwatson	/* Precedence goes to "visibility", with both process and file. */
949100979Srwatson	if (error1 == ESRCH || error2 == ESRCH)
950100979Srwatson		return (ESRCH);
951100979Srwatson
952100979Srwatson	if (error1 == ENOENT || error2 == ENOENT)
953100979Srwatson		return (ENOENT);
954100979Srwatson
955100979Srwatson	/* Precedence goes to DAC/MAC protections. */
956100979Srwatson	if (error1 == EACCES || error2 == EACCES)
957100979Srwatson		return (EACCES);
958100979Srwatson
959100979Srwatson	/* Precedence goes to privilege. */
960100979Srwatson	if (error1 == EPERM || error2 == EPERM)
961100979Srwatson		return (EPERM);
962100979Srwatson
963100979Srwatson	/* Precedence goes to error over success; otherwise, arbitrary. */
964100979Srwatson	if (error1 != 0)
965100979Srwatson		return (error1);
966100979Srwatson	return (error2);
967100979Srwatson}
968100979Srwatson
969100979Srwatsonvoid
970100979Srwatsonmac_update_devfsdirent(struct devfs_dirent *de, struct vnode *vp)
971100979Srwatson{
972100979Srwatson
973100979Srwatson	MAC_PERFORM(update_devfsdirent, de, &de->de_label, vp, &vp->v_label);
974100979Srwatson}
975100979Srwatson
976100979Srwatsonvoid
977100979Srwatsonmac_update_procfsvnode(struct vnode *vp, struct ucred *cred)
978100979Srwatson{
979100979Srwatson
980100979Srwatson	MAC_PERFORM(update_procfsvnode, vp, &vp->v_label, cred);
981100979Srwatson}
982100979Srwatson
983100979Srwatson/*
984100979Srwatson * Support callout for policies that manage their own externalization
985100979Srwatson * using extended attributes.
986100979Srwatson */
987100979Srwatsonstatic int
988100979Srwatsonmac_update_vnode_from_extattr(struct vnode *vp, struct mount *mp)
989100979Srwatson{
990100979Srwatson	int error;
991100979Srwatson
992100979Srwatson	MAC_CHECK(update_vnode_from_extattr, vp, &vp->v_label, mp,
993100979Srwatson	    &mp->mnt_fslabel);
994100979Srwatson
995100979Srwatson	return (error);
996100979Srwatson}
997100979Srwatson
998100979Srwatson/*
999100979Srwatson * Given an externalized mac label, internalize it and stamp it on a
1000100979Srwatson * vnode.
1001100979Srwatson */
1002100979Srwatsonstatic int
1003100979Srwatsonmac_update_vnode_from_externalized(struct vnode *vp, struct mac *extmac)
1004100979Srwatson{
1005100979Srwatson	int error;
1006100979Srwatson
1007100979Srwatson	MAC_CHECK(update_vnode_from_externalized, vp, &vp->v_label, extmac);
1008100979Srwatson
1009100979Srwatson	return (error);
1010100979Srwatson}
1011100979Srwatson
1012100979Srwatson/*
1013100979Srwatson * Call out to individual policies to update the label in a vnode from
1014100979Srwatson * the mountpoint.
1015100979Srwatson */
1016100979Srwatsonvoid
1017100979Srwatsonmac_update_vnode_from_mount(struct vnode *vp, struct mount *mp)
1018100979Srwatson{
1019100979Srwatson
1020100979Srwatson	MAC_PERFORM(update_vnode_from_mount, vp, &vp->v_label, mp,
1021100979Srwatson	    &mp->mnt_fslabel);
1022100979Srwatson
1023101308Sjeff	ASSERT_VOP_LOCKED(vp, "mac_update_vnode_from_mount");
1024100979Srwatson	if (mac_cache_fslabel_in_vnode)
1025101308Sjeff		vp->v_vflag |= VV_CACHEDLABEL;
1026100979Srwatson}
1027100979Srwatson
1028100979Srwatson/*
1029100979Srwatson * Implementation of VOP_REFRESHLABEL() that relies on extended attributes
1030100979Srwatson * to store label data.  Can be referenced by filesystems supporting
1031100979Srwatson * extended attributes.
1032100979Srwatson */
1033100979Srwatsonint
1034100979Srwatsonvop_stdrefreshlabel_ea(struct vop_refreshlabel_args *ap)
1035100979Srwatson{
1036100979Srwatson	struct vnode *vp = ap->a_vp;
1037100979Srwatson	struct mac extmac;
1038100979Srwatson	int buflen, error;
1039100979Srwatson
1040100979Srwatson	ASSERT_VOP_LOCKED(vp, "vop_stdrefreshlabel_ea");
1041100979Srwatson
1042100979Srwatson	/*
1043100979Srwatson	 * Call out to external policies first.  Order doesn't really
1044100979Srwatson	 * matter, as long as failure of one assures failure of all.
1045100979Srwatson	 */
1046100979Srwatson	error = mac_update_vnode_from_extattr(vp, vp->v_mount);
1047100979Srwatson	if (error)
1048100979Srwatson		return (error);
1049100979Srwatson
1050100979Srwatson	buflen = sizeof(extmac);
1051100979Srwatson	error = vn_extattr_get(vp, IO_NODELOCKED,
1052100979Srwatson	    FREEBSD_MAC_EXTATTR_NAMESPACE, FREEBSD_MAC_EXTATTR_NAME, &buflen,
1053100979Srwatson	    (char *)&extmac, curthread);
1054100979Srwatson	switch (error) {
1055100979Srwatson	case 0:
1056100979Srwatson		/* Got it */
1057100979Srwatson		break;
1058100979Srwatson
1059100979Srwatson	case ENOATTR:
1060100979Srwatson		/*
1061100979Srwatson		 * Use the label from the mount point.
1062100979Srwatson		 */
1063100979Srwatson		mac_update_vnode_from_mount(vp, vp->v_mount);
1064100979Srwatson		return (0);
1065100979Srwatson
1066100979Srwatson	case EOPNOTSUPP:
1067100979Srwatson	default:
1068100979Srwatson		/* Fail horribly. */
1069100979Srwatson		return (error);
1070100979Srwatson	}
1071100979Srwatson
1072100979Srwatson	if (buflen != sizeof(extmac))
1073100979Srwatson		error = EPERM;		/* Fail very closed. */
1074100979Srwatson	if (error == 0)
1075100979Srwatson		error = mac_update_vnode_from_externalized(vp, &extmac);
1076100979Srwatson	if (error == 0)
1077101308Sjeff		vp->v_vflag |= VV_CACHEDLABEL;
1078100979Srwatson	else {
1079100979Srwatson		struct vattr va;
1080100979Srwatson
1081100979Srwatson		printf("Corrupted label on %s",
1082100979Srwatson		    vp->v_mount->mnt_stat.f_mntonname);
1083100979Srwatson		if (VOP_GETATTR(vp, &va, curthread->td_ucred, curthread) == 0)
1084100979Srwatson			printf(" inum %ld", va.va_fileid);
1085104268Srwatson#ifdef MAC_DEBUG
1086100979Srwatson		if (mac_debug_label_fallback) {
1087100979Srwatson			printf(", falling back.\n");
1088100979Srwatson			mac_update_vnode_from_mount(vp, vp->v_mount);
1089100979Srwatson			error = 0;
1090100979Srwatson		} else {
1091104268Srwatson#endif
1092100979Srwatson			printf(".\n");
1093100979Srwatson			error = EPERM;
1094104268Srwatson#ifdef MAC_DEBUG
1095100979Srwatson		}
1096104268Srwatson#endif
1097100979Srwatson	}
1098100979Srwatson
1099100979Srwatson	return (error);
1100100979Srwatson}
1101100979Srwatson
1102100979Srwatson/*
1103100979Srwatson * Make sure the vnode label is up-to-date.  If EOPNOTSUPP, then we handle
1104100979Srwatson * the labeling activity outselves.  Filesystems should be careful not
1105100979Srwatson * to change their minds regarding whether they support vop_refreshlabel()
1106100979Srwatson * for a vnode or not.  Don't cache the vnode here, allow the file
1107100979Srwatson * system code to determine if it's safe to cache.  If we update from
1108100979Srwatson * the mount, don't cache since a change to the mount label should affect
1109100979Srwatson * all vnodes.
1110100979Srwatson */
1111100979Srwatsonstatic int
1112100979Srwatsonvn_refreshlabel(struct vnode *vp, struct ucred *cred)
1113100979Srwatson{
1114100979Srwatson	int error;
1115100979Srwatson
1116100979Srwatson	ASSERT_VOP_LOCKED(vp, "vn_refreshlabel");
1117100979Srwatson
1118100979Srwatson	if (vp->v_mount == NULL) {
1119100979Srwatson/*
1120100979Srwatson		Eventually, we probably want to special-case refreshing
1121100979Srwatson		of deadfs vnodes, and if there's a lock-free race somewhere,
1122100979Srwatson		that case might be handled here.
1123100979Srwatson
1124100979Srwatson		mac_update_vnode_deadfs(vp);
1125100979Srwatson		return (0);
1126100979Srwatson */
1127100979Srwatson		/* printf("vn_refreshlabel: null v_mount\n"); */
1128103314Snjl		if (vp->v_type != VNON)
1129100979Srwatson			printf(
1130103314Snjl			    "vn_refreshlabel: null v_mount with non-VNON\n");
1131100979Srwatson		return (EBADF);
1132100979Srwatson	}
1133100979Srwatson
1134101308Sjeff	if (vp->v_vflag & VV_CACHEDLABEL) {
1135100979Srwatson		mac_vnode_label_cache_hits++;
1136100979Srwatson		return (0);
1137100979Srwatson	} else
1138100979Srwatson		mac_vnode_label_cache_misses++;
1139100979Srwatson
1140100979Srwatson	if ((vp->v_mount->mnt_flag & MNT_MULTILABEL) == 0) {
1141100979Srwatson		mac_update_vnode_from_mount(vp, vp->v_mount);
1142100979Srwatson		return (0);
1143100979Srwatson	}
1144100979Srwatson
1145100979Srwatson	error = VOP_REFRESHLABEL(vp, cred, curthread);
1146100979Srwatson	switch (error) {
1147100979Srwatson	case EOPNOTSUPP:
1148100979Srwatson		/*
1149100979Srwatson		 * If labels are not supported on this vnode, fall back to
1150100979Srwatson		 * the label in the mount and propagate it to the vnode.
1151100979Srwatson		 * There should probably be some sort of policy/flag/decision
1152100979Srwatson		 * about doing this.
1153100979Srwatson		 */
1154100979Srwatson		mac_update_vnode_from_mount(vp, vp->v_mount);
1155100979Srwatson		error = 0;
1156100979Srwatson	default:
1157100979Srwatson		return (error);
1158100979Srwatson	}
1159100979Srwatson}
1160100979Srwatson
1161100979Srwatson/*
1162100979Srwatson * Helper function for file systems using the vop_std*_ea() calls.  This
1163100979Srwatson * function must be called after EA service is available for the vnode,
1164100979Srwatson * but before it's hooked up to the namespace so that the node persists
1165100979Srwatson * if there's a crash, or before it can be accessed.  On successful
1166100979Srwatson * commit of the label to disk (etc), do cache the label.
1167100979Srwatson */
1168100979Srwatsonint
1169100979Srwatsonvop_stdcreatevnode_ea(struct vnode *dvp, struct vnode *tvp, struct ucred *cred)
1170100979Srwatson{
1171100979Srwatson	struct mac extmac;
1172100979Srwatson	int error;
1173100979Srwatson
1174101308Sjeff	ASSERT_VOP_LOCKED(tvp, "vop_stdcreatevnode_ea");
1175100979Srwatson	if ((dvp->v_mount->mnt_flag & MNT_MULTILABEL) == 0) {
1176100979Srwatson		mac_update_vnode_from_mount(tvp, tvp->v_mount);
1177100979Srwatson	} else {
1178100979Srwatson		error = vn_refreshlabel(dvp, cred);
1179100979Srwatson		if (error)
1180100979Srwatson			return (error);
1181100979Srwatson
1182100979Srwatson		/*
1183100979Srwatson		 * Stick the label in the vnode.  Then try to write to
1184100979Srwatson		 * disk.  If we fail, return a failure to abort the
1185100979Srwatson		 * create operation.  Really, this failure shouldn't
1186100979Srwatson		 * happen except in fairly unusual circumstances (out
1187100979Srwatson		 * of disk, etc).
1188100979Srwatson		 */
1189100979Srwatson		mac_create_vnode(cred, dvp, tvp);
1190100979Srwatson
1191100979Srwatson		error = mac_stdcreatevnode_ea(tvp);
1192100979Srwatson		if (error)
1193100979Srwatson			return (error);
1194100979Srwatson
1195100979Srwatson		/*
1196100979Srwatson		 * XXX: Eventually this will go away and all policies will
1197100979Srwatson		 * directly manage their extended attributes.
1198100979Srwatson		 */
1199100979Srwatson		error = mac_externalize(&tvp->v_label, &extmac);
1200100979Srwatson		if (error)
1201100979Srwatson			return (error);
1202100979Srwatson
1203100979Srwatson		error = vn_extattr_set(tvp, IO_NODELOCKED,
1204100979Srwatson		    FREEBSD_MAC_EXTATTR_NAMESPACE, FREEBSD_MAC_EXTATTR_NAME,
1205100979Srwatson		    sizeof(extmac), (char *)&extmac, curthread);
1206100979Srwatson		if (error == 0)
1207101308Sjeff			tvp->v_vflag |= VV_CACHEDLABEL;
1208100979Srwatson		else {
1209100979Srwatson#if 0
1210100979Srwatson			/*
1211100979Srwatson			 * In theory, we could have fall-back behavior here.
1212100979Srwatson			 * It would probably be incorrect.
1213100979Srwatson			 */
1214100979Srwatson#endif
1215100979Srwatson			return (error);
1216100979Srwatson		}
1217100979Srwatson	}
1218100979Srwatson
1219100979Srwatson	return (0);
1220100979Srwatson}
1221100979Srwatson
1222100979Srwatsonvoid
1223100979Srwatsonmac_execve_transition(struct ucred *old, struct ucred *new, struct vnode *vp)
1224100979Srwatson{
1225100979Srwatson	int error;
1226100979Srwatson
1227100979Srwatson	ASSERT_VOP_LOCKED(vp, "mac_execve_transition");
1228100979Srwatson
1229100979Srwatson	error = vn_refreshlabel(vp, old);
1230100979Srwatson	if (error) {
1231100979Srwatson		printf("mac_execve_transition: vn_refreshlabel returned %d\n",
1232100979Srwatson		    error);
1233100979Srwatson		printf("mac_execve_transition: using old vnode label\n");
1234100979Srwatson	}
1235100979Srwatson
1236100979Srwatson	MAC_PERFORM(execve_transition, old, new, vp, &vp->v_label);
1237100979Srwatson}
1238100979Srwatson
1239100979Srwatsonint
1240100979Srwatsonmac_execve_will_transition(struct ucred *old, struct vnode *vp)
1241100979Srwatson{
1242100979Srwatson	int error, result;
1243100979Srwatson
1244100979Srwatson	error = vn_refreshlabel(vp, old);
1245100979Srwatson	if (error)
1246100979Srwatson		return (error);
1247100979Srwatson
1248100979Srwatson	result = 0;
1249100979Srwatson	MAC_BOOLEAN(execve_will_transition, ||, old, vp, &vp->v_label);
1250100979Srwatson
1251100979Srwatson	return (result);
1252100979Srwatson}
1253100979Srwatson
1254100979Srwatsonstatic void
1255100979Srwatsonmac_init_label(struct label *label)
1256100979Srwatson{
1257100979Srwatson
1258100979Srwatson	bzero(label, sizeof(*label));
1259100979Srwatson	label->l_flags = MAC_FLAG_INITIALIZED;
1260100979Srwatson}
1261100979Srwatson
1262100979Srwatsonstatic void
1263100979Srwatsonmac_init_structmac(struct mac *mac)
1264100979Srwatson{
1265100979Srwatson
1266100979Srwatson	bzero(mac, sizeof(*mac));
1267100979Srwatson	mac->m_macflags = MAC_FLAG_INITIALIZED;
1268100979Srwatson}
1269100979Srwatson
1270100979Srwatsonstatic void
1271100979Srwatsonmac_destroy_label(struct label *label)
1272100979Srwatson{
1273100979Srwatson
1274100979Srwatson	KASSERT(label->l_flags & MAC_FLAG_INITIALIZED,
1275100979Srwatson	    ("destroying uninitialized label"));
1276100979Srwatson
1277100979Srwatson	bzero(label, sizeof(*label));
1278100979Srwatson	/* implicit: label->l_flags &= ~MAC_FLAG_INITIALIZED; */
1279100979Srwatson}
1280100979Srwatson
1281100979Srwatsonint
1282100979Srwatsonmac_init_mbuf(struct mbuf *m, int how)
1283100979Srwatson{
1284100979Srwatson	KASSERT(m->m_flags & M_PKTHDR, ("mac_init_mbuf on non-header mbuf"));
1285100979Srwatson
1286100979Srwatson	/* "how" is one of M_(TRY|DONT)WAIT */
1287100979Srwatson	mac_init_label(&m->m_pkthdr.label);
1288100979Srwatson	MAC_PERFORM(init_mbuf, m, how, &m->m_pkthdr.label);
1289101988Srwatson#ifdef MAC_DEBUG
1290100979Srwatson	atomic_add_int(&nmacmbufs, 1);
1291101988Srwatson#endif
1292100979Srwatson	return (0);
1293100979Srwatson}
1294100979Srwatson
1295100979Srwatsonvoid
1296100979Srwatsonmac_destroy_mbuf(struct mbuf *m)
1297100979Srwatson{
1298100979Srwatson
1299100979Srwatson	MAC_PERFORM(destroy_mbuf, m, &m->m_pkthdr.label);
1300100979Srwatson	mac_destroy_label(&m->m_pkthdr.label);
1301101988Srwatson#ifdef MAC_DEBUG
1302100979Srwatson	atomic_subtract_int(&nmacmbufs, 1);
1303101988Srwatson#endif
1304100979Srwatson}
1305100979Srwatson
1306100979Srwatsonvoid
1307100979Srwatsonmac_init_cred(struct ucred *cr)
1308100979Srwatson{
1309100979Srwatson
1310100979Srwatson	mac_init_label(&cr->cr_label);
1311100979Srwatson	MAC_PERFORM(init_cred, cr, &cr->cr_label);
1312101988Srwatson#ifdef MAC_DEBUG
1313100979Srwatson	atomic_add_int(&nmaccreds, 1);
1314101988Srwatson#endif
1315100979Srwatson}
1316100979Srwatson
1317100979Srwatsonvoid
1318100979Srwatsonmac_destroy_cred(struct ucred *cr)
1319100979Srwatson{
1320100979Srwatson
1321100979Srwatson	MAC_PERFORM(destroy_cred, cr, &cr->cr_label);
1322100979Srwatson	mac_destroy_label(&cr->cr_label);
1323101988Srwatson#ifdef MAC_DEBUG
1324100979Srwatson	atomic_subtract_int(&nmaccreds, 1);
1325101988Srwatson#endif
1326100979Srwatson}
1327100979Srwatson
1328100979Srwatsonvoid
1329100979Srwatsonmac_init_ifnet(struct ifnet *ifp)
1330100979Srwatson{
1331100979Srwatson
1332100979Srwatson	mac_init_label(&ifp->if_label);
1333100979Srwatson	MAC_PERFORM(init_ifnet, ifp, &ifp->if_label);
1334101988Srwatson#ifdef MAC_DEBUG
1335100979Srwatson	atomic_add_int(&nmacifnets, 1);
1336101988Srwatson#endif
1337100979Srwatson}
1338100979Srwatson
1339100979Srwatsonvoid
1340100979Srwatsonmac_destroy_ifnet(struct ifnet *ifp)
1341100979Srwatson{
1342100979Srwatson
1343100979Srwatson	MAC_PERFORM(destroy_ifnet, ifp, &ifp->if_label);
1344100979Srwatson	mac_destroy_label(&ifp->if_label);
1345101988Srwatson#ifdef MAC_DEBUG
1346100979Srwatson	atomic_subtract_int(&nmacifnets, 1);
1347101988Srwatson#endif
1348100979Srwatson}
1349100979Srwatson
1350100979Srwatsonvoid
1351100979Srwatsonmac_init_ipq(struct ipq *ipq)
1352100979Srwatson{
1353100979Srwatson
1354100979Srwatson	mac_init_label(&ipq->ipq_label);
1355100979Srwatson	MAC_PERFORM(init_ipq, ipq, &ipq->ipq_label);
1356101988Srwatson#ifdef MAC_DEBUG
1357100979Srwatson	atomic_add_int(&nmacipqs, 1);
1358101988Srwatson#endif
1359100979Srwatson}
1360100979Srwatson
1361100979Srwatsonvoid
1362100979Srwatsonmac_destroy_ipq(struct ipq *ipq)
1363100979Srwatson{
1364100979Srwatson
1365100979Srwatson	MAC_PERFORM(destroy_ipq, ipq, &ipq->ipq_label);
1366100979Srwatson	mac_destroy_label(&ipq->ipq_label);
1367101988Srwatson#ifdef MAC_DEBUG
1368100979Srwatson	atomic_subtract_int(&nmacipqs, 1);
1369101988Srwatson#endif
1370100979Srwatson}
1371100979Srwatson
1372100979Srwatsonvoid
1373100979Srwatsonmac_init_socket(struct socket *socket)
1374100979Srwatson{
1375100979Srwatson
1376100979Srwatson	mac_init_label(&socket->so_label);
1377100979Srwatson	mac_init_label(&socket->so_peerlabel);
1378100979Srwatson	MAC_PERFORM(init_socket, socket, &socket->so_label,
1379100979Srwatson	    &socket->so_peerlabel);
1380101988Srwatson#ifdef MAC_DEBUG
1381100979Srwatson	atomic_add_int(&nmacsockets, 1);
1382101988Srwatson#endif
1383100979Srwatson}
1384100979Srwatson
1385100979Srwatsonvoid
1386100979Srwatsonmac_destroy_socket(struct socket *socket)
1387100979Srwatson{
1388100979Srwatson
1389100979Srwatson	MAC_PERFORM(destroy_socket, socket, &socket->so_label,
1390100979Srwatson	    &socket->so_peerlabel);
1391100979Srwatson	mac_destroy_label(&socket->so_label);
1392100979Srwatson	mac_destroy_label(&socket->so_peerlabel);
1393101988Srwatson#ifdef MAC_DEBUG
1394100979Srwatson	atomic_subtract_int(&nmacsockets, 1);
1395101988Srwatson#endif
1396100979Srwatson}
1397100979Srwatson
1398100979Srwatsonvoid
1399100979Srwatsonmac_init_pipe(struct pipe *pipe)
1400100979Srwatson{
1401100979Srwatson	struct label *label;
1402100979Srwatson
1403100979Srwatson	label = malloc(sizeof(struct label), M_MACPIPELABEL, M_ZERO|M_WAITOK);
1404100979Srwatson	mac_init_label(label);
1405100979Srwatson	pipe->pipe_label = label;
1406100979Srwatson	pipe->pipe_peer->pipe_label = label;
1407100979Srwatson	MAC_PERFORM(init_pipe, pipe, pipe->pipe_label);
1408101988Srwatson#ifdef MAC_DEBUG
1409100979Srwatson	atomic_add_int(&nmacpipes, 1);
1410101988Srwatson#endif
1411100979Srwatson}
1412100979Srwatson
1413100979Srwatsonvoid
1414100979Srwatsonmac_destroy_pipe(struct pipe *pipe)
1415100979Srwatson{
1416100979Srwatson
1417100979Srwatson	MAC_PERFORM(destroy_pipe, pipe, pipe->pipe_label);
1418100979Srwatson	mac_destroy_label(pipe->pipe_label);
1419100979Srwatson	free(pipe->pipe_label, M_MACPIPELABEL);
1420101988Srwatson#ifdef MAC_DEBUG
1421100979Srwatson	atomic_subtract_int(&nmacpipes, 1);
1422101988Srwatson#endif
1423100979Srwatson}
1424100979Srwatson
1425100979Srwatsonvoid
1426100979Srwatsonmac_init_bpfdesc(struct bpf_d *bpf_d)
1427100979Srwatson{
1428100979Srwatson
1429100979Srwatson	mac_init_label(&bpf_d->bd_label);
1430100979Srwatson	MAC_PERFORM(init_bpfdesc, bpf_d, &bpf_d->bd_label);
1431101988Srwatson#ifdef MAC_DEBUG
1432100979Srwatson	atomic_add_int(&nmacbpfdescs, 1);
1433101988Srwatson#endif
1434100979Srwatson}
1435100979Srwatson
1436100979Srwatsonvoid
1437100979Srwatsonmac_destroy_bpfdesc(struct bpf_d *bpf_d)
1438100979Srwatson{
1439100979Srwatson
1440100979Srwatson	MAC_PERFORM(destroy_bpfdesc, bpf_d, &bpf_d->bd_label);
1441100979Srwatson	mac_destroy_label(&bpf_d->bd_label);
1442101988Srwatson#ifdef MAC_DEBUG
1443100979Srwatson	atomic_subtract_int(&nmacbpfdescs, 1);
1444101988Srwatson#endif
1445100979Srwatson}
1446100979Srwatson
1447100979Srwatsonvoid
1448100979Srwatsonmac_init_mount(struct mount *mp)
1449100979Srwatson{
1450100979Srwatson
1451100979Srwatson	mac_init_label(&mp->mnt_mntlabel);
1452100979Srwatson	mac_init_label(&mp->mnt_fslabel);
1453100979Srwatson	MAC_PERFORM(init_mount, mp, &mp->mnt_mntlabel, &mp->mnt_fslabel);
1454101988Srwatson#ifdef MAC_DEBUG
1455100979Srwatson	atomic_add_int(&nmacmounts, 1);
1456101988Srwatson#endif
1457100979Srwatson}
1458100979Srwatson
1459100979Srwatsonvoid
1460100979Srwatsonmac_destroy_mount(struct mount *mp)
1461100979Srwatson{
1462100979Srwatson
1463100979Srwatson	MAC_PERFORM(destroy_mount, mp, &mp->mnt_mntlabel, &mp->mnt_fslabel);
1464100979Srwatson	mac_destroy_label(&mp->mnt_fslabel);
1465100979Srwatson	mac_destroy_label(&mp->mnt_mntlabel);
1466101988Srwatson#ifdef MAC_DEBUG
1467100979Srwatson	atomic_subtract_int(&nmacmounts, 1);
1468101988Srwatson#endif
1469100979Srwatson}
1470100979Srwatson
1471100979Srwatsonstatic void
1472100979Srwatsonmac_init_temp(struct label *label)
1473100979Srwatson{
1474100979Srwatson
1475100979Srwatson	mac_init_label(label);
1476100979Srwatson	MAC_PERFORM(init_temp, label);
1477101988Srwatson#ifdef MAC_DEBUG
1478100979Srwatson	atomic_add_int(&nmactemp, 1);
1479101988Srwatson#endif
1480100979Srwatson}
1481100979Srwatson
1482100979Srwatsonstatic void
1483100979Srwatsonmac_destroy_temp(struct label *label)
1484100979Srwatson{
1485100979Srwatson
1486100979Srwatson	MAC_PERFORM(destroy_temp, label);
1487100979Srwatson	mac_destroy_label(label);
1488101988Srwatson#ifdef MAC_DEBUG
1489100979Srwatson	atomic_subtract_int(&nmactemp, 1);
1490101988Srwatson#endif
1491100979Srwatson}
1492100979Srwatson
1493100979Srwatsonvoid
1494100979Srwatsonmac_init_vnode(struct vnode *vp)
1495100979Srwatson{
1496100979Srwatson
1497100979Srwatson	mac_init_label(&vp->v_label);
1498100979Srwatson	MAC_PERFORM(init_vnode, vp, &vp->v_label);
1499101988Srwatson#ifdef MAC_DEBUG
1500100979Srwatson	atomic_add_int(&nmacvnodes, 1);
1501101988Srwatson#endif
1502100979Srwatson}
1503100979Srwatson
1504100979Srwatsonvoid
1505100979Srwatsonmac_destroy_vnode(struct vnode *vp)
1506100979Srwatson{
1507100979Srwatson
1508100979Srwatson	MAC_PERFORM(destroy_vnode, vp, &vp->v_label);
1509100979Srwatson	mac_destroy_label(&vp->v_label);
1510101988Srwatson#ifdef MAC_DEBUG
1511100979Srwatson	atomic_subtract_int(&nmacvnodes, 1);
1512101988Srwatson#endif
1513100979Srwatson}
1514100979Srwatson
1515100979Srwatsonvoid
1516100979Srwatsonmac_init_devfsdirent(struct devfs_dirent *de)
1517100979Srwatson{
1518100979Srwatson
1519100979Srwatson	mac_init_label(&de->de_label);
1520100979Srwatson	MAC_PERFORM(init_devfsdirent, de, &de->de_label);
1521101988Srwatson#ifdef MAC_DEBUG
1522100979Srwatson	atomic_add_int(&nmacdevfsdirents, 1);
1523101988Srwatson#endif
1524100979Srwatson}
1525100979Srwatson
1526100979Srwatsonvoid
1527100979Srwatsonmac_destroy_devfsdirent(struct devfs_dirent *de)
1528100979Srwatson{
1529100979Srwatson
1530100979Srwatson	MAC_PERFORM(destroy_devfsdirent, de, &de->de_label);
1531100979Srwatson	mac_destroy_label(&de->de_label);
1532101988Srwatson#ifdef MAC_DEBUG
1533100979Srwatson	atomic_subtract_int(&nmacdevfsdirents, 1);
1534101988Srwatson#endif
1535100979Srwatson}
1536100979Srwatson
1537100979Srwatsonstatic int
1538100979Srwatsonmac_externalize(struct label *label, struct mac *mac)
1539100979Srwatson{
1540100979Srwatson	int error;
1541100979Srwatson
1542100979Srwatson	mac_init_structmac(mac);
1543100979Srwatson	MAC_CHECK(externalize, label, mac);
1544100979Srwatson
1545100979Srwatson	return (error);
1546100979Srwatson}
1547100979Srwatson
1548100979Srwatsonstatic int
1549100979Srwatsonmac_internalize(struct label *label, struct mac *mac)
1550100979Srwatson{
1551100979Srwatson	int error;
1552100979Srwatson
1553100979Srwatson	mac_init_temp(label);
1554100979Srwatson	MAC_CHECK(internalize, label, mac);
1555100979Srwatson	if (error)
1556100979Srwatson		mac_destroy_temp(label);
1557100979Srwatson
1558100979Srwatson	return (error);
1559100979Srwatson}
1560100979Srwatson
1561100979Srwatson/*
1562100979Srwatson * Initialize MAC label for the first kernel process, from which other
1563100979Srwatson * kernel processes and threads are spawned.
1564100979Srwatson */
1565100979Srwatsonvoid
1566100979Srwatsonmac_create_proc0(struct ucred *cred)
1567100979Srwatson{
1568100979Srwatson
1569100979Srwatson	MAC_PERFORM(create_proc0, cred);
1570100979Srwatson}
1571100979Srwatson
1572100979Srwatson/*
1573100979Srwatson * Initialize MAC label for the first userland process, from which other
1574100979Srwatson * userland processes and threads are spawned.
1575100979Srwatson */
1576100979Srwatsonvoid
1577100979Srwatsonmac_create_proc1(struct ucred *cred)
1578100979Srwatson{
1579100979Srwatson
1580100979Srwatson	MAC_PERFORM(create_proc1, cred);
1581100979Srwatson}
1582100979Srwatson
1583100979Srwatson/*
1584100979Srwatson * When a new process is created, its label must be initialized.  Generally,
1585100979Srwatson * this involves inheritence from the parent process, modulo possible
1586100979Srwatson * deltas.  This function allows that processing to take place.
1587100979Srwatson */
1588100979Srwatsonvoid
1589100979Srwatsonmac_create_cred(struct ucred *parent_cred, struct ucred *child_cred)
1590100979Srwatson{
1591100979Srwatson
1592100979Srwatson	MAC_PERFORM(create_cred, parent_cred, child_cred);
1593100979Srwatson}
1594100979Srwatson
1595100979Srwatsonint
1596100979Srwatsonmac_check_vnode_access(struct ucred *cred, struct vnode *vp, int flags)
1597100979Srwatson{
1598100979Srwatson	int error;
1599100979Srwatson
1600100979Srwatson	ASSERT_VOP_LOCKED(vp, "mac_check_vnode_access");
1601100979Srwatson
1602100979Srwatson	if (!mac_enforce_fs)
1603100979Srwatson		return (0);
1604100979Srwatson
1605100979Srwatson	error = vn_refreshlabel(vp, cred);
1606100979Srwatson	if (error)
1607100979Srwatson		return (error);
1608100979Srwatson
1609100979Srwatson	MAC_CHECK(check_vnode_access, cred, vp, &vp->v_label, flags);
1610100979Srwatson	return (error);
1611100979Srwatson}
1612100979Srwatson
1613100979Srwatsonint
1614100979Srwatsonmac_check_vnode_chdir(struct ucred *cred, struct vnode *dvp)
1615100979Srwatson{
1616100979Srwatson	int error;
1617100979Srwatson
1618100979Srwatson	ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_chdir");
1619100979Srwatson
1620100979Srwatson	if (!mac_enforce_fs)
1621100979Srwatson		return (0);
1622100979Srwatson
1623100979Srwatson	error = vn_refreshlabel(dvp, cred);
1624100979Srwatson	if (error)
1625100979Srwatson		return (error);
1626100979Srwatson
1627100979Srwatson	MAC_CHECK(check_vnode_chdir, cred, dvp, &dvp->v_label);
1628100979Srwatson	return (error);
1629100979Srwatson}
1630100979Srwatson
1631100979Srwatsonint
1632100979Srwatsonmac_check_vnode_chroot(struct ucred *cred, struct vnode *dvp)
1633100979Srwatson{
1634100979Srwatson	int error;
1635100979Srwatson
1636100979Srwatson	ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_chroot");
1637100979Srwatson
1638100979Srwatson	if (!mac_enforce_fs)
1639100979Srwatson		return (0);
1640100979Srwatson
1641100979Srwatson	error = vn_refreshlabel(dvp, cred);
1642100979Srwatson	if (error)
1643100979Srwatson		return (error);
1644100979Srwatson
1645100979Srwatson	MAC_CHECK(check_vnode_chroot, cred, dvp, &dvp->v_label);
1646100979Srwatson	return (error);
1647100979Srwatson}
1648100979Srwatson
1649100979Srwatsonint
1650100979Srwatsonmac_check_vnode_create(struct ucred *cred, struct vnode *dvp,
1651100979Srwatson    struct componentname *cnp, struct vattr *vap)
1652100979Srwatson{
1653100979Srwatson	int error;
1654100979Srwatson
1655100979Srwatson	ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_create");
1656100979Srwatson
1657100979Srwatson	if (!mac_enforce_fs)
1658100979Srwatson		return (0);
1659100979Srwatson
1660100979Srwatson	error = vn_refreshlabel(dvp, cred);
1661100979Srwatson	if (error)
1662100979Srwatson		return (error);
1663100979Srwatson
1664100979Srwatson	MAC_CHECK(check_vnode_create, cred, dvp, &dvp->v_label, cnp, vap);
1665100979Srwatson	return (error);
1666100979Srwatson}
1667100979Srwatson
1668100979Srwatsonint
1669100979Srwatsonmac_check_vnode_delete(struct ucred *cred, struct vnode *dvp, struct vnode *vp,
1670100979Srwatson    struct componentname *cnp)
1671100979Srwatson{
1672100979Srwatson	int error;
1673100979Srwatson
1674100979Srwatson	ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_delete");
1675100979Srwatson	ASSERT_VOP_LOCKED(vp, "mac_check_vnode_delete");
1676100979Srwatson
1677100979Srwatson	if (!mac_enforce_fs)
1678100979Srwatson		return (0);
1679100979Srwatson
1680100979Srwatson	error = vn_refreshlabel(dvp, cred);
1681100979Srwatson	if (error)
1682100979Srwatson		return (error);
1683100979Srwatson	error = vn_refreshlabel(vp, cred);
1684100979Srwatson	if (error)
1685100979Srwatson		return (error);
1686100979Srwatson
1687100979Srwatson	MAC_CHECK(check_vnode_delete, cred, dvp, &dvp->v_label, vp,
1688100979Srwatson	    &vp->v_label, cnp);
1689100979Srwatson	return (error);
1690100979Srwatson}
1691100979Srwatson
1692100979Srwatsonint
1693100979Srwatsonmac_check_vnode_deleteacl(struct ucred *cred, struct vnode *vp,
1694100979Srwatson    acl_type_t type)
1695100979Srwatson{
1696100979Srwatson	int error;
1697100979Srwatson
1698100979Srwatson	ASSERT_VOP_LOCKED(vp, "mac_check_vnode_deleteacl");
1699100979Srwatson
1700100979Srwatson	if (!mac_enforce_fs)
1701100979Srwatson		return (0);
1702100979Srwatson
1703100979Srwatson	error = vn_refreshlabel(vp, cred);
1704100979Srwatson	if (error)
1705100979Srwatson		return (error);
1706100979Srwatson
1707100979Srwatson	MAC_CHECK(check_vnode_deleteacl, cred, vp, &vp->v_label, type);
1708100979Srwatson	return (error);
1709100979Srwatson}
1710100979Srwatson
1711100979Srwatsonint
1712100979Srwatsonmac_check_vnode_exec(struct ucred *cred, struct vnode *vp)
1713100979Srwatson{
1714100979Srwatson	int error;
1715100979Srwatson
1716102102Srwatson	ASSERT_VOP_LOCKED(vp, "mac_check_vnode_exec");
1717102102Srwatson
1718100979Srwatson	if (!mac_enforce_process && !mac_enforce_fs)
1719100979Srwatson		return (0);
1720100979Srwatson
1721100979Srwatson	error = vn_refreshlabel(vp, cred);
1722100979Srwatson	if (error)
1723100979Srwatson		return (error);
1724100979Srwatson	MAC_CHECK(check_vnode_exec, cred, vp, &vp->v_label);
1725100979Srwatson
1726100979Srwatson	return (error);
1727100979Srwatson}
1728100979Srwatson
1729100979Srwatsonint
1730100979Srwatsonmac_check_vnode_getacl(struct ucred *cred, struct vnode *vp, acl_type_t type)
1731100979Srwatson{
1732100979Srwatson	int error;
1733100979Srwatson
1734100979Srwatson	ASSERT_VOP_LOCKED(vp, "mac_check_vnode_getacl");
1735100979Srwatson
1736100979Srwatson	if (!mac_enforce_fs)
1737100979Srwatson		return (0);
1738100979Srwatson
1739100979Srwatson	error = vn_refreshlabel(vp, cred);
1740100979Srwatson	if (error)
1741100979Srwatson		return (error);
1742100979Srwatson
1743100979Srwatson	MAC_CHECK(check_vnode_getacl, cred, vp, &vp->v_label, type);
1744100979Srwatson	return (error);
1745100979Srwatson}
1746100979Srwatson
1747100979Srwatsonint
1748100979Srwatsonmac_check_vnode_getextattr(struct ucred *cred, struct vnode *vp,
1749100979Srwatson    int attrnamespace, const char *name, struct uio *uio)
1750100979Srwatson{
1751100979Srwatson	int error;
1752100979Srwatson
1753100979Srwatson	ASSERT_VOP_LOCKED(vp, "mac_check_vnode_getextattr");
1754100979Srwatson
1755100979Srwatson	if (!mac_enforce_fs)
1756100979Srwatson		return (0);
1757100979Srwatson
1758100979Srwatson	error = vn_refreshlabel(vp, cred);
1759100979Srwatson	if (error)
1760100979Srwatson		return (error);
1761100979Srwatson
1762100979Srwatson	MAC_CHECK(check_vnode_getextattr, cred, vp, &vp->v_label,
1763100979Srwatson	    attrnamespace, name, uio);
1764100979Srwatson	return (error);
1765100979Srwatson}
1766100979Srwatson
1767100979Srwatsonint
1768100979Srwatsonmac_check_vnode_lookup(struct ucred *cred, struct vnode *dvp,
1769100979Srwatson    struct componentname *cnp)
1770100979Srwatson{
1771100979Srwatson	int error;
1772100979Srwatson
1773100979Srwatson	ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_lookup");
1774100979Srwatson
1775100979Srwatson	if (!mac_enforce_fs)
1776100979Srwatson		return (0);
1777100979Srwatson
1778100979Srwatson	error = vn_refreshlabel(dvp, cred);
1779100979Srwatson	if (error)
1780100979Srwatson		return (error);
1781100979Srwatson
1782100979Srwatson	MAC_CHECK(check_vnode_lookup, cred, dvp, &dvp->v_label, cnp);
1783100979Srwatson	return (error);
1784100979Srwatson}
1785100979Srwatson
1786100979Srwatsonvm_prot_t
1787100979Srwatsonmac_check_vnode_mmap_prot(struct ucred *cred, struct vnode *vp, int newmapping)
1788100979Srwatson{
1789100979Srwatson	vm_prot_t result = VM_PROT_ALL;
1790100979Srwatson
1791103514Srwatson	if (!mac_enforce_vm)
1792103514Srwatson		return (result);
1793103514Srwatson
1794100979Srwatson	/*
1795100979Srwatson	 * This should be some sort of MAC_BITWISE, maybe :)
1796100979Srwatson	 */
1797100979Srwatson	ASSERT_VOP_LOCKED(vp, "mac_check_vnode_mmap_perms");
1798100979Srwatson	MAC_BOOLEAN(check_vnode_mmap_perms, &, cred, vp, &vp->v_label,
1799100979Srwatson	    newmapping);
1800100979Srwatson	return (result);
1801100979Srwatson}
1802100979Srwatson
1803100979Srwatsonint
1804102112Srwatsonmac_check_vnode_open(struct ucred *cred, struct vnode *vp, mode_t acc_mode)
1805100979Srwatson{
1806100979Srwatson	int error;
1807100979Srwatson
1808102112Srwatson	ASSERT_VOP_LOCKED(vp, "mac_check_vnode_open");
1809102112Srwatson
1810100979Srwatson	if (!mac_enforce_fs)
1811100979Srwatson		return (0);
1812100979Srwatson
1813102112Srwatson	error = vn_refreshlabel(vp, cred);
1814102112Srwatson	if (error)
1815102112Srwatson		return (error);
1816100979Srwatson
1817102112Srwatson	MAC_CHECK(check_vnode_open, cred, vp, &vp->v_label, acc_mode);
1818102112Srwatson	return (error);
1819102112Srwatson}
1820102112Srwatson
1821102112Srwatsonint
1822102129Srwatsonmac_check_vnode_poll(struct ucred *active_cred, struct ucred *file_cred,
1823102129Srwatson    struct vnode *vp)
1824102112Srwatson{
1825102112Srwatson	int error;
1826102112Srwatson
1827102112Srwatson	ASSERT_VOP_LOCKED(vp, "mac_check_vnode_poll");
1828102112Srwatson
1829102112Srwatson	if (!mac_enforce_fs)
1830102112Srwatson		return (0);
1831102112Srwatson
1832102129Srwatson	error = vn_refreshlabel(vp, active_cred);
1833100979Srwatson	if (error)
1834100979Srwatson		return (error);
1835100979Srwatson
1836102129Srwatson	MAC_CHECK(check_vnode_poll, active_cred, file_cred, vp,
1837102129Srwatson	    &vp->v_label);
1838100979Srwatson
1839100979Srwatson	return (error);
1840100979Srwatson}
1841100979Srwatson
1842100979Srwatsonint
1843102129Srwatsonmac_check_vnode_read(struct ucred *active_cred, struct ucred *file_cred,
1844102129Srwatson    struct vnode *vp)
1845100979Srwatson{
1846100979Srwatson	int error;
1847100979Srwatson
1848102112Srwatson	ASSERT_VOP_LOCKED(vp, "mac_check_vnode_read");
1849100979Srwatson
1850100979Srwatson	if (!mac_enforce_fs)
1851100979Srwatson		return (0);
1852100979Srwatson
1853102129Srwatson	error = vn_refreshlabel(vp, active_cred);
1854100979Srwatson	if (error)
1855100979Srwatson		return (error);
1856100979Srwatson
1857102129Srwatson	MAC_CHECK(check_vnode_read, active_cred, file_cred, vp,
1858102129Srwatson	    &vp->v_label);
1859102112Srwatson
1860100979Srwatson	return (error);
1861100979Srwatson}
1862100979Srwatson
1863100979Srwatsonint
1864100979Srwatsonmac_check_vnode_readdir(struct ucred *cred, struct vnode *dvp)
1865100979Srwatson{
1866100979Srwatson	int error;
1867100979Srwatson
1868100979Srwatson	ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_readdir");
1869100979Srwatson
1870100979Srwatson	if (!mac_enforce_fs)
1871100979Srwatson		return (0);
1872100979Srwatson
1873100979Srwatson	error = vn_refreshlabel(dvp, cred);
1874100979Srwatson	if (error)
1875100979Srwatson		return (error);
1876100979Srwatson
1877100979Srwatson	MAC_CHECK(check_vnode_readdir, cred, dvp, &dvp->v_label);
1878100979Srwatson	return (error);
1879100979Srwatson}
1880100979Srwatson
1881100979Srwatsonint
1882100979Srwatsonmac_check_vnode_readlink(struct ucred *cred, struct vnode *vp)
1883100979Srwatson{
1884100979Srwatson	int error;
1885100979Srwatson
1886100979Srwatson	ASSERT_VOP_LOCKED(vp, "mac_check_vnode_readlink");
1887100979Srwatson
1888100979Srwatson	if (!mac_enforce_fs)
1889100979Srwatson		return (0);
1890100979Srwatson
1891100979Srwatson	error = vn_refreshlabel(vp, cred);
1892100979Srwatson	if (error)
1893100979Srwatson		return (error);
1894100979Srwatson
1895100979Srwatson	MAC_CHECK(check_vnode_readlink, cred, vp, &vp->v_label);
1896100979Srwatson	return (error);
1897100979Srwatson}
1898100979Srwatson
1899100979Srwatsonstatic int
1900100979Srwatsonmac_check_vnode_relabel(struct ucred *cred, struct vnode *vp,
1901100979Srwatson    struct label *newlabel)
1902100979Srwatson{
1903100979Srwatson	int error;
1904100979Srwatson
1905100979Srwatson	ASSERT_VOP_LOCKED(vp, "mac_check_vnode_relabel");
1906100979Srwatson
1907100979Srwatson	error = vn_refreshlabel(vp, cred);
1908100979Srwatson	if (error)
1909100979Srwatson		return (error);
1910100979Srwatson
1911100979Srwatson	MAC_CHECK(check_vnode_relabel, cred, vp, &vp->v_label, newlabel);
1912100979Srwatson
1913100979Srwatson	return (error);
1914100979Srwatson}
1915100979Srwatson
1916100979Srwatsonint
1917100979Srwatsonmac_check_vnode_rename_from(struct ucred *cred, struct vnode *dvp,
1918100979Srwatson    struct vnode *vp, struct componentname *cnp)
1919100979Srwatson{
1920100979Srwatson	int error;
1921100979Srwatson
1922100979Srwatson	ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_rename_from");
1923100979Srwatson	ASSERT_VOP_LOCKED(vp, "mac_check_vnode_rename_from");
1924100979Srwatson
1925100979Srwatson	if (!mac_enforce_fs)
1926100979Srwatson		return (0);
1927100979Srwatson
1928100979Srwatson	error = vn_refreshlabel(dvp, cred);
1929100979Srwatson	if (error)
1930100979Srwatson		return (error);
1931100979Srwatson	error = vn_refreshlabel(vp, cred);
1932100979Srwatson	if (error)
1933100979Srwatson		return (error);
1934100979Srwatson
1935100979Srwatson	MAC_CHECK(check_vnode_rename_from, cred, dvp, &dvp->v_label, vp,
1936100979Srwatson	    &vp->v_label, cnp);
1937100979Srwatson	return (error);
1938100979Srwatson}
1939100979Srwatson
1940100979Srwatsonint
1941100979Srwatsonmac_check_vnode_rename_to(struct ucred *cred, struct vnode *dvp,
1942100979Srwatson    struct vnode *vp, int samedir, struct componentname *cnp)
1943100979Srwatson{
1944100979Srwatson	int error;
1945100979Srwatson
1946100979Srwatson	ASSERT_VOP_LOCKED(dvp, "mac_check_vnode_rename_to");
1947100979Srwatson	ASSERT_VOP_LOCKED(vp, "mac_check_vnode_rename_to");
1948100979Srwatson
1949100979Srwatson	if (!mac_enforce_fs)
1950100979Srwatson		return (0);
1951100979Srwatson
1952100979Srwatson	error = vn_refreshlabel(dvp, cred);
1953100979Srwatson	if (error)
1954100979Srwatson		return (error);
1955100979Srwatson	if (vp != NULL) {
1956100979Srwatson		error = vn_refreshlabel(vp, cred);
1957100979Srwatson		if (error)
1958100979Srwatson			return (error);
1959100979Srwatson	}
1960100979Srwatson	MAC_CHECK(check_vnode_rename_to, cred, dvp, &dvp->v_label, vp,
1961100979Srwatson	    vp != NULL ? &vp->v_label : NULL, samedir, cnp);
1962100979Srwatson	return (error);
1963100979Srwatson}
1964100979Srwatson
1965100979Srwatsonint
1966100979Srwatsonmac_check_vnode_revoke(struct ucred *cred, struct vnode *vp)
1967100979Srwatson{
1968100979Srwatson	int error;
1969100979Srwatson
1970100979Srwatson	ASSERT_VOP_LOCKED(vp, "mac_check_vnode_revoke");
1971100979Srwatson
1972100979Srwatson	if (!mac_enforce_fs)
1973100979Srwatson		return (0);
1974100979Srwatson
1975100979Srwatson	error = vn_refreshlabel(vp, cred);
1976100979Srwatson	if (error)
1977100979Srwatson		return (error);
1978100979Srwatson
1979100979Srwatson	MAC_CHECK(check_vnode_revoke, cred, vp, &vp->v_label);
1980100979Srwatson	return (error);
1981100979Srwatson}
1982100979Srwatson
1983100979Srwatsonint
1984100979Srwatsonmac_check_vnode_setacl(struct ucred *cred, struct vnode *vp, acl_type_t type,
1985100979Srwatson    struct acl *acl)
1986100979Srwatson{
1987100979Srwatson	int error;
1988100979Srwatson
1989100979Srwatson	ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setacl");
1990100979Srwatson
1991100979Srwatson	if (!mac_enforce_fs)
1992100979Srwatson		return (0);
1993100979Srwatson
1994100979Srwatson	error = vn_refreshlabel(vp, cred);
1995100979Srwatson	if (error)
1996100979Srwatson		return (error);
1997100979Srwatson
1998100979Srwatson	MAC_CHECK(check_vnode_setacl, cred, vp, &vp->v_label, type, acl);
1999100979Srwatson	return (error);
2000100979Srwatson}
2001100979Srwatson
2002100979Srwatsonint
2003100979Srwatsonmac_check_vnode_setextattr(struct ucred *cred, struct vnode *vp,
2004100979Srwatson    int attrnamespace, const char *name, struct uio *uio)
2005100979Srwatson{
2006100979Srwatson	int error;
2007100979Srwatson
2008100979Srwatson	ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setextattr");
2009100979Srwatson
2010100979Srwatson	if (!mac_enforce_fs)
2011100979Srwatson		return (0);
2012100979Srwatson
2013100979Srwatson	error = vn_refreshlabel(vp, cred);
2014100979Srwatson	if (error)
2015100979Srwatson		return (error);
2016100979Srwatson
2017100979Srwatson	MAC_CHECK(check_vnode_setextattr, cred, vp, &vp->v_label,
2018100979Srwatson	    attrnamespace, name, uio);
2019100979Srwatson	return (error);
2020100979Srwatson}
2021100979Srwatson
2022100979Srwatsonint
2023100979Srwatsonmac_check_vnode_setflags(struct ucred *cred, struct vnode *vp, u_long flags)
2024100979Srwatson{
2025100979Srwatson	int error;
2026100979Srwatson
2027100979Srwatson	ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setflags");
2028100979Srwatson
2029100979Srwatson	if (!mac_enforce_fs)
2030100979Srwatson		return (0);
2031100979Srwatson
2032100979Srwatson	error = vn_refreshlabel(vp, cred);
2033100979Srwatson	if (error)
2034100979Srwatson		return (error);
2035100979Srwatson
2036100979Srwatson	MAC_CHECK(check_vnode_setflags, cred, vp, &vp->v_label, flags);
2037100979Srwatson	return (error);
2038100979Srwatson}
2039100979Srwatson
2040100979Srwatsonint
2041100979Srwatsonmac_check_vnode_setmode(struct ucred *cred, struct vnode *vp, mode_t mode)
2042100979Srwatson{
2043100979Srwatson	int error;
2044100979Srwatson
2045100979Srwatson	ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setmode");
2046100979Srwatson
2047100979Srwatson	if (!mac_enforce_fs)
2048100979Srwatson		return (0);
2049100979Srwatson
2050100979Srwatson	error = vn_refreshlabel(vp, cred);
2051100979Srwatson	if (error)
2052100979Srwatson		return (error);
2053100979Srwatson
2054100979Srwatson	MAC_CHECK(check_vnode_setmode, cred, vp, &vp->v_label, mode);
2055100979Srwatson	return (error);
2056100979Srwatson}
2057100979Srwatson
2058100979Srwatsonint
2059100979Srwatsonmac_check_vnode_setowner(struct ucred *cred, struct vnode *vp, uid_t uid,
2060100979Srwatson    gid_t gid)
2061100979Srwatson{
2062100979Srwatson	int error;
2063100979Srwatson
2064100979Srwatson	ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setowner");
2065100979Srwatson
2066100979Srwatson	if (!mac_enforce_fs)
2067100979Srwatson		return (0);
2068100979Srwatson
2069100979Srwatson	error = vn_refreshlabel(vp, cred);
2070100979Srwatson	if (error)
2071100979Srwatson		return (error);
2072100979Srwatson
2073100979Srwatson	MAC_CHECK(check_vnode_setowner, cred, vp, &vp->v_label, uid, gid);
2074100979Srwatson	return (error);
2075100979Srwatson}
2076100979Srwatson
2077100979Srwatsonint
2078100979Srwatsonmac_check_vnode_setutimes(struct ucred *cred, struct vnode *vp,
2079100979Srwatson    struct timespec atime, struct timespec mtime)
2080100979Srwatson{
2081100979Srwatson	int error;
2082100979Srwatson
2083100979Srwatson	ASSERT_VOP_LOCKED(vp, "mac_check_vnode_setutimes");
2084100979Srwatson
2085100979Srwatson	if (!mac_enforce_fs)
2086100979Srwatson		return (0);
2087100979Srwatson
2088100979Srwatson	error = vn_refreshlabel(vp, cred);
2089100979Srwatson	if (error)
2090100979Srwatson		return (error);
2091100979Srwatson
2092100979Srwatson	MAC_CHECK(check_vnode_setutimes, cred, vp, &vp->v_label, atime,
2093100979Srwatson	    mtime);
2094100979Srwatson	return (error);
2095100979Srwatson}
2096100979Srwatson
2097100979Srwatsonint
2098102129Srwatsonmac_check_vnode_stat(struct ucred *active_cred, struct ucred *file_cred,
2099102129Srwatson    struct vnode *vp)
2100100979Srwatson{
2101100979Srwatson	int error;
2102100979Srwatson
2103100979Srwatson	ASSERT_VOP_LOCKED(vp, "mac_check_vnode_stat");
2104100979Srwatson
2105100979Srwatson	if (!mac_enforce_fs)
2106100979Srwatson		return (0);
2107100979Srwatson
2108102129Srwatson	error = vn_refreshlabel(vp, active_cred);
2109100979Srwatson	if (error)
2110100979Srwatson		return (error);
2111100979Srwatson
2112102129Srwatson	MAC_CHECK(check_vnode_stat, active_cred, file_cred, vp,
2113102129Srwatson	    &vp->v_label);
2114100979Srwatson	return (error);
2115100979Srwatson}
2116100979Srwatson
2117102112Srwatsonint
2118102129Srwatsonmac_check_vnode_write(struct ucred *active_cred, struct ucred *file_cred,
2119102129Srwatson    struct vnode *vp)
2120102112Srwatson{
2121102112Srwatson	int error;
2122102112Srwatson
2123102112Srwatson	ASSERT_VOP_LOCKED(vp, "mac_check_vnode_write");
2124102112Srwatson
2125102112Srwatson	if (!mac_enforce_fs)
2126102112Srwatson		return (0);
2127102112Srwatson
2128102129Srwatson	error = vn_refreshlabel(vp, active_cred);
2129102112Srwatson	if (error)
2130102112Srwatson		return (error);
2131102112Srwatson
2132102129Srwatson	MAC_CHECK(check_vnode_write, active_cred, file_cred, vp,
2133102129Srwatson	    &vp->v_label);
2134102112Srwatson
2135102112Srwatson	return (error);
2136102112Srwatson}
2137102112Srwatson
2138100979Srwatson/*
2139100979Srwatson * When relabeling a process, call out to the policies for the maximum
2140100979Srwatson * permission allowed for each object type we know about in its
2141100979Srwatson * memory space, and revoke access (in the least surprising ways we
2142100979Srwatson * know) when necessary.  The process lock is not held here.
2143100979Srwatson */
2144100979Srwatsonstatic void
2145100979Srwatsonmac_cred_mmapped_drop_perms(struct thread *td, struct ucred *cred)
2146100979Srwatson{
2147100979Srwatson
2148100979Srwatson	/* XXX freeze all other threads */
2149100979Srwatson	mac_cred_mmapped_drop_perms_recurse(td, cred,
2150100979Srwatson	    &td->td_proc->p_vmspace->vm_map);
2151100979Srwatson	/* XXX allow other threads to continue */
2152100979Srwatson}
2153100979Srwatson
2154100979Srwatsonstatic __inline const char *
2155100979Srwatsonprot2str(vm_prot_t prot)
2156100979Srwatson{
2157100979Srwatson
2158100979Srwatson	switch (prot & VM_PROT_ALL) {
2159100979Srwatson	case VM_PROT_READ:
2160100979Srwatson		return ("r--");
2161100979Srwatson	case VM_PROT_READ | VM_PROT_WRITE:
2162100979Srwatson		return ("rw-");
2163100979Srwatson	case VM_PROT_READ | VM_PROT_EXECUTE:
2164100979Srwatson		return ("r-x");
2165100979Srwatson	case VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE:
2166100979Srwatson		return ("rwx");
2167100979Srwatson	case VM_PROT_WRITE:
2168100979Srwatson		return ("-w-");
2169100979Srwatson	case VM_PROT_EXECUTE:
2170100979Srwatson		return ("--x");
2171100979Srwatson	case VM_PROT_WRITE | VM_PROT_EXECUTE:
2172100979Srwatson		return ("-wx");
2173100979Srwatson	default:
2174100979Srwatson		return ("---");
2175100979Srwatson	}
2176100979Srwatson}
2177100979Srwatson
2178100979Srwatsonstatic void
2179100979Srwatsonmac_cred_mmapped_drop_perms_recurse(struct thread *td, struct ucred *cred,
2180100979Srwatson    struct vm_map *map)
2181100979Srwatson{
2182100979Srwatson	struct vm_map_entry *vme;
2183100979Srwatson	vm_prot_t result, revokeperms;
2184100979Srwatson	vm_object_t object;
2185100979Srwatson	vm_ooffset_t offset;
2186100979Srwatson	struct vnode *vp;
2187100979Srwatson
2188103136Srwatson	if (!mac_mmap_revocation)
2189103136Srwatson		return;
2190103136Srwatson
2191100979Srwatson	vm_map_lock_read(map);
2192100979Srwatson	for (vme = map->header.next; vme != &map->header; vme = vme->next) {
2193100979Srwatson		if (vme->eflags & MAP_ENTRY_IS_SUB_MAP) {
2194100979Srwatson			mac_cred_mmapped_drop_perms_recurse(td, cred,
2195100979Srwatson			    vme->object.sub_map);
2196100979Srwatson			continue;
2197100979Srwatson		}
2198100979Srwatson		/*
2199100979Srwatson		 * Skip over entries that obviously are not shared.
2200100979Srwatson		 */
2201100979Srwatson		if (vme->eflags & (MAP_ENTRY_COW | MAP_ENTRY_NOSYNC) ||
2202100979Srwatson		    !vme->max_protection)
2203100979Srwatson			continue;
2204100979Srwatson		/*
2205100979Srwatson		 * Drill down to the deepest backing object.
2206100979Srwatson		 */
2207100979Srwatson		offset = vme->offset;
2208100979Srwatson		object = vme->object.vm_object;
2209100979Srwatson		if (object == NULL)
2210100979Srwatson			continue;
2211100979Srwatson		while (object->backing_object != NULL) {
2212100979Srwatson			object = object->backing_object;
2213100979Srwatson			offset += object->backing_object_offset;
2214100979Srwatson		}
2215100979Srwatson		/*
2216100979Srwatson		 * At the moment, vm_maps and objects aren't considered
2217100979Srwatson		 * by the MAC system, so only things with backing by a
2218100979Srwatson		 * normal object (read: vnodes) are checked.
2219100979Srwatson		 */
2220100979Srwatson		if (object->type != OBJT_VNODE)
2221100979Srwatson			continue;
2222100979Srwatson		vp = (struct vnode *)object->handle;
2223100979Srwatson		vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
2224100979Srwatson		result = mac_check_vnode_mmap_prot(cred, vp, 0);
2225100979Srwatson		VOP_UNLOCK(vp, 0, td);
2226100979Srwatson		/*
2227100979Srwatson		 * Find out what maximum protection we may be allowing
2228100979Srwatson		 * now but a policy needs to get removed.
2229100979Srwatson		 */
2230100979Srwatson		revokeperms = vme->max_protection & ~result;
2231100979Srwatson		if (!revokeperms)
2232100979Srwatson			continue;
2233102949Sbde		printf("pid %ld: revoking %s perms from %#lx:%ld "
2234102949Sbde		    "(max %s/cur %s)\n", (long)td->td_proc->p_pid,
2235102949Sbde		    prot2str(revokeperms), (u_long)vme->start,
2236102949Sbde		    (long)(vme->end - vme->start),
2237100979Srwatson		    prot2str(vme->max_protection), prot2str(vme->protection));
2238100979Srwatson		vm_map_lock_upgrade(map);
2239100979Srwatson		/*
2240100979Srwatson		 * This is the really simple case: if a map has more
2241100979Srwatson		 * max_protection than is allowed, but it's not being
2242100979Srwatson		 * actually used (that is, the current protection is
2243100979Srwatson		 * still allowed), we can just wipe it out and do
2244100979Srwatson		 * nothing more.
2245100979Srwatson		 */
2246100979Srwatson		if ((vme->protection & revokeperms) == 0) {
2247100979Srwatson			vme->max_protection -= revokeperms;
2248100979Srwatson		} else {
2249100979Srwatson			if (revokeperms & VM_PROT_WRITE) {
2250100979Srwatson				/*
2251100979Srwatson				 * In the more complicated case, flush out all
2252100979Srwatson				 * pending changes to the object then turn it
2253100979Srwatson				 * copy-on-write.
2254100979Srwatson				 */
2255100979Srwatson				vm_object_reference(object);
2256100979Srwatson				vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
2257100979Srwatson				vm_object_page_clean(object,
2258100979Srwatson				    OFF_TO_IDX(offset),
2259100979Srwatson				    OFF_TO_IDX(offset + vme->end - vme->start +
2260100979Srwatson					PAGE_MASK),
2261100979Srwatson				    OBJPC_SYNC);
2262100979Srwatson				VOP_UNLOCK(vp, 0, td);
2263100979Srwatson				vm_object_deallocate(object);
2264100979Srwatson				/*
2265100979Srwatson				 * Why bother if there's no read permissions
2266100979Srwatson				 * anymore?  For the rest, we need to leave
2267100979Srwatson				 * the write permissions on for COW, or
2268100979Srwatson				 * remove them entirely if configured to.
2269100979Srwatson				 */
2270100979Srwatson				if (!mac_mmap_revocation_via_cow) {
2271100979Srwatson					vme->max_protection &= ~VM_PROT_WRITE;
2272100979Srwatson					vme->protection &= ~VM_PROT_WRITE;
2273100979Srwatson				} if ((revokeperms & VM_PROT_READ) == 0)
2274100979Srwatson					vme->eflags |= MAP_ENTRY_COW |
2275100979Srwatson					    MAP_ENTRY_NEEDS_COPY;
2276100979Srwatson			}
2277100979Srwatson			if (revokeperms & VM_PROT_EXECUTE) {
2278100979Srwatson				vme->max_protection &= ~VM_PROT_EXECUTE;
2279100979Srwatson				vme->protection &= ~VM_PROT_EXECUTE;
2280100979Srwatson			}
2281100979Srwatson			if (revokeperms & VM_PROT_READ) {
2282100979Srwatson				vme->max_protection = 0;
2283100979Srwatson				vme->protection = 0;
2284100979Srwatson			}
2285100979Srwatson			pmap_protect(map->pmap, vme->start, vme->end,
2286100979Srwatson			    vme->protection & ~revokeperms);
2287100979Srwatson			vm_map_simplify_entry(map, vme);
2288100979Srwatson		}
2289100979Srwatson		vm_map_lock_downgrade(map);
2290100979Srwatson	}
2291100979Srwatson	vm_map_unlock_read(map);
2292100979Srwatson}
2293100979Srwatson
2294100979Srwatson/*
2295100979Srwatson * When the subject's label changes, it may require revocation of privilege
2296100979Srwatson * to mapped objects.  This can't be done on-the-fly later with a unified
2297100979Srwatson * buffer cache.
2298100979Srwatson */
2299100979Srwatsonstatic void
2300100979Srwatsonmac_relabel_cred(struct ucred *cred, struct label *newlabel)
2301100979Srwatson{
2302100979Srwatson
2303100979Srwatson	MAC_PERFORM(relabel_cred, cred, newlabel);
2304100979Srwatson}
2305100979Srwatson
2306100979Srwatsonvoid
2307100979Srwatsonmac_relabel_vnode(struct ucred *cred, struct vnode *vp, struct label *newlabel)
2308100979Srwatson{
2309100979Srwatson
2310100979Srwatson	MAC_PERFORM(relabel_vnode, cred, vp, &vp->v_label, newlabel);
2311100979Srwatson}
2312100979Srwatson
2313100979Srwatsonvoid
2314100979Srwatsonmac_create_ifnet(struct ifnet *ifnet)
2315100979Srwatson{
2316100979Srwatson
2317100979Srwatson	MAC_PERFORM(create_ifnet, ifnet, &ifnet->if_label);
2318100979Srwatson}
2319100979Srwatson
2320100979Srwatsonvoid
2321100979Srwatsonmac_create_bpfdesc(struct ucred *cred, struct bpf_d *bpf_d)
2322100979Srwatson{
2323100979Srwatson
2324100979Srwatson	MAC_PERFORM(create_bpfdesc, cred, bpf_d, &bpf_d->bd_label);
2325100979Srwatson}
2326100979Srwatson
2327100979Srwatsonvoid
2328100979Srwatsonmac_create_socket(struct ucred *cred, struct socket *socket)
2329100979Srwatson{
2330100979Srwatson
2331100979Srwatson	MAC_PERFORM(create_socket, cred, socket, &socket->so_label);
2332100979Srwatson}
2333100979Srwatson
2334100979Srwatsonvoid
2335100979Srwatsonmac_create_pipe(struct ucred *cred, struct pipe *pipe)
2336100979Srwatson{
2337100979Srwatson
2338100979Srwatson	MAC_PERFORM(create_pipe, cred, pipe, pipe->pipe_label);
2339100979Srwatson}
2340100979Srwatson
2341100979Srwatsonvoid
2342100979Srwatsonmac_create_socket_from_socket(struct socket *oldsocket,
2343100979Srwatson    struct socket *newsocket)
2344100979Srwatson{
2345100979Srwatson
2346100979Srwatson	MAC_PERFORM(create_socket_from_socket, oldsocket, &oldsocket->so_label,
2347100979Srwatson	    newsocket, &newsocket->so_label);
2348100979Srwatson}
2349100979Srwatson
2350100979Srwatsonstatic void
2351100979Srwatsonmac_relabel_socket(struct ucred *cred, struct socket *socket,
2352100979Srwatson    struct label *newlabel)
2353100979Srwatson{
2354100979Srwatson
2355100979Srwatson	MAC_PERFORM(relabel_socket, cred, socket, &socket->so_label, newlabel);
2356100979Srwatson}
2357100979Srwatson
2358100979Srwatsonstatic void
2359100979Srwatsonmac_relabel_pipe(struct ucred *cred, struct pipe *pipe, struct label *newlabel)
2360100979Srwatson{
2361100979Srwatson
2362100979Srwatson	MAC_PERFORM(relabel_pipe, cred, pipe, pipe->pipe_label, newlabel);
2363100979Srwatson}
2364100979Srwatson
2365100979Srwatsonvoid
2366100979Srwatsonmac_set_socket_peer_from_mbuf(struct mbuf *mbuf, struct socket *socket)
2367100979Srwatson{
2368100979Srwatson
2369100979Srwatson	MAC_PERFORM(set_socket_peer_from_mbuf, mbuf, &mbuf->m_pkthdr.label,
2370100979Srwatson	    socket, &socket->so_peerlabel);
2371100979Srwatson}
2372100979Srwatson
2373100979Srwatsonvoid
2374100979Srwatsonmac_set_socket_peer_from_socket(struct socket *oldsocket,
2375100979Srwatson    struct socket *newsocket)
2376100979Srwatson{
2377100979Srwatson
2378100979Srwatson	MAC_PERFORM(set_socket_peer_from_socket, oldsocket,
2379100979Srwatson	    &oldsocket->so_label, newsocket, &newsocket->so_peerlabel);
2380100979Srwatson}
2381100979Srwatson
2382100979Srwatsonvoid
2383100979Srwatsonmac_create_datagram_from_ipq(struct ipq *ipq, struct mbuf *datagram)
2384100979Srwatson{
2385100979Srwatson
2386100979Srwatson	MAC_PERFORM(create_datagram_from_ipq, ipq, &ipq->ipq_label,
2387100979Srwatson	    datagram, &datagram->m_pkthdr.label);
2388100979Srwatson}
2389100979Srwatson
2390100979Srwatsonvoid
2391100979Srwatsonmac_create_fragment(struct mbuf *datagram, struct mbuf *fragment)
2392100979Srwatson{
2393100979Srwatson
2394100979Srwatson	MAC_PERFORM(create_fragment, datagram, &datagram->m_pkthdr.label,
2395100979Srwatson	    fragment, &fragment->m_pkthdr.label);
2396100979Srwatson}
2397100979Srwatson
2398100979Srwatsonvoid
2399100979Srwatsonmac_create_ipq(struct mbuf *fragment, struct ipq *ipq)
2400100979Srwatson{
2401100979Srwatson
2402100979Srwatson	MAC_PERFORM(create_ipq, fragment, &fragment->m_pkthdr.label, ipq,
2403100979Srwatson	    &ipq->ipq_label);
2404100979Srwatson}
2405100979Srwatson
2406100979Srwatsonvoid
2407100979Srwatsonmac_create_mbuf_from_mbuf(struct mbuf *oldmbuf, struct mbuf *newmbuf)
2408100979Srwatson{
2409100979Srwatson
2410100979Srwatson	MAC_PERFORM(create_mbuf_from_mbuf, oldmbuf, &oldmbuf->m_pkthdr.label,
2411100979Srwatson	    newmbuf, &newmbuf->m_pkthdr.label);
2412100979Srwatson}
2413100979Srwatson
2414100979Srwatsonvoid
2415100979Srwatsonmac_create_mbuf_from_bpfdesc(struct bpf_d *bpf_d, struct mbuf *mbuf)
2416100979Srwatson{
2417100979Srwatson
2418100979Srwatson	MAC_PERFORM(create_mbuf_from_bpfdesc, bpf_d, &bpf_d->bd_label, mbuf,
2419100979Srwatson	    &mbuf->m_pkthdr.label);
2420100979Srwatson}
2421100979Srwatson
2422100979Srwatsonvoid
2423100979Srwatsonmac_create_mbuf_linklayer(struct ifnet *ifnet, struct mbuf *mbuf)
2424100979Srwatson{
2425100979Srwatson
2426100979Srwatson	MAC_PERFORM(create_mbuf_linklayer, ifnet, &ifnet->if_label, mbuf,
2427100979Srwatson	    &mbuf->m_pkthdr.label);
2428100979Srwatson}
2429100979Srwatson
2430100979Srwatsonvoid
2431100979Srwatsonmac_create_mbuf_from_ifnet(struct ifnet *ifnet, struct mbuf *mbuf)
2432100979Srwatson{
2433100979Srwatson
2434100979Srwatson	MAC_PERFORM(create_mbuf_from_ifnet, ifnet, &ifnet->if_label, mbuf,
2435100979Srwatson	    &mbuf->m_pkthdr.label);
2436100979Srwatson}
2437100979Srwatson
2438100979Srwatsonvoid
2439100979Srwatsonmac_create_mbuf_multicast_encap(struct mbuf *oldmbuf, struct ifnet *ifnet,
2440100979Srwatson    struct mbuf *newmbuf)
2441100979Srwatson{
2442100979Srwatson
2443100979Srwatson	MAC_PERFORM(create_mbuf_multicast_encap, oldmbuf,
2444100979Srwatson	    &oldmbuf->m_pkthdr.label, ifnet, &ifnet->if_label, newmbuf,
2445100979Srwatson	    &newmbuf->m_pkthdr.label);
2446100979Srwatson}
2447100979Srwatson
2448100979Srwatsonvoid
2449100979Srwatsonmac_create_mbuf_netlayer(struct mbuf *oldmbuf, struct mbuf *newmbuf)
2450100979Srwatson{
2451100979Srwatson
2452100979Srwatson	MAC_PERFORM(create_mbuf_netlayer, oldmbuf, &oldmbuf->m_pkthdr.label,
2453100979Srwatson	    newmbuf, &newmbuf->m_pkthdr.label);
2454100979Srwatson}
2455100979Srwatson
2456100979Srwatsonint
2457100979Srwatsonmac_fragment_match(struct mbuf *fragment, struct ipq *ipq)
2458100979Srwatson{
2459100979Srwatson	int result;
2460100979Srwatson
2461100979Srwatson	result = 1;
2462100979Srwatson	MAC_BOOLEAN(fragment_match, &&, fragment, &fragment->m_pkthdr.label,
2463100979Srwatson	    ipq, &ipq->ipq_label);
2464100979Srwatson
2465100979Srwatson	return (result);
2466100979Srwatson}
2467100979Srwatson
2468100979Srwatsonvoid
2469100979Srwatsonmac_update_ipq(struct mbuf *fragment, struct ipq *ipq)
2470100979Srwatson{
2471100979Srwatson
2472100979Srwatson	MAC_PERFORM(update_ipq, fragment, &fragment->m_pkthdr.label, ipq,
2473100979Srwatson	    &ipq->ipq_label);
2474100979Srwatson}
2475100979Srwatson
2476100979Srwatsonvoid
2477100979Srwatsonmac_create_mbuf_from_socket(struct socket *socket, struct mbuf *mbuf)
2478100979Srwatson{
2479100979Srwatson
2480100979Srwatson	MAC_PERFORM(create_mbuf_from_socket, socket, &socket->so_label, mbuf,
2481100979Srwatson	    &mbuf->m_pkthdr.label);
2482100979Srwatson}
2483100979Srwatson
2484100979Srwatsonvoid
2485100979Srwatsonmac_create_mount(struct ucred *cred, struct mount *mp)
2486100979Srwatson{
2487100979Srwatson
2488100979Srwatson	MAC_PERFORM(create_mount, cred, mp, &mp->mnt_mntlabel,
2489100979Srwatson	    &mp->mnt_fslabel);
2490100979Srwatson}
2491100979Srwatson
2492100979Srwatsonvoid
2493100979Srwatsonmac_create_root_mount(struct ucred *cred, struct mount *mp)
2494100979Srwatson{
2495100979Srwatson
2496100979Srwatson	MAC_PERFORM(create_root_mount, cred, mp, &mp->mnt_mntlabel,
2497100979Srwatson	    &mp->mnt_fslabel);
2498100979Srwatson}
2499100979Srwatson
2500100979Srwatsonint
2501100979Srwatsonmac_check_bpfdesc_receive(struct bpf_d *bpf_d, struct ifnet *ifnet)
2502100979Srwatson{
2503100979Srwatson	int error;
2504100979Srwatson
2505100979Srwatson	if (!mac_enforce_network)
2506100979Srwatson		return (0);
2507100979Srwatson
2508100979Srwatson	MAC_CHECK(check_bpfdesc_receive, bpf_d, &bpf_d->bd_label, ifnet,
2509100979Srwatson	    &ifnet->if_label);
2510100979Srwatson
2511100979Srwatson	return (error);
2512100979Srwatson}
2513100979Srwatson
2514100979Srwatsonstatic int
2515100979Srwatsonmac_check_cred_relabel(struct ucred *cred, struct label *newlabel)
2516100979Srwatson{
2517100979Srwatson	int error;
2518100979Srwatson
2519100979Srwatson	MAC_CHECK(check_cred_relabel, cred, newlabel);
2520100979Srwatson
2521100979Srwatson	return (error);
2522100979Srwatson}
2523100979Srwatson
2524100979Srwatsonint
2525100979Srwatsonmac_check_cred_visible(struct ucred *u1, struct ucred *u2)
2526100979Srwatson{
2527100979Srwatson	int error;
2528100979Srwatson
2529100979Srwatson	if (!mac_enforce_process)
2530100979Srwatson		return (0);
2531100979Srwatson
2532100979Srwatson	MAC_CHECK(check_cred_visible, u1, u2);
2533100979Srwatson
2534100979Srwatson	return (error);
2535100979Srwatson}
2536100979Srwatson
2537100979Srwatsonint
2538100979Srwatsonmac_check_ifnet_transmit(struct ifnet *ifnet, struct mbuf *mbuf)
2539100979Srwatson{
2540100979Srwatson	int error;
2541100979Srwatson
2542100979Srwatson	if (!mac_enforce_network)
2543100979Srwatson		return (0);
2544100979Srwatson
2545100979Srwatson	KASSERT(mbuf->m_flags & M_PKTHDR, ("packet has no pkthdr"));
2546100979Srwatson	if (!(mbuf->m_pkthdr.label.l_flags & MAC_FLAG_INITIALIZED))
2547100979Srwatson		printf("%s%d: not initialized\n", ifnet->if_name,
2548100979Srwatson		    ifnet->if_unit);
2549100979Srwatson
2550100979Srwatson	MAC_CHECK(check_ifnet_transmit, ifnet, &ifnet->if_label, mbuf,
2551100979Srwatson	    &mbuf->m_pkthdr.label);
2552100979Srwatson
2553100979Srwatson	return (error);
2554100979Srwatson}
2555100979Srwatson
2556100979Srwatsonint
2557100979Srwatsonmac_check_mount_stat(struct ucred *cred, struct mount *mount)
2558100979Srwatson{
2559100979Srwatson	int error;
2560100979Srwatson
2561100979Srwatson	if (!mac_enforce_fs)
2562100979Srwatson		return (0);
2563100979Srwatson
2564100979Srwatson	MAC_CHECK(check_mount_stat, cred, mount, &mount->mnt_mntlabel);
2565100979Srwatson
2566100979Srwatson	return (error);
2567100979Srwatson}
2568100979Srwatson
2569100979Srwatsonint
2570100979Srwatsonmac_check_pipe_ioctl(struct ucred *cred, struct pipe *pipe, unsigned long cmd,
2571100979Srwatson    void *data)
2572100979Srwatson{
2573100979Srwatson	int error;
2574100979Srwatson
2575104269Srwatson	PIPE_LOCK_ASSERT(pipe, MA_OWNED);
2576104269Srwatson
2577104269Srwatson	if (!mac_enforce_pipe)
2578104269Srwatson		return (0);
2579104269Srwatson
2580100979Srwatson	MAC_CHECK(check_pipe_ioctl, cred, pipe, pipe->pipe_label, cmd, data);
2581100979Srwatson
2582100979Srwatson	return (error);
2583100979Srwatson}
2584100979Srwatson
2585100979Srwatsonint
2586102115Srwatsonmac_check_pipe_poll(struct ucred *cred, struct pipe *pipe)
2587100979Srwatson{
2588100979Srwatson	int error;
2589100979Srwatson
2590104269Srwatson	PIPE_LOCK_ASSERT(pipe, MA_OWNED);
2591104269Srwatson
2592104269Srwatson	if (!mac_enforce_pipe)
2593104269Srwatson		return (0);
2594104269Srwatson
2595102115Srwatson	MAC_CHECK(check_pipe_poll, cred, pipe, pipe->pipe_label);
2596100979Srwatson
2597100979Srwatson	return (error);
2598100979Srwatson}
2599100979Srwatson
2600102115Srwatsonint
2601102115Srwatsonmac_check_pipe_read(struct ucred *cred, struct pipe *pipe)
2602102115Srwatson{
2603102115Srwatson	int error;
2604102115Srwatson
2605104269Srwatson	PIPE_LOCK_ASSERT(pipe, MA_OWNED);
2606104269Srwatson
2607104269Srwatson	if (!mac_enforce_pipe)
2608104269Srwatson		return (0);
2609104269Srwatson
2610102115Srwatson	MAC_CHECK(check_pipe_read, cred, pipe, pipe->pipe_label);
2611102115Srwatson
2612102115Srwatson	return (error);
2613102115Srwatson}
2614102115Srwatson
2615100979Srwatsonstatic int
2616100979Srwatsonmac_check_pipe_relabel(struct ucred *cred, struct pipe *pipe,
2617100979Srwatson    struct label *newlabel)
2618100979Srwatson{
2619100979Srwatson	int error;
2620100979Srwatson
2621104269Srwatson	PIPE_LOCK_ASSERT(pipe, MA_OWNED);
2622104269Srwatson
2623104269Srwatson	if (!mac_enforce_pipe)
2624104269Srwatson		return (0);
2625104269Srwatson
2626100979Srwatson	MAC_CHECK(check_pipe_relabel, cred, pipe, pipe->pipe_label, newlabel);
2627100979Srwatson
2628100979Srwatson	return (error);
2629100979Srwatson}
2630100979Srwatson
2631100979Srwatsonint
2632102115Srwatsonmac_check_pipe_stat(struct ucred *cred, struct pipe *pipe)
2633102115Srwatson{
2634102115Srwatson	int error;
2635102115Srwatson
2636104269Srwatson	PIPE_LOCK_ASSERT(pipe, MA_OWNED);
2637104269Srwatson
2638104269Srwatson	if (!mac_enforce_pipe)
2639104269Srwatson		return (0);
2640104269Srwatson
2641102115Srwatson	MAC_CHECK(check_pipe_stat, cred, pipe, pipe->pipe_label);
2642102115Srwatson
2643102115Srwatson	return (error);
2644102115Srwatson}
2645102115Srwatson
2646102115Srwatsonint
2647102115Srwatsonmac_check_pipe_write(struct ucred *cred, struct pipe *pipe)
2648102115Srwatson{
2649102115Srwatson	int error;
2650102115Srwatson
2651104269Srwatson	PIPE_LOCK_ASSERT(pipe, MA_OWNED);
2652104269Srwatson
2653104269Srwatson	if (!mac_enforce_pipe)
2654104269Srwatson		return (0);
2655104269Srwatson
2656102115Srwatson	MAC_CHECK(check_pipe_write, cred, pipe, pipe->pipe_label);
2657102115Srwatson
2658102115Srwatson	return (error);
2659102115Srwatson}
2660102115Srwatson
2661102115Srwatsonint
2662100979Srwatsonmac_check_proc_debug(struct ucred *cred, struct proc *proc)
2663100979Srwatson{
2664100979Srwatson	int error;
2665100979Srwatson
2666102103Srwatson	PROC_LOCK_ASSERT(proc, MA_OWNED);
2667102103Srwatson
2668100979Srwatson	if (!mac_enforce_process)
2669100979Srwatson		return (0);
2670100979Srwatson
2671100979Srwatson	MAC_CHECK(check_proc_debug, cred, proc);
2672100979Srwatson
2673100979Srwatson	return (error);
2674100979Srwatson}
2675100979Srwatson
2676100979Srwatsonint
2677100979Srwatsonmac_check_proc_sched(struct ucred *cred, struct proc *proc)
2678100979Srwatson{
2679100979Srwatson	int error;
2680100979Srwatson
2681102103Srwatson	PROC_LOCK_ASSERT(proc, MA_OWNED);
2682102103Srwatson
2683100979Srwatson	if (!mac_enforce_process)
2684100979Srwatson		return (0);
2685100979Srwatson
2686100979Srwatson	MAC_CHECK(check_proc_sched, cred, proc);
2687100979Srwatson
2688100979Srwatson	return (error);
2689100979Srwatson}
2690100979Srwatson
2691100979Srwatsonint
2692100979Srwatsonmac_check_proc_signal(struct ucred *cred, struct proc *proc, int signum)
2693100979Srwatson{
2694100979Srwatson	int error;
2695100979Srwatson
2696102103Srwatson	PROC_LOCK_ASSERT(proc, MA_OWNED);
2697102103Srwatson
2698100979Srwatson	if (!mac_enforce_process)
2699100979Srwatson		return (0);
2700100979Srwatson
2701100979Srwatson	MAC_CHECK(check_proc_signal, cred, proc, signum);
2702100979Srwatson
2703100979Srwatson	return (error);
2704100979Srwatson}
2705100979Srwatson
2706100979Srwatsonint
2707100979Srwatsonmac_check_socket_bind(struct ucred *ucred, struct socket *socket,
2708100979Srwatson    struct sockaddr *sockaddr)
2709100979Srwatson{
2710100979Srwatson	int error;
2711100979Srwatson
2712100979Srwatson	if (!mac_enforce_socket)
2713100979Srwatson		return (0);
2714100979Srwatson
2715100979Srwatson	MAC_CHECK(check_socket_bind, ucred, socket, &socket->so_label,
2716100979Srwatson	    sockaddr);
2717100979Srwatson
2718100979Srwatson	return (error);
2719100979Srwatson}
2720100979Srwatson
2721100979Srwatsonint
2722100979Srwatsonmac_check_socket_connect(struct ucred *cred, struct socket *socket,
2723100979Srwatson    struct sockaddr *sockaddr)
2724100979Srwatson{
2725100979Srwatson	int error;
2726100979Srwatson
2727100979Srwatson	if (!mac_enforce_socket)
2728100979Srwatson		return (0);
2729100979Srwatson
2730100979Srwatson	MAC_CHECK(check_socket_connect, cred, socket, &socket->so_label,
2731100979Srwatson	    sockaddr);
2732100979Srwatson
2733100979Srwatson	return (error);
2734100979Srwatson}
2735100979Srwatson
2736100979Srwatsonint
2737101933Srwatsonmac_check_socket_deliver(struct socket *socket, struct mbuf *mbuf)
2738100979Srwatson{
2739100979Srwatson	int error;
2740100979Srwatson
2741100979Srwatson	if (!mac_enforce_socket)
2742100979Srwatson		return (0);
2743100979Srwatson
2744101933Srwatson	MAC_CHECK(check_socket_deliver, socket, &socket->so_label, mbuf,
2745101933Srwatson	    &mbuf->m_pkthdr.label);
2746101933Srwatson
2747100979Srwatson	return (error);
2748100979Srwatson}
2749100979Srwatson
2750100979Srwatsonint
2751101933Srwatsonmac_check_socket_listen(struct ucred *cred, struct socket *socket)
2752100979Srwatson{
2753100979Srwatson	int error;
2754100979Srwatson
2755100979Srwatson	if (!mac_enforce_socket)
2756100979Srwatson		return (0);
2757100979Srwatson
2758101933Srwatson	MAC_CHECK(check_socket_listen, cred, socket, &socket->so_label);
2759100979Srwatson	return (error);
2760100979Srwatson}
2761100979Srwatson
2762100979Srwatsonstatic int
2763100979Srwatsonmac_check_socket_relabel(struct ucred *cred, struct socket *socket,
2764100979Srwatson    struct label *newlabel)
2765100979Srwatson{
2766100979Srwatson	int error;
2767100979Srwatson
2768100979Srwatson	MAC_CHECK(check_socket_relabel, cred, socket, &socket->so_label,
2769100979Srwatson	    newlabel);
2770100979Srwatson
2771100979Srwatson	return (error);
2772100979Srwatson}
2773100979Srwatson
2774100979Srwatsonint
2775100979Srwatsonmac_check_socket_visible(struct ucred *cred, struct socket *socket)
2776100979Srwatson{
2777100979Srwatson	int error;
2778100979Srwatson
2779100979Srwatson	if (!mac_enforce_socket)
2780100979Srwatson		return (0);
2781100979Srwatson
2782100979Srwatson	MAC_CHECK(check_socket_visible, cred, socket, &socket->so_label);
2783100979Srwatson
2784100979Srwatson	return (error);
2785100979Srwatson}
2786100979Srwatson
2787100979Srwatsonint
2788100979Srwatsonmac_ioctl_ifnet_get(struct ucred *cred, struct ifreq *ifr,
2789100979Srwatson    struct ifnet *ifnet)
2790100979Srwatson{
2791100979Srwatson	struct mac label;
2792100979Srwatson	int error;
2793100979Srwatson
2794100979Srwatson	error = mac_externalize(&ifnet->if_label, &label);
2795100979Srwatson	if (error)
2796100979Srwatson		return (error);
2797100979Srwatson
2798100979Srwatson	return (copyout(&label, ifr->ifr_ifru.ifru_data, sizeof(label)));
2799100979Srwatson}
2800100979Srwatson
2801100979Srwatsonint
2802100979Srwatsonmac_ioctl_ifnet_set(struct ucred *cred, struct ifreq *ifr,
2803100979Srwatson    struct ifnet *ifnet)
2804100979Srwatson{
2805100979Srwatson	struct mac newlabel;
2806100979Srwatson	struct label intlabel;
2807100979Srwatson	int error;
2808100979Srwatson
2809100979Srwatson	error = copyin(ifr->ifr_ifru.ifru_data, &newlabel, sizeof(newlabel));
2810100979Srwatson	if (error)
2811100979Srwatson		return (error);
2812100979Srwatson
2813100979Srwatson	error = mac_internalize(&intlabel, &newlabel);
2814100979Srwatson	if (error)
2815100979Srwatson		return (error);
2816100979Srwatson
2817100979Srwatson	/*
2818100979Srwatson	 * XXX: Note that this is a redundant privilege check, since
2819100979Srwatson	 * policies impose this check themselves if required by the
2820100979Srwatson	 * policy.  Eventually, this should go away.
2821100979Srwatson	 */
2822100979Srwatson	error = suser_cred(cred, 0);
2823100979Srwatson	if (error)
2824100979Srwatson		goto out;
2825100979Srwatson
2826100979Srwatson	MAC_CHECK(check_ifnet_relabel, cred, ifnet, &ifnet->if_label,
2827100979Srwatson	    &intlabel);
2828100979Srwatson	if (error)
2829100979Srwatson		goto out;
2830100979Srwatson
2831100979Srwatson	MAC_PERFORM(relabel_ifnet, cred, ifnet, &ifnet->if_label, &intlabel);
2832100979Srwatson
2833100979Srwatsonout:
2834100979Srwatson	mac_destroy_temp(&intlabel);
2835100979Srwatson	return (error);
2836100979Srwatson}
2837100979Srwatson
2838100979Srwatsonvoid
2839100979Srwatsonmac_create_devfs_vnode(struct devfs_dirent *de, struct vnode *vp)
2840100979Srwatson{
2841100979Srwatson
2842100979Srwatson	MAC_PERFORM(create_devfs_vnode, de, &de->de_label, vp, &vp->v_label);
2843100979Srwatson}
2844100979Srwatson
2845100979Srwatsonvoid
2846100979Srwatsonmac_create_devfs_device(dev_t dev, struct devfs_dirent *de)
2847100979Srwatson{
2848100979Srwatson
2849100979Srwatson	MAC_PERFORM(create_devfs_device, dev, de, &de->de_label);
2850100979Srwatson}
2851100979Srwatson
2852100979Srwatsonstatic int
2853100979Srwatsonmac_stdcreatevnode_ea(struct vnode *vp)
2854100979Srwatson{
2855100979Srwatson	int error;
2856100979Srwatson
2857100979Srwatson	MAC_CHECK(stdcreatevnode_ea, vp, &vp->v_label);
2858100979Srwatson
2859100979Srwatson	return (error);
2860100979Srwatson}
2861100979Srwatson
2862100979Srwatsonvoid
2863100979Srwatsonmac_create_devfs_directory(char *dirname, int dirnamelen,
2864100979Srwatson    struct devfs_dirent *de)
2865100979Srwatson{
2866100979Srwatson
2867100979Srwatson	MAC_PERFORM(create_devfs_directory, dirname, dirnamelen, de,
2868100979Srwatson	    &de->de_label);
2869100979Srwatson}
2870100979Srwatson
2871100979Srwatson/*
2872100979Srwatson * When a new vnode is created, this call will initialize its label.
2873100979Srwatson */
2874100979Srwatsonvoid
2875100979Srwatsonmac_create_vnode(struct ucred *cred, struct vnode *parent,
2876100979Srwatson    struct vnode *child)
2877100979Srwatson{
2878100979Srwatson	int error;
2879100979Srwatson
2880100979Srwatson	ASSERT_VOP_LOCKED(parent, "mac_create_vnode");
2881100979Srwatson	ASSERT_VOP_LOCKED(child, "mac_create_vnode");
2882100979Srwatson
2883100979Srwatson	error = vn_refreshlabel(parent, cred);
2884100979Srwatson	if (error) {
2885100979Srwatson		printf("mac_create_vnode: vn_refreshlabel returned %d\n",
2886100979Srwatson		    error);
2887100979Srwatson		printf("mac_create_vnode: using old vnode label\n");
2888100979Srwatson	}
2889100979Srwatson
2890100979Srwatson	MAC_PERFORM(create_vnode, cred, parent, &parent->v_label, child,
2891100979Srwatson	    &child->v_label);
2892100979Srwatson}
2893100979Srwatson
2894100979Srwatsonint
2895100979Srwatsonmac_setsockopt_label_set(struct ucred *cred, struct socket *so,
2896100979Srwatson    struct mac *extmac)
2897100979Srwatson{
2898100979Srwatson	struct label intlabel;
2899100979Srwatson	int error;
2900100979Srwatson
2901100979Srwatson	error = mac_internalize(&intlabel, extmac);
2902100979Srwatson	if (error)
2903100979Srwatson		return (error);
2904100979Srwatson
2905100979Srwatson	mac_check_socket_relabel(cred, so, &intlabel);
2906100979Srwatson	if (error) {
2907100979Srwatson		mac_destroy_temp(&intlabel);
2908100979Srwatson		return (error);
2909100979Srwatson	}
2910100979Srwatson
2911100979Srwatson	mac_relabel_socket(cred, so, &intlabel);
2912100979Srwatson
2913100979Srwatson	mac_destroy_temp(&intlabel);
2914100979Srwatson	return (0);
2915100979Srwatson}
2916100979Srwatson
2917100979Srwatsonint
2918100979Srwatsonmac_pipe_label_set(struct ucred *cred, struct pipe *pipe, struct label *label)
2919100979Srwatson{
2920100979Srwatson	int error;
2921100979Srwatson
2922104269Srwatson	PIPE_LOCK_ASSERT(pipe, MA_OWNED);
2923104269Srwatson
2924100979Srwatson	error = mac_check_pipe_relabel(cred, pipe, label);
2925100979Srwatson	if (error)
2926100979Srwatson		return (error);
2927100979Srwatson
2928100979Srwatson	mac_relabel_pipe(cred, pipe, label);
2929100979Srwatson
2930100979Srwatson	return (0);
2931100979Srwatson}
2932100979Srwatson
2933100979Srwatsonint
2934100979Srwatsonmac_getsockopt_label_get(struct ucred *cred, struct socket *so,
2935100979Srwatson    struct mac *extmac)
2936100979Srwatson{
2937100979Srwatson
2938100979Srwatson	return (mac_externalize(&so->so_label, extmac));
2939100979Srwatson}
2940100979Srwatson
2941100979Srwatsonint
2942100979Srwatsonmac_getsockopt_peerlabel_get(struct ucred *cred, struct socket *so,
2943100979Srwatson    struct mac *extmac)
2944100979Srwatson{
2945100979Srwatson
2946100979Srwatson	return (mac_externalize(&so->so_peerlabel, extmac));
2947100979Srwatson}
2948100979Srwatson
2949100979Srwatson/*
2950100979Srwatson * Implementation of VOP_SETLABEL() that relies on extended attributes
2951100979Srwatson * to store label data.  Can be referenced by filesystems supporting
2952100979Srwatson * extended attributes.
2953100979Srwatson */
2954100979Srwatsonint
2955100979Srwatsonvop_stdsetlabel_ea(struct vop_setlabel_args *ap)
2956100979Srwatson{
2957100979Srwatson	struct vnode *vp = ap->a_vp;
2958100979Srwatson	struct label *intlabel = ap->a_label;
2959100979Srwatson	struct mac extmac;
2960100979Srwatson	int error;
2961100979Srwatson
2962100979Srwatson	ASSERT_VOP_LOCKED(vp, "vop_stdsetlabel_ea");
2963100979Srwatson
2964100979Srwatson	/*
2965100979Srwatson	 * XXX: Eventually call out to EA check/set calls here.
2966100979Srwatson	 * Be particularly careful to avoid race conditions,
2967100979Srwatson	 * consistency problems, and stability problems when
2968100979Srwatson	 * dealing with multiple EAs.  In particular, we require
2969100979Srwatson	 * the ability to write multiple EAs on the same file in
2970100979Srwatson	 * a single transaction, which the current EA interface
2971100979Srwatson	 * does not provide.
2972100979Srwatson	 */
2973100979Srwatson
2974100979Srwatson	error = mac_externalize(intlabel, &extmac);
2975100979Srwatson	if (error)
2976100979Srwatson		return (error);
2977100979Srwatson
2978100979Srwatson	error = vn_extattr_set(vp, IO_NODELOCKED,
2979100979Srwatson	    FREEBSD_MAC_EXTATTR_NAMESPACE, FREEBSD_MAC_EXTATTR_NAME,
2980100979Srwatson	    sizeof(extmac), (char *)&extmac, curthread);
2981100979Srwatson	if (error)
2982100979Srwatson		return (error);
2983100979Srwatson
2984100979Srwatson	mac_relabel_vnode(ap->a_cred, vp, intlabel);
2985100979Srwatson
2986101308Sjeff	vp->v_vflag |= VV_CACHEDLABEL;
2987100979Srwatson
2988100979Srwatson	return (0);
2989100979Srwatson}
2990100979Srwatson
2991100979Srwatsonstatic int
2992100979Srwatsonvn_setlabel(struct vnode *vp, struct label *intlabel, struct ucred *cred)
2993100979Srwatson{
2994100979Srwatson	int error;
2995100979Srwatson
2996100979Srwatson	if (vp->v_mount == NULL) {
2997100979Srwatson		/* printf("vn_setlabel: null v_mount\n"); */
2998103314Snjl		if (vp->v_type != VNON)
2999103314Snjl			printf("vn_setlabel: null v_mount with non-VNON\n");
3000100979Srwatson		return (EBADF);
3001100979Srwatson	}
3002100979Srwatson
3003100979Srwatson	if ((vp->v_mount->mnt_flag & MNT_MULTILABEL) == 0)
3004100979Srwatson		return (EOPNOTSUPP);
3005100979Srwatson
3006100979Srwatson	/*
3007100979Srwatson	 * Multi-phase commit.  First check the policies to confirm the
3008100979Srwatson	 * change is OK.  Then commit via the filesystem.  Finally,
3009100979Srwatson	 * update the actual vnode label.  Question: maybe the filesystem
3010100979Srwatson	 * should update the vnode at the end as part of VOP_SETLABEL()?
3011100979Srwatson	 */
3012100979Srwatson	error = mac_check_vnode_relabel(cred, vp, intlabel);
3013100979Srwatson	if (error)
3014100979Srwatson		return (error);
3015100979Srwatson
3016100979Srwatson	/*
3017100979Srwatson	 * VADMIN provides the opportunity for the filesystem to make
3018100979Srwatson	 * decisions about who is and is not able to modify labels
3019100979Srwatson	 * and protections on files.  This might not be right.  We can't
3020100979Srwatson	 * assume VOP_SETLABEL() will do it, because we might implement
3021100979Srwatson	 * that as part of vop_stdsetlabel_ea().
3022100979Srwatson	 */
3023100979Srwatson	error = VOP_ACCESS(vp, VADMIN, cred, curthread);
3024100979Srwatson	if (error)
3025100979Srwatson		return (error);
3026100979Srwatson
3027100979Srwatson	error = VOP_SETLABEL(vp, intlabel, cred, curthread);
3028100979Srwatson	if (error)
3029100979Srwatson		return (error);
3030100979Srwatson
3031100979Srwatson	return (0);
3032100979Srwatson}
3033100979Srwatson
3034100979Srwatson/*
3035100979Srwatson * MPSAFE
3036100979Srwatson */
3037100979Srwatsonint
3038100894Srwatson__mac_get_proc(struct thread *td, struct __mac_get_proc_args *uap)
3039100894Srwatson{
3040100979Srwatson	struct mac extmac;
3041100979Srwatson	int error;
3042100894Srwatson
3043100979Srwatson	error = mac_externalize(&td->td_ucred->cr_label, &extmac);
3044100979Srwatson	if (error == 0)
3045100979Srwatson		error = copyout(&extmac, SCARG(uap, mac_p), sizeof(extmac));
3046100979Srwatson
3047100979Srwatson	return (error);
3048100979Srwatson}
3049100979Srwatson
3050100979Srwatson/*
3051100979Srwatson * MPSAFE
3052100979Srwatson */
3053100979Srwatsonint
3054100979Srwatson__mac_set_proc(struct thread *td, struct __mac_set_proc_args *uap)
3055100979Srwatson{
3056100979Srwatson	struct ucred *newcred, *oldcred;
3057100979Srwatson	struct proc *p;
3058100979Srwatson	struct mac extmac;
3059100979Srwatson	struct label intlabel;
3060100979Srwatson	int error;
3061100979Srwatson
3062100979Srwatson	error = copyin(SCARG(uap, mac_p), &extmac, sizeof(extmac));
3063100979Srwatson	if (error)
3064100979Srwatson		return (error);
3065100979Srwatson
3066100979Srwatson	error = mac_internalize(&intlabel, &extmac);
3067100979Srwatson	if (error)
3068100979Srwatson		return (error);
3069100979Srwatson
3070100979Srwatson	newcred = crget();
3071100979Srwatson
3072100979Srwatson	p = td->td_proc;
3073100979Srwatson	PROC_LOCK(p);
3074100979Srwatson	oldcred = p->p_ucred;
3075100979Srwatson
3076100979Srwatson	error = mac_check_cred_relabel(oldcred, &intlabel);
3077100979Srwatson	if (error) {
3078100979Srwatson		PROC_UNLOCK(p);
3079100979Srwatson		mac_destroy_temp(&intlabel);
3080100979Srwatson		crfree(newcred);
3081100979Srwatson		return (error);
3082100979Srwatson	}
3083100979Srwatson
3084100979Srwatson	setsugid(p);
3085100979Srwatson	crcopy(newcred, oldcred);
3086100979Srwatson	mac_relabel_cred(newcred, &intlabel);
3087102136Srwatson	p->p_ucred = newcred;
3088100979Srwatson
3089102136Srwatson	/*
3090102136Srwatson	 * Grab additional reference for use while revoking mmaps, prior
3091102136Srwatson	 * to releasing the proc lock and sharing the cred.
3092102136Srwatson	 */
3093102136Srwatson	crhold(newcred);
3094100979Srwatson	PROC_UNLOCK(p);
3095102136Srwatson
3096103135Srwatson	mtx_lock(&Giant);
3097102136Srwatson	mac_cred_mmapped_drop_perms(td, newcred);
3098103135Srwatson	mtx_unlock(&Giant);
3099102136Srwatson
3100102136Srwatson	crfree(newcred);	/* Free revocation reference. */
3101100979Srwatson	crfree(oldcred);
3102100979Srwatson	mac_destroy_temp(&intlabel);
3103100979Srwatson	return (0);
3104100979Srwatson}
3105100979Srwatson
3106100979Srwatson/*
3107100979Srwatson * MPSAFE
3108100979Srwatson */
3109100979Srwatsonint
3110100979Srwatson__mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap)
3111100979Srwatson{
3112100979Srwatson	struct file *fp;
3113100979Srwatson	struct mac extmac;
3114100979Srwatson	struct vnode *vp;
3115100979Srwatson	struct pipe *pipe;
3116100979Srwatson	int error;
3117100979Srwatson
3118100979Srwatson	mtx_lock(&Giant);
3119100979Srwatson
3120100979Srwatson	error = fget(td, SCARG(uap, fd), &fp);
3121100979Srwatson	if (error)
3122100979Srwatson		goto out;
3123100979Srwatson
3124100979Srwatson	switch (fp->f_type) {
3125100979Srwatson	case DTYPE_FIFO:
3126100979Srwatson	case DTYPE_VNODE:
3127100979Srwatson		vp = (struct vnode *)fp->f_data;
3128100979Srwatson
3129100979Srwatson		vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
3130100979Srwatson		error = vn_refreshlabel(vp, td->td_ucred);
3131100979Srwatson		if (error == 0)
3132100979Srwatson			error = mac_externalize(&vp->v_label, &extmac);
3133100979Srwatson		VOP_UNLOCK(vp, 0, td);
3134100979Srwatson		break;
3135100979Srwatson	case DTYPE_PIPE:
3136100979Srwatson		pipe = (struct pipe *)fp->f_data;
3137100979Srwatson		error = mac_externalize(pipe->pipe_label, &extmac);
3138100979Srwatson		break;
3139100979Srwatson	default:
3140100979Srwatson		error = EINVAL;
3141100979Srwatson	}
3142100979Srwatson
3143100979Srwatson	if (error == 0)
3144100979Srwatson		error = copyout(&extmac, SCARG(uap, mac_p), sizeof(extmac));
3145100979Srwatson
3146100979Srwatson	fdrop(fp, td);
3147100979Srwatson
3148100979Srwatsonout:
3149100979Srwatson	mtx_unlock(&Giant);
3150100979Srwatson	return (error);
3151100979Srwatson}
3152100979Srwatson
3153100979Srwatson/*
3154100979Srwatson * MPSAFE
3155100979Srwatson */
3156100979Srwatsonint
3157100979Srwatson__mac_get_file(struct thread *td, struct __mac_get_file_args *uap)
3158100979Srwatson{
3159100979Srwatson	struct nameidata nd;
3160100979Srwatson	struct mac extmac;
3161100979Srwatson	int error;
3162100979Srwatson
3163100979Srwatson	mtx_lock(&Giant);
3164100979Srwatson	NDINIT(&nd, LOOKUP, LOCKLEAF | FOLLOW, UIO_USERSPACE,
3165100979Srwatson	    SCARG(uap, path_p), td);
3166100979Srwatson	error = namei(&nd);
3167100979Srwatson	if (error)
3168100979Srwatson		goto out;
3169100979Srwatson
3170100979Srwatson	error = vn_refreshlabel(nd.ni_vp, td->td_ucred);
3171100979Srwatson	if (error == 0)
3172100979Srwatson		error = mac_externalize(&nd.ni_vp->v_label, &extmac);
3173100979Srwatson	NDFREE(&nd, 0);
3174100979Srwatson	if (error)
3175100979Srwatson		goto out;
3176100979Srwatson
3177100979Srwatson	error = copyout(&extmac, SCARG(uap, mac_p), sizeof(extmac));
3178100979Srwatson
3179100979Srwatsonout:
3180100979Srwatson	mtx_unlock(&Giant);
3181100979Srwatson	return (error);
3182100979Srwatson}
3183100979Srwatson
3184100979Srwatson/*
3185100979Srwatson * MPSAFE
3186100979Srwatson */
3187100979Srwatsonint
3188100979Srwatson__mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap)
3189100979Srwatson{
3190100979Srwatson	struct file *fp;
3191100979Srwatson	struct mac extmac;
3192100979Srwatson	struct label intlabel;
3193100979Srwatson	struct mount *mp;
3194100979Srwatson	struct vnode *vp;
3195100979Srwatson	struct pipe *pipe;
3196100979Srwatson	int error;
3197100979Srwatson
3198100979Srwatson	mtx_lock(&Giant);
3199100979Srwatson	error = fget(td, SCARG(uap, fd), &fp);
3200100979Srwatson	if (error)
3201100979Srwatson		goto out1;
3202100979Srwatson
3203100979Srwatson	error = copyin(SCARG(uap, mac_p), &extmac, sizeof(extmac));
3204100979Srwatson	if (error)
3205100979Srwatson		goto out2;
3206100979Srwatson
3207100979Srwatson	error = mac_internalize(&intlabel, &extmac);
3208100979Srwatson	if (error)
3209100979Srwatson		goto out2;
3210100979Srwatson
3211100979Srwatson	switch (fp->f_type) {
3212100979Srwatson	case DTYPE_FIFO:
3213100979Srwatson	case DTYPE_VNODE:
3214100979Srwatson		vp = (struct vnode *)fp->f_data;
3215100979Srwatson		error = vn_start_write(vp, &mp, V_WAIT | PCATCH);
3216100979Srwatson		if (error != 0)
3217100979Srwatson			break;
3218100979Srwatson
3219100979Srwatson		vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
3220100979Srwatson		error = vn_setlabel(vp, &intlabel, td->td_ucred);
3221100979Srwatson		VOP_UNLOCK(vp, 0, td);
3222100979Srwatson		vn_finished_write(mp);
3223100979Srwatson		mac_destroy_temp(&intlabel);
3224100979Srwatson		break;
3225100979Srwatson	case DTYPE_PIPE:
3226100979Srwatson		pipe = (struct pipe *)fp->f_data;
3227104269Srwatson		PIPE_LOCK(pipe);
3228100979Srwatson		error = mac_pipe_label_set(td->td_ucred, pipe, &intlabel);
3229104269Srwatson		PIPE_UNLOCK(pipe);
3230100979Srwatson		break;
3231100979Srwatson	default:
3232100979Srwatson		error = EINVAL;
3233100979Srwatson	}
3234100979Srwatson
3235100979Srwatsonout2:
3236100979Srwatson	fdrop(fp, td);
3237100979Srwatsonout1:
3238100979Srwatson	mtx_unlock(&Giant);
3239100979Srwatson	return (error);
3240100979Srwatson}
3241100979Srwatson
3242100979Srwatson/*
3243100979Srwatson * MPSAFE
3244100979Srwatson */
3245100979Srwatsonint
3246100979Srwatson__mac_set_file(struct thread *td, struct __mac_set_file_args *uap)
3247100979Srwatson{
3248100979Srwatson	struct nameidata nd;
3249100979Srwatson	struct mac extmac;
3250100979Srwatson	struct label intlabel;
3251100979Srwatson	struct mount *mp;
3252100979Srwatson	int error;
3253100979Srwatson
3254100979Srwatson	mtx_lock(&Giant);
3255100979Srwatson
3256100979Srwatson	error = copyin(SCARG(uap, mac_p), &extmac, sizeof(extmac));
3257100979Srwatson	if (error)
3258100979Srwatson		goto out;
3259100979Srwatson
3260100979Srwatson	error = mac_internalize(&intlabel, &extmac);
3261100979Srwatson	if (error)
3262100979Srwatson		goto out;
3263100979Srwatson
3264100979Srwatson	NDINIT(&nd, LOOKUP, LOCKLEAF | FOLLOW, UIO_USERSPACE,
3265100979Srwatson	    SCARG(uap, path_p), td);
3266100979Srwatson	error = namei(&nd);
3267100979Srwatson	if (error)
3268100979Srwatson		goto out2;
3269100979Srwatson	error = vn_start_write(nd.ni_vp, &mp, V_WAIT | PCATCH);
3270100979Srwatson	if (error)
3271100979Srwatson		goto out2;
3272100979Srwatson
3273100979Srwatson	error = vn_setlabel(nd.ni_vp, &intlabel, td->td_ucred);
3274100979Srwatson
3275100979Srwatson	vn_finished_write(mp);
3276100979Srwatsonout2:
3277100979Srwatson	mac_destroy_temp(&intlabel);
3278100979Srwatson	NDFREE(&nd, 0);
3279100979Srwatsonout:
3280100979Srwatson	mtx_unlock(&Giant);
3281100979Srwatson	return (error);
3282100979Srwatson}
3283100979Srwatson
3284102123Srwatsonint
3285102123Srwatsonmac_syscall(struct thread *td, struct mac_syscall_args *uap)
3286102123Srwatson{
3287102123Srwatson	struct mac_policy_conf *mpc;
3288102123Srwatson	char target[MAC_MAX_POLICY_NAME];
3289102123Srwatson	int error;
3290102123Srwatson
3291102123Srwatson	error = copyinstr(SCARG(uap, policy), target, sizeof(target), NULL);
3292102123Srwatson	if (error)
3293102123Srwatson		return (error);
3294102123Srwatson
3295102123Srwatson	error = ENOSYS;
3296102123Srwatson	MAC_POLICY_LIST_BUSY();
3297102123Srwatson	LIST_FOREACH(mpc, &mac_policy_list, mpc_list) {
3298102123Srwatson		if (strcmp(mpc->mpc_name, target) == 0 &&
3299102123Srwatson		    mpc->mpc_ops->mpo_syscall != NULL) {
3300102123Srwatson			error = mpc->mpc_ops->mpo_syscall(td,
3301102123Srwatson			    SCARG(uap, call), SCARG(uap, arg));
3302102123Srwatson			goto out;
3303102123Srwatson		}
3304102123Srwatson	}
3305102123Srwatson
3306102123Srwatsonout:
3307102123Srwatson	MAC_POLICY_LIST_UNBUSY();
3308102123Srwatson	return (error);
3309102123Srwatson}
3310102123Srwatson
3311100979SrwatsonSYSINIT(mac, SI_SUB_MAC, SI_ORDER_FIRST, mac_init, NULL);
3312100979SrwatsonSYSINIT(mac_late, SI_SUB_MAC_LATE, SI_ORDER_FIRST, mac_late_init, NULL);
3313100979Srwatson
3314100979Srwatson#else /* !MAC */
3315100979Srwatson
3316100979Srwatsonint
3317100979Srwatson__mac_get_proc(struct thread *td, struct __mac_get_proc_args *uap)
3318100979Srwatson{
3319100979Srwatson
3320100894Srwatson	return (ENOSYS);
3321100894Srwatson}
3322100894Srwatson
3323100894Srwatsonint
3324100894Srwatson__mac_set_proc(struct thread *td, struct __mac_set_proc_args *uap)
3325100894Srwatson{
3326100894Srwatson
3327100894Srwatson	return (ENOSYS);
3328100894Srwatson}
3329100894Srwatson
3330100894Srwatsonint
3331100894Srwatson__mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap)
3332100894Srwatson{
3333100894Srwatson
3334100894Srwatson	return (ENOSYS);
3335100894Srwatson}
3336100894Srwatson
3337100894Srwatsonint
3338100894Srwatson__mac_get_file(struct thread *td, struct __mac_get_file_args *uap)
3339100894Srwatson{
3340100894Srwatson
3341100894Srwatson	return (ENOSYS);
3342100894Srwatson}
3343100894Srwatson
3344100894Srwatsonint
3345100894Srwatson__mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap)
3346100894Srwatson{
3347100894Srwatson
3348100894Srwatson	return (ENOSYS);
3349100894Srwatson}
3350100894Srwatson
3351100894Srwatsonint
3352100894Srwatson__mac_set_file(struct thread *td, struct __mac_set_file_args *uap)
3353100894Srwatson{
3354100894Srwatson
3355100894Srwatson	return (ENOSYS);
3356100894Srwatson}
3357100979Srwatson
3358102123Srwatsonint
3359102123Srwatsonmac_syscall(struct thread *td, struct mac_syscall_args *uap)
3360102123Srwatson{
3361102123Srwatson
3362102123Srwatson	return (ENOSYS);
3363102123Srwatson}
3364102123Srwatson
3365100979Srwatson#endif /* !MAC */
3366