mac_biba.c revision 106160
1101099Srwatson/*-
2101099Srwatson * Copyright (c) 1999, 2000, 2001, 2002 Robert N. M. Watson
3101099Srwatson * Copyright (c) 2001, 2002 Networks Associates Technology, Inc.
4101099Srwatson * All rights reserved.
5101099Srwatson *
6101099Srwatson * This software was developed by Robert Watson for the TrustedBSD Project.
7101099Srwatson *
8101099Srwatson * This software was developed for the FreeBSD Project in part by NAI Labs,
9101099Srwatson * the Security Research Division of Network Associates, Inc. under
10101099Srwatson * DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA
11101099Srwatson * CHATS research program.
12101099Srwatson *
13101099Srwatson * Redistribution and use in source and binary forms, with or without
14101099Srwatson * modification, are permitted provided that the following conditions
15101099Srwatson * are met:
16101099Srwatson * 1. Redistributions of source code must retain the above copyright
17101099Srwatson *    notice, this list of conditions and the following disclaimer.
18101099Srwatson * 2. Redistributions in binary form must reproduce the above copyright
19101099Srwatson *    notice, this list of conditions and the following disclaimer in the
20101099Srwatson *    documentation and/or other materials provided with the distribution.
21101099Srwatson * 3. The names of the authors may not be used to endorse or promote
22101099Srwatson *    products derived from this software without specific prior written
23101099Srwatson *    permission.
24101099Srwatson *
25101099Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
26101099Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27101099Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28101099Srwatson * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
29101099Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30101099Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31101099Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32101099Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33101099Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34101099Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35101099Srwatson * SUCH DAMAGE.
36101099Srwatson *
37101099Srwatson * $FreeBSD: head/sys/security/mac_biba/mac_biba.c 106160 2002-10-29 19:14:16Z rwatson $
38101099Srwatson */
39101099Srwatson
40101099Srwatson/*
41101099Srwatson * Developed by the TrustedBSD Project.
42101099Srwatson * Biba fixed label mandatory integrity policy.
43101099Srwatson */
44101099Srwatson
45101099Srwatson#include <sys/types.h>
46101099Srwatson#include <sys/param.h>
47101099Srwatson#include <sys/acl.h>
48101099Srwatson#include <sys/conf.h>
49105988Srwatson#include <sys/extattr.h>
50101099Srwatson#include <sys/kernel.h>
51101099Srwatson#include <sys/mac.h>
52103183Sbde#include <sys/malloc.h>
53101099Srwatson#include <sys/mount.h>
54101099Srwatson#include <sys/proc.h>
55101099Srwatson#include <sys/systm.h>
56101099Srwatson#include <sys/sysproto.h>
57101099Srwatson#include <sys/sysent.h>
58105696Srwatson#include <sys/systm.h>
59101099Srwatson#include <sys/vnode.h>
60101099Srwatson#include <sys/file.h>
61101099Srwatson#include <sys/socket.h>
62101099Srwatson#include <sys/socketvar.h>
63101099Srwatson#include <sys/pipe.h>
64101099Srwatson#include <sys/sysctl.h>
65101099Srwatson
66101099Srwatson#include <fs/devfs/devfs.h>
67101099Srwatson
68101099Srwatson#include <net/bpfdesc.h>
69101099Srwatson#include <net/if.h>
70101099Srwatson#include <net/if_types.h>
71101099Srwatson#include <net/if_var.h>
72101099Srwatson
73101099Srwatson#include <netinet/in.h>
74101099Srwatson#include <netinet/ip_var.h>
75101099Srwatson
76101099Srwatson#include <vm/vm.h>
77101099Srwatson
78101099Srwatson#include <sys/mac_policy.h>
79101099Srwatson
80101099Srwatson#include <security/mac_biba/mac_biba.h>
81101099Srwatson
82101099SrwatsonSYSCTL_DECL(_security_mac);
83101099Srwatson
84101099SrwatsonSYSCTL_NODE(_security_mac, OID_AUTO, biba, CTLFLAG_RW, 0,
85101099Srwatson    "TrustedBSD mac_biba policy controls");
86101099Srwatson
87105988Srwatsonstatic int	mac_biba_label_size = sizeof(struct mac_biba);
88105988SrwatsonSYSCTL_INT(_security_mac_biba, OID_AUTO, label_size, CTLFLAG_RD,
89105988Srwatson    &mac_biba_label_size, 0, "Size of struct mac_biba");
90105988Srwatson
91101099Srwatsonstatic int	mac_biba_enabled = 0;
92101099SrwatsonSYSCTL_INT(_security_mac_biba, OID_AUTO, enabled, CTLFLAG_RW,
93101099Srwatson    &mac_biba_enabled, 0, "Enforce MAC/Biba policy");
94102980SrwatsonTUNABLE_INT("security.mac.biba.enabled", &mac_biba_enabled);
95101099Srwatson
96101099Srwatsonstatic int	destroyed_not_inited;
97101099SrwatsonSYSCTL_INT(_security_mac_biba, OID_AUTO, destroyed_not_inited, CTLFLAG_RD,
98101099Srwatson    &destroyed_not_inited, 0, "Count of labels destroyed but not inited");
99101099Srwatson
100101099Srwatsonstatic int	trust_all_interfaces = 0;
101101099SrwatsonSYSCTL_INT(_security_mac_biba, OID_AUTO, trust_all_interfaces, CTLFLAG_RD,
102101099Srwatson    &trust_all_interfaces, 0, "Consider all interfaces 'trusted' by MAC/Biba");
103101099SrwatsonTUNABLE_INT("security.mac.biba.trust_all_interfaces", &trust_all_interfaces);
104101099Srwatson
105101099Srwatsonstatic char	trusted_interfaces[128];
106101099SrwatsonSYSCTL_STRING(_security_mac_biba, OID_AUTO, trusted_interfaces, CTLFLAG_RD,
107101099Srwatson    trusted_interfaces, 0, "Interfaces considered 'trusted' by MAC/Biba");
108101099SrwatsonTUNABLE_STR("security.mac.biba.trusted_interfaces", trusted_interfaces,
109101099Srwatson    sizeof(trusted_interfaces));
110101099Srwatson
111105643Srwatsonstatic int	max_compartments = MAC_BIBA_MAX_COMPARTMENTS;
112105643SrwatsonSYSCTL_INT(_security_mac_biba, OID_AUTO, max_compartments, CTLFLAG_RD,
113105643Srwatson    &max_compartments, 0, "Maximum supported compartments");
114105643Srwatson
115105606Srwatsonstatic int	ptys_equal = 0;
116105606SrwatsonSYSCTL_INT(_security_mac_biba, OID_AUTO, ptys_equal, CTLFLAG_RW,
117105606Srwatson    &ptys_equal, 0, "Label pty devices as biba/equal on create");
118105606SrwatsonTUNABLE_INT("security.mac.biba.ptys_equal", &ptys_equal);
119105606Srwatson
120105637Srwatsonstatic int	revocation_enabled = 0;
121101099SrwatsonSYSCTL_INT(_security_mac_biba, OID_AUTO, revocation_enabled, CTLFLAG_RW,
122105637Srwatson    &revocation_enabled, 0, "Revoke access to objects on relabel");
123105637SrwatsonTUNABLE_INT("security.mac.biba.revocation_enabled", &revocation_enabled);
124101099Srwatson
125101099Srwatsonstatic int	mac_biba_slot;
126101099Srwatson#define	SLOT(l)	((struct mac_biba *)LABEL_TO_SLOT((l), mac_biba_slot).l_ptr)
127101099Srwatson
128101099SrwatsonMALLOC_DEFINE(M_MACBIBA, "biba label", "MAC/Biba labels");
129101099Srwatson
130105643Srwatsonstatic __inline int
131105643Srwatsonbiba_bit_set_empty(u_char *set) {
132105643Srwatson	int i;
133105643Srwatson
134105643Srwatson	for (i = 0; i < MAC_BIBA_MAX_COMPARTMENTS >> 3; i++)
135105643Srwatson		if (set[i] != 0)
136105643Srwatson			return (0);
137105643Srwatson	return (1);
138105643Srwatson}
139105643Srwatson
140101099Srwatsonstatic struct mac_biba *
141104514Srwatsonbiba_alloc(int flag)
142101099Srwatson{
143101099Srwatson	struct mac_biba *mac_biba;
144101099Srwatson
145104514Srwatson	mac_biba = malloc(sizeof(struct mac_biba), M_MACBIBA, M_ZERO | flag);
146101099Srwatson
147101099Srwatson	return (mac_biba);
148101099Srwatson}
149101099Srwatson
150101099Srwatsonstatic void
151101099Srwatsonbiba_free(struct mac_biba *mac_biba)
152101099Srwatson{
153101099Srwatson
154101099Srwatson	if (mac_biba != NULL)
155101099Srwatson		free(mac_biba, M_MACBIBA);
156101099Srwatson	else
157101099Srwatson		atomic_add_int(&destroyed_not_inited, 1);
158101099Srwatson}
159101099Srwatson
160101099Srwatsonstatic int
161105634Srwatsonbiba_atmostflags(struct mac_biba *mac_biba, int flags)
162105634Srwatson{
163105634Srwatson
164105634Srwatson	if ((mac_biba->mb_flags & flags) != mac_biba->mb_flags)
165105634Srwatson		return (EINVAL);
166105634Srwatson	return (0);
167105634Srwatson}
168105634Srwatson
169105634Srwatsonstatic int
170101099Srwatsonmac_biba_dominate_element(struct mac_biba_element *a,
171101099Srwatson    struct mac_biba_element *b)
172101099Srwatson{
173105643Srwatson	int bit;
174101099Srwatson
175105736Srwatson	switch (a->mbe_type) {
176101099Srwatson	case MAC_BIBA_TYPE_EQUAL:
177101099Srwatson	case MAC_BIBA_TYPE_HIGH:
178101099Srwatson		return (1);
179101099Srwatson
180101099Srwatson	case MAC_BIBA_TYPE_LOW:
181101099Srwatson		switch (b->mbe_type) {
182101099Srwatson		case MAC_BIBA_TYPE_GRADE:
183101099Srwatson		case MAC_BIBA_TYPE_HIGH:
184101099Srwatson			return (0);
185101099Srwatson
186101099Srwatson		case MAC_BIBA_TYPE_EQUAL:
187101099Srwatson		case MAC_BIBA_TYPE_LOW:
188101099Srwatson			return (1);
189101099Srwatson
190101099Srwatson		default:
191101099Srwatson			panic("mac_biba_dominate_element: b->mbe_type invalid");
192101099Srwatson		}
193101099Srwatson
194101099Srwatson	case MAC_BIBA_TYPE_GRADE:
195101099Srwatson		switch (b->mbe_type) {
196101099Srwatson		case MAC_BIBA_TYPE_EQUAL:
197101099Srwatson		case MAC_BIBA_TYPE_LOW:
198101099Srwatson			return (1);
199101099Srwatson
200101099Srwatson		case MAC_BIBA_TYPE_HIGH:
201101099Srwatson			return (0);
202101099Srwatson
203101099Srwatson		case MAC_BIBA_TYPE_GRADE:
204105643Srwatson			for (bit = 1; bit <= MAC_BIBA_MAX_COMPARTMENTS; bit++)
205105643Srwatson				if (!MAC_BIBA_BIT_TEST(bit,
206105643Srwatson				    a->mbe_compartments) &&
207105643Srwatson				    MAC_BIBA_BIT_TEST(bit, b->mbe_compartments))
208105643Srwatson					return (0);
209101099Srwatson			return (a->mbe_grade >= b->mbe_grade);
210101099Srwatson
211101099Srwatson		default:
212101099Srwatson			panic("mac_biba_dominate_element: b->mbe_type invalid");
213101099Srwatson		}
214101099Srwatson
215101099Srwatson	default:
216101099Srwatson		panic("mac_biba_dominate_element: a->mbe_type invalid");
217101099Srwatson	}
218101099Srwatson
219101099Srwatson	return (0);
220101099Srwatson}
221101099Srwatson
222101099Srwatsonstatic int
223105988Srwatsonmac_biba_subject_dominate_high(struct mac_biba *mac_biba)
224105988Srwatson{
225105988Srwatson	struct mac_biba_element *element;
226105988Srwatson
227105988Srwatson	KASSERT((mac_biba->mb_single->mb_flags & MAC_BIBA_FLAG_SINGLE) != 0,
228105988Srwatson	    ("mac_biba_single_in_range: mac_biba not single"));
229105988Srwatson	element = &mac_biba->mb_single;
230105988Srwatson
231105988Srwatson	return (element->mbe_type == MAC_BIBA_TYPE_EQUAL ||
232105988Srwatson	    element->mbe_type == MAC_BIBA_TYPE_HIGH);
233105988Srwatson}
234105988Srwatson
235105988Srwatsonstatic int
236101099Srwatsonmac_biba_range_in_range(struct mac_biba *rangea, struct mac_biba *rangeb)
237101099Srwatson{
238101099Srwatson
239101099Srwatson	return (mac_biba_dominate_element(&rangeb->mb_rangehigh,
240101099Srwatson	    &rangea->mb_rangehigh) &&
241101099Srwatson	    mac_biba_dominate_element(&rangea->mb_rangelow,
242101099Srwatson	    &rangeb->mb_rangelow));
243101099Srwatson}
244101099Srwatson
245101099Srwatsonstatic int
246101099Srwatsonmac_biba_single_in_range(struct mac_biba *single, struct mac_biba *range)
247101099Srwatson{
248101099Srwatson
249103750Srwatson	KASSERT((single->mb_flags & MAC_BIBA_FLAG_SINGLE) != 0,
250101099Srwatson	    ("mac_biba_single_in_range: a not single"));
251103750Srwatson	KASSERT((range->mb_flags & MAC_BIBA_FLAG_RANGE) != 0,
252101099Srwatson	    ("mac_biba_single_in_range: b not range"));
253101099Srwatson
254101099Srwatson	return (mac_biba_dominate_element(&range->mb_rangehigh,
255101099Srwatson	    &single->mb_single) &&
256101099Srwatson	    mac_biba_dominate_element(&single->mb_single,
257101099Srwatson	    &range->mb_rangelow));
258101099Srwatson
259101099Srwatson	return (1);
260101099Srwatson}
261101099Srwatson
262101099Srwatsonstatic int
263101099Srwatsonmac_biba_dominate_single(struct mac_biba *a, struct mac_biba *b)
264101099Srwatson{
265101099Srwatson	KASSERT((a->mb_flags & MAC_BIBA_FLAG_SINGLE) != 0,
266101099Srwatson	    ("mac_biba_dominate_single: a not single"));
267101099Srwatson	KASSERT((b->mb_flags & MAC_BIBA_FLAG_SINGLE) != 0,
268101099Srwatson	    ("mac_biba_dominate_single: b not single"));
269101099Srwatson
270101099Srwatson	return (mac_biba_dominate_element(&a->mb_single, &b->mb_single));
271101099Srwatson}
272101099Srwatson
273101099Srwatsonstatic int
274101099Srwatsonmac_biba_equal_element(struct mac_biba_element *a, struct mac_biba_element *b)
275101099Srwatson{
276101099Srwatson
277101099Srwatson	if (a->mbe_type == MAC_BIBA_TYPE_EQUAL ||
278101099Srwatson	    b->mbe_type == MAC_BIBA_TYPE_EQUAL)
279101099Srwatson		return (1);
280101099Srwatson
281101099Srwatson	return (a->mbe_type == b->mbe_type && a->mbe_grade == b->mbe_grade);
282101099Srwatson}
283101099Srwatson
284101099Srwatsonstatic int
285101099Srwatsonmac_biba_equal_single(struct mac_biba *a, struct mac_biba *b)
286101099Srwatson{
287101099Srwatson
288101099Srwatson	KASSERT((a->mb_flags & MAC_BIBA_FLAG_SINGLE) != 0,
289101099Srwatson	    ("mac_biba_equal_single: a not single"));
290101099Srwatson	KASSERT((b->mb_flags & MAC_BIBA_FLAG_SINGLE) != 0,
291101099Srwatson	    ("mac_biba_equal_single: b not single"));
292101099Srwatson
293101099Srwatson	return (mac_biba_equal_element(&a->mb_single, &b->mb_single));
294101099Srwatson}
295101099Srwatson
296101099Srwatsonstatic int
297105634Srwatsonmac_biba_contains_equal(struct mac_biba *mac_biba)
298105634Srwatson{
299105634Srwatson
300105634Srwatson	if (mac_biba->mb_flags & MAC_BIBA_FLAG_SINGLE)
301105634Srwatson		if (mac_biba->mb_single.mbe_type == MAC_BIBA_TYPE_EQUAL)
302105634Srwatson			return (1);
303105634Srwatson
304105634Srwatson	if (mac_biba->mb_flags & MAC_BIBA_FLAG_RANGE) {
305105634Srwatson		if (mac_biba->mb_rangelow.mbe_type == MAC_BIBA_TYPE_EQUAL)
306105634Srwatson			return (1);
307105634Srwatson		if (mac_biba->mb_rangehigh.mbe_type == MAC_BIBA_TYPE_EQUAL)
308105637Srwatson			return (1);
309105634Srwatson	}
310105634Srwatson
311105634Srwatson	return (0);
312105634Srwatson}
313105634Srwatson
314105634Srwatsonstatic int
315106090Srwatsonmac_biba_subject_privileged(struct mac_biba *mac_biba)
316105634Srwatson{
317105634Srwatson
318105634Srwatson	KASSERT((mac_biba->mb_flags & MAC_BIBA_FLAGS_BOTH) ==
319105634Srwatson	    MAC_BIBA_FLAGS_BOTH,
320106090Srwatson	    ("mac_biba_subject_privileged: subject doesn't have both labels"));
321105634Srwatson
322105634Srwatson	/* If the single is EQUAL, it's ok. */
323105634Srwatson	if (mac_biba->mb_single.mbe_type == MAC_BIBA_TYPE_EQUAL)
324105634Srwatson		return (0);
325105634Srwatson
326105634Srwatson	/* If either range endpoint is EQUAL, it's ok. */
327105634Srwatson	if (mac_biba->mb_rangelow.mbe_type == MAC_BIBA_TYPE_EQUAL ||
328105634Srwatson	    mac_biba->mb_rangehigh.mbe_type == MAC_BIBA_TYPE_EQUAL)
329105634Srwatson		return (0);
330105634Srwatson
331105634Srwatson	/* If the range is low-high, it's ok. */
332105634Srwatson	if (mac_biba->mb_rangelow.mbe_type == MAC_BIBA_TYPE_LOW &&
333105634Srwatson	    mac_biba->mb_rangehigh.mbe_type == MAC_BIBA_TYPE_HIGH)
334105634Srwatson		return (0);
335105634Srwatson
336105634Srwatson	/* It's not ok. */
337105634Srwatson	return (EPERM);
338105634Srwatson}
339105634Srwatson
340106091Srwatsonstatic int
341105988Srwatsonmac_biba_high_single(struct mac_biba *mac_biba)
342105988Srwatson{
343105988Srwatson
344105988Srwatson	KASSERT((mac_biba->mb_flags & MAC_BIBA_FLAG_SINGLE) != 0,
345105988Srwatson	    ("mac_biba_equal_single: mac_biba not single"));
346105988Srwatson
347105988Srwatson	return (mac_biba->mb_single.mbe_type == MAC_BIBA_TYPE_HIGH);
348105988Srwatson}
349105988Srwatson
350105634Srwatsonstatic int
351101099Srwatsonmac_biba_valid(struct mac_biba *mac_biba)
352101099Srwatson{
353101099Srwatson
354101099Srwatson	if (mac_biba->mb_flags & MAC_BIBA_FLAG_SINGLE) {
355101099Srwatson		switch (mac_biba->mb_single.mbe_type) {
356101099Srwatson		case MAC_BIBA_TYPE_GRADE:
357101099Srwatson			break;
358101099Srwatson
359101099Srwatson		case MAC_BIBA_TYPE_EQUAL:
360101099Srwatson		case MAC_BIBA_TYPE_HIGH:
361101099Srwatson		case MAC_BIBA_TYPE_LOW:
362105643Srwatson			if (mac_biba->mb_single.mbe_grade != 0 ||
363105643Srwatson			    !MAC_BIBA_BIT_SET_EMPTY(
364105643Srwatson			    mac_biba->mb_single.mbe_compartments))
365101099Srwatson				return (EINVAL);
366101099Srwatson			break;
367101099Srwatson
368101099Srwatson		default:
369101099Srwatson			return (EINVAL);
370101099Srwatson		}
371101099Srwatson	} else {
372101099Srwatson		if (mac_biba->mb_single.mbe_type != MAC_BIBA_TYPE_UNDEF)
373101099Srwatson			return (EINVAL);
374101099Srwatson	}
375101099Srwatson
376101099Srwatson	if (mac_biba->mb_flags & MAC_BIBA_FLAG_RANGE) {
377101099Srwatson		switch (mac_biba->mb_rangelow.mbe_type) {
378101099Srwatson		case MAC_BIBA_TYPE_GRADE:
379101099Srwatson			break;
380101099Srwatson
381101099Srwatson		case MAC_BIBA_TYPE_EQUAL:
382101099Srwatson		case MAC_BIBA_TYPE_HIGH:
383101099Srwatson		case MAC_BIBA_TYPE_LOW:
384105643Srwatson			if (mac_biba->mb_rangelow.mbe_grade != 0 ||
385105643Srwatson			    !MAC_BIBA_BIT_SET_EMPTY(
386105643Srwatson			    mac_biba->mb_rangelow.mbe_compartments))
387101099Srwatson				return (EINVAL);
388101099Srwatson			break;
389101099Srwatson
390101099Srwatson		default:
391101099Srwatson			return (EINVAL);
392101099Srwatson		}
393101099Srwatson
394101099Srwatson		switch (mac_biba->mb_rangehigh.mbe_type) {
395101099Srwatson		case MAC_BIBA_TYPE_GRADE:
396101099Srwatson			break;
397101099Srwatson
398101099Srwatson		case MAC_BIBA_TYPE_EQUAL:
399101099Srwatson		case MAC_BIBA_TYPE_HIGH:
400101099Srwatson		case MAC_BIBA_TYPE_LOW:
401105643Srwatson			if (mac_biba->mb_rangehigh.mbe_grade != 0 ||
402105643Srwatson			    !MAC_BIBA_BIT_SET_EMPTY(
403105643Srwatson			    mac_biba->mb_rangehigh.mbe_compartments))
404101099Srwatson				return (EINVAL);
405101099Srwatson			break;
406101099Srwatson
407101099Srwatson		default:
408101099Srwatson			return (EINVAL);
409101099Srwatson		}
410101099Srwatson		if (!mac_biba_dominate_element(&mac_biba->mb_rangehigh,
411101099Srwatson		    &mac_biba->mb_rangelow))
412101099Srwatson			return (EINVAL);
413101099Srwatson	} else {
414101099Srwatson		if (mac_biba->mb_rangelow.mbe_type != MAC_BIBA_TYPE_UNDEF ||
415101099Srwatson		    mac_biba->mb_rangehigh.mbe_type != MAC_BIBA_TYPE_UNDEF)
416101099Srwatson			return (EINVAL);
417101099Srwatson	}
418101099Srwatson
419101099Srwatson	return (0);
420101099Srwatson}
421101099Srwatson
422101099Srwatsonstatic void
423101099Srwatsonmac_biba_set_range(struct mac_biba *mac_biba, u_short typelow,
424105643Srwatson    u_short gradelow, u_char *compartmentslow, u_short typehigh,
425105643Srwatson    u_short gradehigh, u_char *compartmentshigh)
426101099Srwatson{
427101099Srwatson
428101099Srwatson	mac_biba->mb_rangelow.mbe_type = typelow;
429101099Srwatson	mac_biba->mb_rangelow.mbe_grade = gradelow;
430105643Srwatson	if (compartmentslow != NULL)
431105643Srwatson		memcpy(mac_biba->mb_rangelow.mbe_compartments,
432105643Srwatson		    compartmentslow,
433105643Srwatson		    sizeof(mac_biba->mb_rangelow.mbe_compartments));
434101099Srwatson	mac_biba->mb_rangehigh.mbe_type = typehigh;
435101099Srwatson	mac_biba->mb_rangehigh.mbe_grade = gradehigh;
436105643Srwatson	if (compartmentshigh != NULL)
437105643Srwatson		memcpy(mac_biba->mb_rangehigh.mbe_compartments,
438105643Srwatson		    compartmentshigh,
439105643Srwatson		    sizeof(mac_biba->mb_rangehigh.mbe_compartments));
440101099Srwatson	mac_biba->mb_flags |= MAC_BIBA_FLAG_RANGE;
441101099Srwatson}
442101099Srwatson
443101099Srwatsonstatic void
444105643Srwatsonmac_biba_set_single(struct mac_biba *mac_biba, u_short type, u_short grade,
445105643Srwatson    u_char *compartments)
446101099Srwatson{
447101099Srwatson
448101099Srwatson	mac_biba->mb_single.mbe_type = type;
449101099Srwatson	mac_biba->mb_single.mbe_grade = grade;
450105643Srwatson	if (compartments != NULL)
451105643Srwatson		memcpy(mac_biba->mb_single.mbe_compartments, compartments,
452105643Srwatson		    sizeof(mac_biba->mb_single.mbe_compartments));
453101099Srwatson	mac_biba->mb_flags |= MAC_BIBA_FLAG_SINGLE;
454101099Srwatson}
455101099Srwatson
456101099Srwatsonstatic void
457101099Srwatsonmac_biba_copy_range(struct mac_biba *labelfrom, struct mac_biba *labelto)
458101099Srwatson{
459105643Srwatson
460101099Srwatson	KASSERT((labelfrom->mb_flags & MAC_BIBA_FLAG_RANGE) != 0,
461101099Srwatson	    ("mac_biba_copy_range: labelfrom not range"));
462101099Srwatson
463101099Srwatson	labelto->mb_rangelow = labelfrom->mb_rangelow;
464101099Srwatson	labelto->mb_rangehigh = labelfrom->mb_rangehigh;
465101099Srwatson	labelto->mb_flags |= MAC_BIBA_FLAG_RANGE;
466101099Srwatson}
467101099Srwatson
468101099Srwatsonstatic void
469101099Srwatsonmac_biba_copy_single(struct mac_biba *labelfrom, struct mac_biba *labelto)
470101099Srwatson{
471101099Srwatson
472101099Srwatson	KASSERT((labelfrom->mb_flags & MAC_BIBA_FLAG_SINGLE) != 0,
473101099Srwatson	    ("mac_biba_copy_single: labelfrom not single"));
474101099Srwatson
475101099Srwatson	labelto->mb_single = labelfrom->mb_single;
476101099Srwatson	labelto->mb_flags |= MAC_BIBA_FLAG_SINGLE;
477101099Srwatson}
478101099Srwatson
479105656Srwatsonstatic void
480105656Srwatsonmac_biba_copy(struct mac_biba *source, struct mac_biba *dest)
481105656Srwatson{
482105656Srwatson
483105656Srwatson	if (source->mb_flags & MAC_BIBA_FLAG_SINGLE)
484105656Srwatson		mac_biba_copy_single(source, dest);
485105656Srwatson	if (source->mb_flags & MAC_BIBA_FLAG_RANGE)
486105656Srwatson		mac_biba_copy_range(source, dest);
487105656Srwatson}
488105656Srwatson
489101099Srwatson/*
490101099Srwatson * Policy module operations.
491101099Srwatson */
492101099Srwatsonstatic void
493101099Srwatsonmac_biba_destroy(struct mac_policy_conf *conf)
494101099Srwatson{
495101099Srwatson
496101099Srwatson}
497101099Srwatson
498101099Srwatsonstatic void
499101099Srwatsonmac_biba_init(struct mac_policy_conf *conf)
500101099Srwatson{
501101099Srwatson
502101099Srwatson}
503101099Srwatson
504101099Srwatson/*
505101099Srwatson * Label operations.
506101099Srwatson */
507101099Srwatsonstatic void
508104514Srwatsonmac_biba_init_label(struct label *label)
509101099Srwatson{
510101099Srwatson
511101099Srwatson	SLOT(label) = biba_alloc(M_WAITOK);
512101099Srwatson}
513101099Srwatson
514101099Srwatsonstatic int
515104514Srwatsonmac_biba_init_label_waitcheck(struct label *label, int flag)
516101099Srwatson{
517101099Srwatson
518104514Srwatson	SLOT(label) = biba_alloc(flag);
519101099Srwatson	if (SLOT(label) == NULL)
520101099Srwatson		return (ENOMEM);
521101099Srwatson
522101099Srwatson	return (0);
523101099Srwatson}
524101099Srwatson
525101099Srwatsonstatic void
526104514Srwatsonmac_biba_destroy_label(struct label *label)
527101099Srwatson{
528101099Srwatson
529101099Srwatson	biba_free(SLOT(label));
530101099Srwatson	SLOT(label) = NULL;
531101099Srwatson}
532101099Srwatson
533105696Srwatson/*
534105696Srwatson * mac_biba_element_to_string() is basically an snprintf wrapper with
535105696Srwatson * the same properties as snprintf().  It returns the length it would
536105696Srwatson * have added to the string in the event the string is too short.
537105696Srwatson */
538105696Srwatsonstatic size_t
539105696Srwatsonmac_biba_element_to_string(char *string, size_t size,
540105696Srwatson    struct mac_biba_element *element)
541105696Srwatson{
542105696Srwatson	int pos, bit = 1;
543105696Srwatson
544105696Srwatson	switch (element->mbe_type) {
545105696Srwatson	case MAC_BIBA_TYPE_HIGH:
546105696Srwatson		return (snprintf(string, size, "high"));
547105696Srwatson
548105696Srwatson	case MAC_BIBA_TYPE_LOW:
549105696Srwatson		return (snprintf(string, size, "low"));
550105696Srwatson
551105696Srwatson	case MAC_BIBA_TYPE_EQUAL:
552105696Srwatson		return (snprintf(string, size, "equal"));
553105696Srwatson
554105696Srwatson	case MAC_BIBA_TYPE_GRADE:
555105696Srwatson		pos = snprintf(string, size, "%d:", element->mbe_grade);
556105696Srwatson		for (bit = 1; bit <= MAC_BIBA_MAX_COMPARTMENTS; bit++) {
557105696Srwatson			if (MAC_BIBA_BIT_TEST(bit, element->mbe_compartments))
558105696Srwatson				pos += snprintf(string + pos, size - pos,
559105696Srwatson				    "%d+", bit);
560105696Srwatson		}
561105696Srwatson		if (string[pos - 1] == '+' || string[pos - 1] == ':')
562105696Srwatson			string[--pos] = NULL;
563105696Srwatson		return (pos);
564105696Srwatson
565105696Srwatson	default:
566105696Srwatson		panic("mac_biba_element_to_string: invalid type (%d)",
567105696Srwatson		    element->mbe_type);
568105696Srwatson	}
569105696Srwatson}
570105696Srwatson
571101099Srwatsonstatic int
572105696Srwatsonmac_biba_to_string(char *string, size_t size, size_t *caller_len,
573105696Srwatson    struct mac_biba *mac_biba)
574101099Srwatson{
575105696Srwatson	size_t left, len;
576105696Srwatson	char *curptr;
577105696Srwatson
578105696Srwatson	bzero(string, size);
579105696Srwatson	curptr = string;
580105696Srwatson	left = size;
581105696Srwatson
582105696Srwatson	if (mac_biba->mb_flags & MAC_BIBA_FLAG_SINGLE) {
583105696Srwatson		len = mac_biba_element_to_string(curptr, left,
584105696Srwatson		    &mac_biba->mb_single);
585105696Srwatson		if (len >= left)
586105696Srwatson			return (EINVAL);
587105696Srwatson		left -= len;
588105696Srwatson		curptr += len;
589105696Srwatson	}
590105696Srwatson
591105696Srwatson	if (mac_biba->mb_flags & MAC_BIBA_FLAG_RANGE) {
592105696Srwatson		len = snprintf(curptr, left, "(");
593105696Srwatson		if (len >= left)
594105696Srwatson			return (EINVAL);
595105696Srwatson		left -= len;
596105696Srwatson		curptr += len;
597105696Srwatson
598105696Srwatson		len = mac_biba_element_to_string(curptr, left,
599105696Srwatson		    &mac_biba->mb_rangelow);
600105696Srwatson		if (len >= left)
601105696Srwatson			return (EINVAL);
602105696Srwatson		left -= len;
603105696Srwatson		curptr += len;
604105696Srwatson
605105696Srwatson		len = snprintf(curptr, left, "-");
606105696Srwatson		if (len >= left)
607105696Srwatson			return (EINVAL);
608105696Srwatson		left -= len;
609105696Srwatson		curptr += len;
610105696Srwatson
611105696Srwatson		len = mac_biba_element_to_string(curptr, left,
612105696Srwatson		    &mac_biba->mb_rangehigh);
613105696Srwatson		if (len >= left)
614105696Srwatson			return (EINVAL);
615105696Srwatson		left -= len;
616105696Srwatson		curptr += len;
617105696Srwatson
618105696Srwatson		len = snprintf(curptr, left, ")");
619105696Srwatson		if (len >= left)
620105696Srwatson			return (EINVAL);
621105696Srwatson		left -= len;
622105696Srwatson		curptr += len;
623105696Srwatson	}
624105696Srwatson
625105696Srwatson	*caller_len = strlen(string);
626105696Srwatson	return (0);
627105696Srwatson}
628105696Srwatson
629105696Srwatsonstatic int
630105696Srwatsonmac_biba_externalize_label(struct label *label, char *element_name,
631105696Srwatson    char *element_data, size_t size, size_t *len, int *claimed)
632105696Srwatson{
633101099Srwatson	struct mac_biba *mac_biba;
634105696Srwatson	int error;
635101099Srwatson
636105696Srwatson	if (strcmp(MAC_BIBA_LABEL_NAME, element_name) != 0)
637105696Srwatson		return (0);
638105696Srwatson
639105696Srwatson	(*claimed)++;
640105696Srwatson
641101099Srwatson	mac_biba = SLOT(label);
642105696Srwatson	error = mac_biba_to_string(element_data, size, len, mac_biba);
643105696Srwatson	if (error)
644105696Srwatson		return (error);
645101099Srwatson
646105696Srwatson	*len = strlen(element_data);
647105696Srwatson	return (0);
648105696Srwatson}
649105696Srwatson
650105696Srwatsonstatic int
651105696Srwatsonmac_biba_parse_element(struct mac_biba_element *element, char *string)
652101099Srwatson{
653105696Srwatson
654105696Srwatson	if (strcmp(string, "high") == 0 ||
655105696Srwatson	    strcmp(string, "hi") == 0) {
656105696Srwatson		element->mbe_type = MAC_BIBA_TYPE_HIGH;
657105696Srwatson		element->mbe_grade = MAC_BIBA_TYPE_UNDEF;
658105696Srwatson	} else if (strcmp(string, "low") == 0 ||
659105696Srwatson	    strcmp(string, "lo") == 0) {
660105696Srwatson		element->mbe_type = MAC_BIBA_TYPE_LOW;
661105696Srwatson		element->mbe_grade = MAC_BIBA_TYPE_UNDEF;
662105696Srwatson	} else if (strcmp(string, "equal") == 0 ||
663105696Srwatson	    strcmp(string, "eq") == 0) {
664105696Srwatson		element->mbe_type = MAC_BIBA_TYPE_EQUAL;
665105696Srwatson		element->mbe_grade = MAC_BIBA_TYPE_UNDEF;
666105696Srwatson	} else {
667105696Srwatson		char *p0, *p1;
668105696Srwatson		int d;
669105696Srwatson
670105696Srwatson		p0 = string;
671105696Srwatson		d = strtol(p0, &p1, 10);
672105696Srwatson
673105696Srwatson		if (d < 0 || d > 65535)
674105696Srwatson			return (EINVAL);
675105696Srwatson		element->mbe_type = MAC_BIBA_TYPE_GRADE;
676105696Srwatson		element->mbe_grade = d;
677105696Srwatson
678105696Srwatson		if (*p1 != ':')  {
679105696Srwatson			if (p1 == p0 || *p1 != '\0')
680105696Srwatson				return (EINVAL);
681105696Srwatson			else
682105696Srwatson				return (0);
683105696Srwatson		}
684105696Srwatson		else
685105696Srwatson			if (*(p1 + 1) == '\0')
686105696Srwatson				return (0);
687105696Srwatson
688105696Srwatson		while ((p0 = ++p1)) {
689105696Srwatson			d = strtol(p0, &p1, 10);
690105696Srwatson			if (d < 1 || d > MAC_BIBA_MAX_COMPARTMENTS)
691105696Srwatson				return (EINVAL);
692105696Srwatson
693105696Srwatson			MAC_BIBA_BIT_SET(d, element->mbe_compartments);
694105696Srwatson
695105696Srwatson			if (*p1 == '\0')
696105696Srwatson				break;
697105696Srwatson			if (p1 == p0 || *p1 != '+')
698105696Srwatson				return (EINVAL);
699105696Srwatson		}
700105696Srwatson	}
701105696Srwatson
702105696Srwatson	return (0);
703105696Srwatson}
704105696Srwatson
705105696Srwatson/*
706105696Srwatson * Note: destructively consumes the string, make a local copy before
707105696Srwatson * calling if that's a problem.
708105696Srwatson */
709105696Srwatsonstatic int
710105696Srwatsonmac_biba_parse(struct mac_biba *mac_biba, char *string)
711105696Srwatson{
712105696Srwatson	char *range, *rangeend, *rangehigh, *rangelow, *single;
713101099Srwatson	int error;
714101099Srwatson
715105696Srwatson	/* Do we have a range? */
716105696Srwatson	single = string;
717105696Srwatson	range = index(string, '(');
718105696Srwatson	if (range == single)
719105696Srwatson		single = NULL;
720105696Srwatson	rangelow = rangehigh = NULL;
721105696Srwatson	if (range != NULL) {
722105696Srwatson		/* Nul terminate the end of the single string. */
723105696Srwatson		*range = '\0';
724105696Srwatson		range++;
725105696Srwatson		rangelow = range;
726105696Srwatson		rangehigh = index(rangelow, '-');
727105696Srwatson		if (rangehigh == NULL)
728105696Srwatson			return (EINVAL);
729105696Srwatson		rangehigh++;
730105696Srwatson		if (*rangelow == '\0' || *rangehigh == '\0')
731105696Srwatson			return (EINVAL);
732105696Srwatson		rangeend = index(rangehigh, ')');
733105696Srwatson		if (rangeend == NULL)
734105696Srwatson			return (EINVAL);
735105696Srwatson		if (*(rangeend + 1) != '\0')
736105696Srwatson			return (EINVAL);
737105696Srwatson		/* Nul terminate the ends of the ranges. */
738105696Srwatson		*(rangehigh - 1) = '\0';
739105696Srwatson		*rangeend = '\0';
740105696Srwatson	}
741105696Srwatson	KASSERT((rangelow != NULL && rangehigh != NULL) ||
742105696Srwatson	    (rangelow == NULL && rangehigh == NULL),
743105696Srwatson	    ("mac_biba_internalize_label: range mismatch"));
744101099Srwatson
745105696Srwatson	bzero(mac_biba, sizeof(*mac_biba));
746105696Srwatson	if (single != NULL) {
747105696Srwatson		error = mac_biba_parse_element(&mac_biba->mb_single, single);
748105696Srwatson		if (error)
749105696Srwatson			return (error);
750105696Srwatson		mac_biba->mb_flags |= MAC_BIBA_FLAG_SINGLE;
751105696Srwatson	}
752105696Srwatson
753105696Srwatson	if (rangelow != NULL) {
754105696Srwatson		error = mac_biba_parse_element(&mac_biba->mb_rangelow,
755105696Srwatson		    rangelow);
756105696Srwatson		if (error)
757105696Srwatson			return (error);
758105696Srwatson		error = mac_biba_parse_element(&mac_biba->mb_rangehigh,
759105696Srwatson		    rangehigh);
760105696Srwatson		if (error)
761105696Srwatson			return (error);
762105696Srwatson		mac_biba->mb_flags |= MAC_BIBA_FLAG_RANGE;
763105696Srwatson	}
764105696Srwatson
765101099Srwatson	error = mac_biba_valid(mac_biba);
766101099Srwatson	if (error)
767101099Srwatson		return (error);
768101099Srwatson
769105696Srwatson	return (0);
770105696Srwatson}
771101099Srwatson
772105696Srwatsonstatic int
773105696Srwatsonmac_biba_internalize_label(struct label *label, char *element_name,
774105696Srwatson    char *element_data, int *claimed)
775105696Srwatson{
776105696Srwatson	struct mac_biba *mac_biba, mac_biba_temp;
777105696Srwatson	int error;
778105696Srwatson
779105696Srwatson	if (strcmp(MAC_BIBA_LABEL_NAME, element_name) != 0)
780105696Srwatson		return (0);
781105696Srwatson
782105696Srwatson	(*claimed)++;
783105696Srwatson
784105696Srwatson	error = mac_biba_parse(&mac_biba_temp, element_data);
785105696Srwatson	if (error)
786105696Srwatson		return (error);
787105696Srwatson
788105696Srwatson	mac_biba = SLOT(label);
789105696Srwatson	*mac_biba = mac_biba_temp;
790105696Srwatson
791101099Srwatson	return (0);
792101099Srwatson}
793101099Srwatson
794105696Srwatsonstatic void
795105696Srwatsonmac_biba_copy_label(struct label *src, struct label *dest)
796105696Srwatson{
797105696Srwatson
798105696Srwatson	*SLOT(dest) = *SLOT(src);
799105696Srwatson}
800105696Srwatson
801101099Srwatson/*
802101099Srwatson * Labeling event operations: file system objects, and things that look
803101099Srwatson * a lot like file system objects.
804101099Srwatson */
805101099Srwatsonstatic void
806101099Srwatsonmac_biba_create_devfs_device(dev_t dev, struct devfs_dirent *devfs_dirent,
807101099Srwatson    struct label *label)
808101099Srwatson{
809101099Srwatson	struct mac_biba *mac_biba;
810101099Srwatson	int biba_type;
811101099Srwatson
812101099Srwatson	mac_biba = SLOT(label);
813101099Srwatson	if (strcmp(dev->si_name, "null") == 0 ||
814101099Srwatson	    strcmp(dev->si_name, "zero") == 0 ||
815101099Srwatson	    strcmp(dev->si_name, "random") == 0 ||
816101099Srwatson	    strncmp(dev->si_name, "fd/", strlen("fd/")) == 0)
817101099Srwatson		biba_type = MAC_BIBA_TYPE_EQUAL;
818105606Srwatson	else if (ptys_equal &&
819105606Srwatson	    (strncmp(dev->si_name, "ttyp", strlen("ttyp")) == 0 ||
820105606Srwatson	    strncmp(dev->si_name, "ptyp", strlen("ptyp")) == 0))
821105606Srwatson		biba_type = MAC_BIBA_TYPE_EQUAL;
822101099Srwatson	else
823101099Srwatson		biba_type = MAC_BIBA_TYPE_HIGH;
824105643Srwatson	mac_biba_set_single(mac_biba, biba_type, 0, NULL);
825101099Srwatson}
826101099Srwatson
827101099Srwatsonstatic void
828101099Srwatsonmac_biba_create_devfs_directory(char *dirname, int dirnamelen,
829101099Srwatson    struct devfs_dirent *devfs_dirent, struct label *label)
830101099Srwatson{
831101099Srwatson	struct mac_biba *mac_biba;
832101099Srwatson
833101099Srwatson	mac_biba = SLOT(label);
834105643Srwatson	mac_biba_set_single(mac_biba, MAC_BIBA_TYPE_HIGH, 0, NULL);
835101099Srwatson}
836101099Srwatson
837101099Srwatsonstatic void
838104535Srwatsonmac_biba_create_devfs_symlink(struct ucred *cred, struct devfs_dirent *dd,
839104535Srwatson    struct label *ddlabel, struct devfs_dirent *de, struct label *delabel)
840104535Srwatson{
841104535Srwatson	struct mac_biba *source, *dest;
842104535Srwatson
843104535Srwatson	source = SLOT(&cred->cr_label);
844104535Srwatson	dest = SLOT(delabel);
845104535Srwatson
846104535Srwatson	mac_biba_copy_single(source, dest);
847104535Srwatson}
848104535Srwatson
849104535Srwatsonstatic void
850101099Srwatsonmac_biba_create_devfs_vnode(struct devfs_dirent *devfs_dirent,
851101099Srwatson    struct label *direntlabel, struct vnode *vp, struct label *vnodelabel)
852101099Srwatson{
853101099Srwatson	struct mac_biba *source, *dest;
854101099Srwatson
855101099Srwatson	source = SLOT(direntlabel);
856101099Srwatson	dest = SLOT(vnodelabel);
857101099Srwatson	mac_biba_copy_single(source, dest);
858101099Srwatson}
859101099Srwatson
860101099Srwatsonstatic void
861101099Srwatsonmac_biba_create_mount(struct ucred *cred, struct mount *mp,
862101099Srwatson    struct label *mntlabel, struct label *fslabel)
863101099Srwatson{
864101099Srwatson	struct mac_biba *source, *dest;
865101099Srwatson
866101099Srwatson	source = SLOT(&cred->cr_label);
867101099Srwatson	dest = SLOT(mntlabel);
868101099Srwatson	mac_biba_copy_single(source, dest);
869101099Srwatson	dest = SLOT(fslabel);
870101099Srwatson	mac_biba_copy_single(source, dest);
871101099Srwatson}
872101099Srwatson
873101099Srwatsonstatic void
874101099Srwatsonmac_biba_create_root_mount(struct ucred *cred, struct mount *mp,
875101099Srwatson    struct label *mntlabel, struct label *fslabel)
876101099Srwatson{
877101099Srwatson	struct mac_biba *mac_biba;
878101099Srwatson
879101099Srwatson	/* Always mount root as high integrity. */
880101099Srwatson	mac_biba = SLOT(fslabel);
881105643Srwatson	mac_biba_set_single(mac_biba, MAC_BIBA_TYPE_HIGH, 0, NULL);
882101099Srwatson	mac_biba = SLOT(mntlabel);
883105643Srwatson	mac_biba_set_single(mac_biba, MAC_BIBA_TYPE_HIGH, 0, NULL);
884101099Srwatson}
885101099Srwatson
886101099Srwatsonstatic void
887101099Srwatsonmac_biba_relabel_vnode(struct ucred *cred, struct vnode *vp,
888101099Srwatson    struct label *vnodelabel, struct label *label)
889101099Srwatson{
890101099Srwatson	struct mac_biba *source, *dest;
891101099Srwatson
892101099Srwatson	source = SLOT(label);
893101099Srwatson	dest = SLOT(vnodelabel);
894101099Srwatson
895105656Srwatson	mac_biba_copy(source, dest);
896101099Srwatson}
897101099Srwatson
898101099Srwatsonstatic void
899101099Srwatsonmac_biba_update_devfsdirent(struct devfs_dirent *devfs_dirent,
900101099Srwatson    struct label *direntlabel, struct vnode *vp, struct label *vnodelabel)
901101099Srwatson{
902101099Srwatson	struct mac_biba *source, *dest;
903101099Srwatson
904101099Srwatson	source = SLOT(vnodelabel);
905101099Srwatson	dest = SLOT(direntlabel);
906101099Srwatson
907105656Srwatson	mac_biba_copy(source, dest);
908101099Srwatson}
909101099Srwatson
910101099Srwatsonstatic void
911105988Srwatsonmac_biba_associate_vnode_devfs(struct mount *mp, struct label *fslabel,
912105988Srwatson    struct devfs_dirent *de, struct label *delabel, struct vnode *vp,
913105988Srwatson    struct label *vlabel)
914101099Srwatson{
915101099Srwatson	struct mac_biba *source, *dest;
916101099Srwatson
917105988Srwatson	source = SLOT(delabel);
918105988Srwatson	dest = SLOT(vlabel);
919101099Srwatson
920101099Srwatson	mac_biba_copy_single(source, dest);
921101099Srwatson}
922101099Srwatson
923101099Srwatsonstatic int
924105988Srwatsonmac_biba_associate_vnode_extattr(struct mount *mp, struct label *fslabel,
925105988Srwatson    struct vnode *vp, struct label *vlabel)
926101099Srwatson{
927105988Srwatson	struct mac_biba temp, *source, *dest;
928105988Srwatson	size_t buflen;
929101099Srwatson	int error;
930101099Srwatson
931105988Srwatson	source = SLOT(fslabel);
932105988Srwatson	dest = SLOT(vlabel);
933101099Srwatson
934105988Srwatson	buflen = sizeof(temp);
935105988Srwatson	bzero(&temp, buflen);
936105988Srwatson
937105988Srwatson	error = vn_extattr_get(vp, IO_NODELOCKED, MAC_BIBA_EXTATTR_NAMESPACE,
938105988Srwatson	    MAC_BIBA_EXTATTR_NAME, &buflen, (char *) &temp, curthread);
939105988Srwatson	if (error == ENOATTR || error == EOPNOTSUPP) {
940105988Srwatson		/* Fall back to the fslabel. */
941105988Srwatson		mac_biba_copy_single(source, dest);
942105988Srwatson		return (0);
943105988Srwatson	} else if (error)
944101099Srwatson		return (error);
945101099Srwatson
946105988Srwatson	if (buflen != sizeof(temp)) {
947105988Srwatson		printf("mac_biba_associate_vnode_extattr: bad size %d\n",
948105988Srwatson		    buflen);
949105988Srwatson		return (EPERM);
950105988Srwatson	}
951105988Srwatson	if (mac_biba_valid(&temp) != 0) {
952105988Srwatson		printf("mac_biba_associate_vnode_extattr: invalid\n");
953105988Srwatson		return (EPERM);
954105988Srwatson	}
955105988Srwatson	if ((temp.mb_flags & MAC_BIBA_FLAGS_BOTH) != MAC_BIBA_FLAG_SINGLE) {
956105988Srwatson		printf("mac_biba_associate_vnode_extattr: not single\n");
957105988Srwatson		return (EPERM);
958105988Srwatson	}
959101099Srwatson
960105988Srwatson	mac_biba_copy_single(&temp, dest);
961101099Srwatson	return (0);
962101099Srwatson}
963101099Srwatson
964101099Srwatsonstatic void
965105988Srwatsonmac_biba_associate_vnode_singlelabel(struct mount *mp,
966105988Srwatson    struct label *fslabel, struct vnode *vp, struct label *vlabel)
967101099Srwatson{
968101099Srwatson	struct mac_biba *source, *dest;
969101099Srwatson
970101099Srwatson	source = SLOT(fslabel);
971105988Srwatson	dest = SLOT(vlabel);
972101099Srwatson
973101099Srwatson	mac_biba_copy_single(source, dest);
974101099Srwatson}
975101099Srwatson
976105988Srwatsonstatic int
977105988Srwatsonmac_biba_create_vnode_extattr(struct ucred *cred, struct mount *mp,
978105988Srwatson    struct label *fslabel, struct vnode *dvp, struct label *dlabel,
979105988Srwatson    struct vnode *vp, struct label *vlabel, struct componentname *cnp)
980105988Srwatson{
981105988Srwatson	struct mac_biba *source, *dest, temp;
982105988Srwatson	size_t buflen;
983105988Srwatson	int error;
984105988Srwatson
985105988Srwatson	buflen = sizeof(temp);
986105988Srwatson	bzero(&temp, buflen);
987105988Srwatson
988105988Srwatson	source = SLOT(&cred->cr_label);
989105988Srwatson	dest = SLOT(vlabel);
990105988Srwatson	mac_biba_copy_single(source, &temp);
991105988Srwatson
992105988Srwatson	error = vn_extattr_set(vp, IO_NODELOCKED, MAC_BIBA_EXTATTR_NAMESPACE,
993105988Srwatson	    MAC_BIBA_EXTATTR_NAME, buflen, (char *) &temp, curthread);
994105988Srwatson	if (error == 0)
995105988Srwatson		mac_biba_copy_single(source, dest);
996105988Srwatson	return (error);
997105988Srwatson}
998105988Srwatson
999105988Srwatsonstatic int
1000105988Srwatsonmac_biba_setlabel_vnode_extattr(struct ucred *cred, struct vnode *vp,
1001105988Srwatson    struct label *vlabel, struct label *intlabel)
1002105988Srwatson{
1003105988Srwatson	struct mac_biba *source, temp;
1004105988Srwatson	size_t buflen;
1005105988Srwatson	int error;
1006105988Srwatson
1007105988Srwatson	buflen = sizeof(temp);
1008105988Srwatson	bzero(&temp, buflen);
1009105988Srwatson
1010105988Srwatson	source = SLOT(intlabel);
1011105988Srwatson	if ((source->mb_flags & MAC_BIBA_FLAG_SINGLE) == 0)
1012105988Srwatson		return (0);
1013105988Srwatson
1014105988Srwatson	mac_biba_copy_single(source, &temp);
1015105988Srwatson
1016105988Srwatson	error = vn_extattr_set(vp, IO_NODELOCKED, MAC_BIBA_EXTATTR_NAMESPACE,
1017105988Srwatson	    MAC_BIBA_EXTATTR_NAME, buflen, (char *) &temp, curthread);
1018105988Srwatson	return (error);
1019105988Srwatson}
1020105988Srwatson
1021101099Srwatson/*
1022101099Srwatson * Labeling event operations: IPC object.
1023101099Srwatson */
1024101099Srwatsonstatic void
1025101099Srwatsonmac_biba_create_mbuf_from_socket(struct socket *so, struct label *socketlabel,
1026101099Srwatson    struct mbuf *m, struct label *mbuflabel)
1027101099Srwatson{
1028101099Srwatson	struct mac_biba *source, *dest;
1029101099Srwatson
1030101099Srwatson	source = SLOT(socketlabel);
1031101099Srwatson	dest = SLOT(mbuflabel);
1032101099Srwatson
1033101099Srwatson	mac_biba_copy_single(source, dest);
1034101099Srwatson}
1035101099Srwatson
1036101099Srwatsonstatic void
1037101099Srwatsonmac_biba_create_socket(struct ucred *cred, struct socket *socket,
1038101099Srwatson    struct label *socketlabel)
1039101099Srwatson{
1040101099Srwatson	struct mac_biba *source, *dest;
1041101099Srwatson
1042101099Srwatson	source = SLOT(&cred->cr_label);
1043101099Srwatson	dest = SLOT(socketlabel);
1044101099Srwatson
1045101099Srwatson	mac_biba_copy_single(source, dest);
1046101099Srwatson}
1047101099Srwatson
1048101099Srwatsonstatic void
1049101099Srwatsonmac_biba_create_pipe(struct ucred *cred, struct pipe *pipe,
1050101099Srwatson    struct label *pipelabel)
1051101099Srwatson{
1052101099Srwatson	struct mac_biba *source, *dest;
1053101099Srwatson
1054101099Srwatson	source = SLOT(&cred->cr_label);
1055101099Srwatson	dest = SLOT(pipelabel);
1056101099Srwatson
1057101099Srwatson	mac_biba_copy_single(source, dest);
1058101099Srwatson}
1059101099Srwatson
1060101099Srwatsonstatic void
1061101099Srwatsonmac_biba_create_socket_from_socket(struct socket *oldsocket,
1062101099Srwatson    struct label *oldsocketlabel, struct socket *newsocket,
1063101099Srwatson    struct label *newsocketlabel)
1064101099Srwatson{
1065101099Srwatson	struct mac_biba *source, *dest;
1066101099Srwatson
1067101099Srwatson	source = SLOT(oldsocketlabel);
1068101099Srwatson	dest = SLOT(newsocketlabel);
1069101099Srwatson
1070101099Srwatson	mac_biba_copy_single(source, dest);
1071101099Srwatson}
1072101099Srwatson
1073101099Srwatsonstatic void
1074101099Srwatsonmac_biba_relabel_socket(struct ucred *cred, struct socket *socket,
1075101099Srwatson    struct label *socketlabel, struct label *newlabel)
1076101099Srwatson{
1077101099Srwatson	struct mac_biba *source, *dest;
1078101099Srwatson
1079101099Srwatson	source = SLOT(newlabel);
1080101099Srwatson	dest = SLOT(socketlabel);
1081101099Srwatson
1082105656Srwatson	mac_biba_copy(source, dest);
1083101099Srwatson}
1084101099Srwatson
1085101099Srwatsonstatic void
1086101099Srwatsonmac_biba_relabel_pipe(struct ucred *cred, struct pipe *pipe,
1087101099Srwatson    struct label *pipelabel, struct label *newlabel)
1088101099Srwatson{
1089101099Srwatson	struct mac_biba *source, *dest;
1090101099Srwatson
1091101099Srwatson	source = SLOT(newlabel);
1092101099Srwatson	dest = SLOT(pipelabel);
1093101099Srwatson
1094105656Srwatson	mac_biba_copy(source, dest);
1095101099Srwatson}
1096101099Srwatson
1097101099Srwatsonstatic void
1098101099Srwatsonmac_biba_set_socket_peer_from_mbuf(struct mbuf *mbuf, struct label *mbuflabel,
1099101099Srwatson    struct socket *socket, struct label *socketpeerlabel)
1100101099Srwatson{
1101101099Srwatson	struct mac_biba *source, *dest;
1102101099Srwatson
1103101099Srwatson	source = SLOT(mbuflabel);
1104101099Srwatson	dest = SLOT(socketpeerlabel);
1105101099Srwatson
1106101099Srwatson	mac_biba_copy_single(source, dest);
1107101099Srwatson}
1108101099Srwatson
1109101099Srwatson/*
1110101099Srwatson * Labeling event operations: network objects.
1111101099Srwatson */
1112101099Srwatsonstatic void
1113101099Srwatsonmac_biba_set_socket_peer_from_socket(struct socket *oldsocket,
1114101099Srwatson    struct label *oldsocketlabel, struct socket *newsocket,
1115101099Srwatson    struct label *newsocketpeerlabel)
1116101099Srwatson{
1117101099Srwatson	struct mac_biba *source, *dest;
1118101099Srwatson
1119101099Srwatson	source = SLOT(oldsocketlabel);
1120101099Srwatson	dest = SLOT(newsocketpeerlabel);
1121101099Srwatson
1122101099Srwatson	mac_biba_copy_single(source, dest);
1123101099Srwatson}
1124101099Srwatson
1125101099Srwatsonstatic void
1126101099Srwatsonmac_biba_create_bpfdesc(struct ucred *cred, struct bpf_d *bpf_d,
1127101099Srwatson    struct label *bpflabel)
1128101099Srwatson{
1129101099Srwatson	struct mac_biba *source, *dest;
1130101099Srwatson
1131101099Srwatson	source = SLOT(&cred->cr_label);
1132101099Srwatson	dest = SLOT(bpflabel);
1133101099Srwatson
1134101099Srwatson	mac_biba_copy_single(source, dest);
1135101099Srwatson}
1136101099Srwatson
1137101099Srwatsonstatic void
1138101099Srwatsonmac_biba_create_ifnet(struct ifnet *ifnet, struct label *ifnetlabel)
1139101099Srwatson{
1140101099Srwatson	char tifname[IFNAMSIZ], ifname[IFNAMSIZ], *p, *q;
1141101099Srwatson	char tiflist[sizeof(trusted_interfaces)];
1142101099Srwatson	struct mac_biba *dest;
1143101099Srwatson	int len, grade;
1144101099Srwatson
1145101099Srwatson	dest = SLOT(ifnetlabel);
1146101099Srwatson
1147101099Srwatson	if (ifnet->if_type == IFT_LOOP) {
1148101099Srwatson		grade = MAC_BIBA_TYPE_EQUAL;
1149101099Srwatson		goto set;
1150101099Srwatson	}
1151101099Srwatson
1152101099Srwatson	if (trust_all_interfaces) {
1153101099Srwatson		grade = MAC_BIBA_TYPE_HIGH;
1154101099Srwatson		goto set;
1155101099Srwatson	}
1156101099Srwatson
1157101099Srwatson	grade = MAC_BIBA_TYPE_LOW;
1158101099Srwatson
1159101099Srwatson	if (trusted_interfaces[0] == '\0' ||
1160101099Srwatson	    !strvalid(trusted_interfaces, sizeof(trusted_interfaces)))
1161101099Srwatson		goto set;
1162101099Srwatson
1163106089Srwatson	bzero(tiflist, sizeof(tiflist));
1164101099Srwatson	for (p = trusted_interfaces, q = tiflist; *p != '\0'; p++, q++)
1165101099Srwatson		if(*p != ' ' && *p != '\t')
1166101099Srwatson			*q = *p;
1167101099Srwatson
1168101099Srwatson	snprintf(ifname, IFNAMSIZ, "%s%d", ifnet->if_name, ifnet->if_unit);
1169101099Srwatson
1170101099Srwatson	for (p = q = tiflist;; p++) {
1171101099Srwatson		if (*p == ',' || *p == '\0') {
1172101099Srwatson			len = p - q;
1173101099Srwatson			if (len < IFNAMSIZ) {
1174101099Srwatson				bzero(tifname, sizeof(tifname));
1175101099Srwatson				bcopy(q, tifname, len);
1176101099Srwatson				if (strcmp(tifname, ifname) == 0) {
1177101099Srwatson					grade = MAC_BIBA_TYPE_HIGH;
1178101099Srwatson					break;
1179101099Srwatson				}
1180106089Srwatson			} else {
1181106089Srwatson				*p = '\0';
1182106089Srwatson				printf("mac_biba warning: interface name "
1183106089Srwatson				    "\"%s\" is too long (must be < %d)\n",
1184106089Srwatson				    q, IFNAMSIZ);
1185101099Srwatson			}
1186101099Srwatson			if (*p == '\0')
1187101099Srwatson				break;
1188101099Srwatson			q = p + 1;
1189101099Srwatson		}
1190101099Srwatson	}
1191101099Srwatsonset:
1192105643Srwatson	mac_biba_set_single(dest, grade, 0, NULL);
1193105643Srwatson	mac_biba_set_range(dest, grade, 0, NULL, grade, 0, NULL);
1194101099Srwatson}
1195101099Srwatson
1196101099Srwatsonstatic void
1197101099Srwatsonmac_biba_create_ipq(struct mbuf *fragment, struct label *fragmentlabel,
1198101099Srwatson    struct ipq *ipq, struct label *ipqlabel)
1199101099Srwatson{
1200101099Srwatson	struct mac_biba *source, *dest;
1201101099Srwatson
1202101099Srwatson	source = SLOT(fragmentlabel);
1203101099Srwatson	dest = SLOT(ipqlabel);
1204101099Srwatson
1205101099Srwatson	mac_biba_copy_single(source, dest);
1206101099Srwatson}
1207101099Srwatson
1208101099Srwatsonstatic void
1209101099Srwatsonmac_biba_create_datagram_from_ipq(struct ipq *ipq, struct label *ipqlabel,
1210101099Srwatson    struct mbuf *datagram, struct label *datagramlabel)
1211101099Srwatson{
1212101099Srwatson	struct mac_biba *source, *dest;
1213101099Srwatson
1214101099Srwatson	source = SLOT(ipqlabel);
1215101099Srwatson	dest = SLOT(datagramlabel);
1216101099Srwatson
1217101099Srwatson	/* Just use the head, since we require them all to match. */
1218101099Srwatson	mac_biba_copy_single(source, dest);
1219101099Srwatson}
1220101099Srwatson
1221101099Srwatsonstatic void
1222101099Srwatsonmac_biba_create_fragment(struct mbuf *datagram, struct label *datagramlabel,
1223101099Srwatson    struct mbuf *fragment, struct label *fragmentlabel)
1224101099Srwatson{
1225101099Srwatson	struct mac_biba *source, *dest;
1226101099Srwatson
1227101099Srwatson	source = SLOT(datagramlabel);
1228101099Srwatson	dest = SLOT(fragmentlabel);
1229101099Srwatson
1230101099Srwatson	mac_biba_copy_single(source, dest);
1231101099Srwatson}
1232101099Srwatson
1233101099Srwatsonstatic void
1234101099Srwatsonmac_biba_create_mbuf_from_mbuf(struct mbuf *oldmbuf,
1235101099Srwatson    struct label *oldmbuflabel, struct mbuf *newmbuf,
1236101099Srwatson    struct label *newmbuflabel)
1237101099Srwatson{
1238101099Srwatson	struct mac_biba *source, *dest;
1239101099Srwatson
1240101099Srwatson	source = SLOT(oldmbuflabel);
1241101099Srwatson	dest = SLOT(newmbuflabel);
1242101099Srwatson
1243105656Srwatson	/*
1244105656Srwatson	 * Because the source mbuf may not yet have been "created",
1245105696Srwatson	 * just initialized, we do a conditional copy.  Since we don't
1246105656Srwatson	 * allow mbufs to have ranges, do a KASSERT to make sure that
1247105656Srwatson	 * doesn't happen.
1248105656Srwatson	 */
1249105656Srwatson	KASSERT((source->mb_flags & MAC_BIBA_FLAG_RANGE) == 0,
1250105656Srwatson	    ("mac_biba_create_mbuf_from_mbuf: source mbuf has range"));
1251105656Srwatson	mac_biba_copy(source, dest);
1252101099Srwatson}
1253101099Srwatson
1254101099Srwatsonstatic void
1255101099Srwatsonmac_biba_create_mbuf_linklayer(struct ifnet *ifnet, struct label *ifnetlabel,
1256101099Srwatson    struct mbuf *mbuf, struct label *mbuflabel)
1257101099Srwatson{
1258101099Srwatson	struct mac_biba *dest;
1259101099Srwatson
1260101099Srwatson	dest = SLOT(mbuflabel);
1261101099Srwatson
1262105643Srwatson	mac_biba_set_single(dest, MAC_BIBA_TYPE_EQUAL, 0, NULL);
1263101099Srwatson}
1264101099Srwatson
1265101099Srwatsonstatic void
1266101099Srwatsonmac_biba_create_mbuf_from_bpfdesc(struct bpf_d *bpf_d, struct label *bpflabel,
1267101099Srwatson    struct mbuf *mbuf, struct label *mbuflabel)
1268101099Srwatson{
1269101099Srwatson	struct mac_biba *source, *dest;
1270101099Srwatson
1271101099Srwatson	source = SLOT(bpflabel);
1272101099Srwatson	dest = SLOT(mbuflabel);
1273101099Srwatson
1274101099Srwatson	mac_biba_copy_single(source, dest);
1275101099Srwatson}
1276101099Srwatson
1277101099Srwatsonstatic void
1278101099Srwatsonmac_biba_create_mbuf_from_ifnet(struct ifnet *ifnet, struct label *ifnetlabel,
1279101099Srwatson    struct mbuf *m, struct label *mbuflabel)
1280101099Srwatson{
1281101099Srwatson	struct mac_biba *source, *dest;
1282101099Srwatson
1283101099Srwatson	source = SLOT(ifnetlabel);
1284101099Srwatson	dest = SLOT(mbuflabel);
1285101099Srwatson
1286101099Srwatson	mac_biba_copy_single(source, dest);
1287101099Srwatson}
1288101099Srwatson
1289101099Srwatsonstatic void
1290101099Srwatsonmac_biba_create_mbuf_multicast_encap(struct mbuf *oldmbuf,
1291101099Srwatson    struct label *oldmbuflabel, struct ifnet *ifnet, struct label *ifnetlabel,
1292101099Srwatson    struct mbuf *newmbuf, struct label *newmbuflabel)
1293101099Srwatson{
1294101099Srwatson	struct mac_biba *source, *dest;
1295101099Srwatson
1296101099Srwatson	source = SLOT(oldmbuflabel);
1297101099Srwatson	dest = SLOT(newmbuflabel);
1298101099Srwatson
1299101099Srwatson	mac_biba_copy_single(source, dest);
1300101099Srwatson}
1301101099Srwatson
1302101099Srwatsonstatic void
1303101099Srwatsonmac_biba_create_mbuf_netlayer(struct mbuf *oldmbuf, struct label *oldmbuflabel,
1304101099Srwatson    struct mbuf *newmbuf, struct label *newmbuflabel)
1305101099Srwatson{
1306101099Srwatson	struct mac_biba *source, *dest;
1307101099Srwatson
1308101099Srwatson	source = SLOT(oldmbuflabel);
1309101099Srwatson	dest = SLOT(newmbuflabel);
1310101099Srwatson
1311101099Srwatson	mac_biba_copy_single(source, dest);
1312101099Srwatson}
1313101099Srwatson
1314101099Srwatsonstatic int
1315101099Srwatsonmac_biba_fragment_match(struct mbuf *fragment, struct label *fragmentlabel,
1316101099Srwatson    struct ipq *ipq, struct label *ipqlabel)
1317101099Srwatson{
1318101099Srwatson	struct mac_biba *a, *b;
1319101099Srwatson
1320101099Srwatson	a = SLOT(ipqlabel);
1321101099Srwatson	b = SLOT(fragmentlabel);
1322101099Srwatson
1323101099Srwatson	return (mac_biba_equal_single(a, b));
1324101099Srwatson}
1325101099Srwatson
1326101099Srwatsonstatic void
1327101099Srwatsonmac_biba_relabel_ifnet(struct ucred *cred, struct ifnet *ifnet,
1328101099Srwatson    struct label *ifnetlabel, struct label *newlabel)
1329101099Srwatson{
1330101099Srwatson	struct mac_biba *source, *dest;
1331101099Srwatson
1332101099Srwatson	source = SLOT(newlabel);
1333101099Srwatson	dest = SLOT(ifnetlabel);
1334101099Srwatson
1335105656Srwatson	mac_biba_copy(source, dest);
1336101099Srwatson}
1337101099Srwatson
1338101099Srwatsonstatic void
1339101099Srwatsonmac_biba_update_ipq(struct mbuf *fragment, struct label *fragmentlabel,
1340101099Srwatson    struct ipq *ipq, struct label *ipqlabel)
1341101099Srwatson{
1342101099Srwatson
1343101099Srwatson	/* NOOP: we only accept matching labels, so no need to update */
1344101099Srwatson}
1345101099Srwatson
1346101099Srwatson/*
1347101099Srwatson * Labeling event operations: processes.
1348101099Srwatson */
1349101099Srwatsonstatic void
1350101099Srwatsonmac_biba_create_cred(struct ucred *cred_parent, struct ucred *cred_child)
1351101099Srwatson{
1352101099Srwatson	struct mac_biba *source, *dest;
1353101099Srwatson
1354101099Srwatson	source = SLOT(&cred_parent->cr_label);
1355101099Srwatson	dest = SLOT(&cred_child->cr_label);
1356101099Srwatson
1357101099Srwatson	mac_biba_copy_single(source, dest);
1358101099Srwatson	mac_biba_copy_range(source, dest);
1359101099Srwatson}
1360101099Srwatson
1361101099Srwatsonstatic void
1362101099Srwatsonmac_biba_execve_transition(struct ucred *old, struct ucred *new,
1363101099Srwatson    struct vnode *vp, struct mac *vnodelabel)
1364101099Srwatson{
1365101099Srwatson	struct mac_biba *source, *dest;
1366101099Srwatson
1367101099Srwatson	source = SLOT(&old->cr_label);
1368101099Srwatson	dest = SLOT(&new->cr_label);
1369101099Srwatson
1370101099Srwatson	mac_biba_copy_single(source, dest);
1371101099Srwatson	mac_biba_copy_range(source, dest);
1372101099Srwatson}
1373101099Srwatson
1374101099Srwatsonstatic int
1375101099Srwatsonmac_biba_execve_will_transition(struct ucred *old, struct vnode *vp,
1376101099Srwatson    struct mac *vnodelabel)
1377101099Srwatson{
1378101099Srwatson
1379101099Srwatson	return (0);
1380101099Srwatson}
1381101099Srwatson
1382101099Srwatsonstatic void
1383101099Srwatsonmac_biba_create_proc0(struct ucred *cred)
1384101099Srwatson{
1385101099Srwatson	struct mac_biba *dest;
1386101099Srwatson
1387101099Srwatson	dest = SLOT(&cred->cr_label);
1388101099Srwatson
1389105643Srwatson	mac_biba_set_single(dest, MAC_BIBA_TYPE_EQUAL, 0, NULL);
1390105643Srwatson	mac_biba_set_range(dest, MAC_BIBA_TYPE_LOW, 0, NULL,
1391105643Srwatson	    MAC_BIBA_TYPE_HIGH, 0, NULL);
1392101099Srwatson}
1393101099Srwatson
1394101099Srwatsonstatic void
1395101099Srwatsonmac_biba_create_proc1(struct ucred *cred)
1396101099Srwatson{
1397101099Srwatson	struct mac_biba *dest;
1398101099Srwatson
1399101099Srwatson	dest = SLOT(&cred->cr_label);
1400101099Srwatson
1401105643Srwatson	mac_biba_set_single(dest, MAC_BIBA_TYPE_HIGH, 0, NULL);
1402105643Srwatson	mac_biba_set_range(dest, MAC_BIBA_TYPE_LOW, 0, NULL,
1403105643Srwatson	    MAC_BIBA_TYPE_HIGH, 0, NULL);
1404101099Srwatson}
1405101099Srwatson
1406101099Srwatsonstatic void
1407101099Srwatsonmac_biba_relabel_cred(struct ucred *cred, struct label *newlabel)
1408101099Srwatson{
1409101099Srwatson	struct mac_biba *source, *dest;
1410101099Srwatson
1411101099Srwatson	source = SLOT(newlabel);
1412101099Srwatson	dest = SLOT(&cred->cr_label);
1413101099Srwatson
1414105656Srwatson	mac_biba_copy(source, dest);
1415101099Srwatson}
1416101099Srwatson
1417101099Srwatson/*
1418101099Srwatson * Access control checks.
1419101099Srwatson */
1420101099Srwatsonstatic int
1421101099Srwatsonmac_biba_check_bpfdesc_receive(struct bpf_d *bpf_d, struct label *bpflabel,
1422101099Srwatson    struct ifnet *ifnet, struct label *ifnetlabel)
1423101099Srwatson{
1424101099Srwatson	struct mac_biba *a, *b;
1425101099Srwatson
1426101099Srwatson	if (!mac_biba_enabled)
1427101099Srwatson		return (0);
1428101099Srwatson
1429101099Srwatson	a = SLOT(bpflabel);
1430101099Srwatson	b = SLOT(ifnetlabel);
1431101099Srwatson
1432101099Srwatson	if (mac_biba_equal_single(a, b))
1433101099Srwatson		return (0);
1434101099Srwatson	return (EACCES);
1435101099Srwatson}
1436101099Srwatson
1437101099Srwatsonstatic int
1438101099Srwatsonmac_biba_check_cred_relabel(struct ucred *cred, struct label *newlabel)
1439101099Srwatson{
1440101099Srwatson	struct mac_biba *subj, *new;
1441105634Srwatson	int error;
1442101099Srwatson
1443101099Srwatson	subj = SLOT(&cred->cr_label);
1444101099Srwatson	new = SLOT(newlabel);
1445101099Srwatson
1446101099Srwatson	/*
1447105634Srwatson	 * If there is a Biba label update for the credential, it may
1448105634Srwatson	 * be an update of the single, range, or both.
1449101099Srwatson	 */
1450105634Srwatson	error = biba_atmostflags(new, MAC_BIBA_FLAGS_BOTH);
1451105634Srwatson	if (error)
1452105634Srwatson		return (error);
1453101099Srwatson
1454101099Srwatson	/*
1455105634Srwatson	 * If the Biba label is to be changed, authorize as appropriate.
1456101099Srwatson	 */
1457105634Srwatson	if (new->mb_flags & MAC_BIBA_FLAGS_BOTH) {
1458105634Srwatson		/*
1459105634Srwatson		 * To change the Biba single label on a credential, the
1460105634Srwatson		 * new single label must be in the current range.
1461105634Srwatson		 */
1462105634Srwatson		if (new->mb_flags & MAC_BIBA_FLAG_SINGLE &&
1463105634Srwatson		    !mac_biba_single_in_range(new, subj))
1464105634Srwatson			return (EPERM);
1465101099Srwatson
1466105634Srwatson		/*
1467105634Srwatson		 * To change the Biba range on a credential, the new
1468105634Srwatson		 * range label must be in the current range.
1469105634Srwatson		 */
1470105634Srwatson		if (new->mb_flags & MAC_BIBA_FLAG_RANGE &&
1471105634Srwatson		    !mac_biba_range_in_range(new, subj))
1472105634Srwatson			return (EPERM);
1473101099Srwatson
1474105634Srwatson		/*
1475105634Srwatson		 * To have EQUAL in any component of the new credential
1476105634Srwatson		 * Biba label, the subject must already have EQUAL in
1477105634Srwatson		 * their label.
1478105634Srwatson		 */
1479105634Srwatson		if (mac_biba_contains_equal(new)) {
1480106090Srwatson			error = mac_biba_subject_privileged(subj);
1481105634Srwatson			if (error)
1482105634Srwatson				return (error);
1483105634Srwatson		}
1484101099Srwatson
1485105634Srwatson		/*
1486105634Srwatson		 * XXXMAC: Additional consistency tests regarding the
1487105634Srwatson		 * single and range of the new label might be performed
1488105634Srwatson		 * here.
1489105634Srwatson		 */
1490105634Srwatson	}
1491105634Srwatson
1492101099Srwatson	return (0);
1493101099Srwatson}
1494101099Srwatson
1495101099Srwatsonstatic int
1496101099Srwatsonmac_biba_check_cred_visible(struct ucred *u1, struct ucred *u2)
1497101099Srwatson{
1498101099Srwatson	struct mac_biba *subj, *obj;
1499101099Srwatson
1500101099Srwatson	if (!mac_biba_enabled)
1501101099Srwatson		return (0);
1502101099Srwatson
1503101099Srwatson	subj = SLOT(&u1->cr_label);
1504101099Srwatson	obj = SLOT(&u2->cr_label);
1505101099Srwatson
1506101099Srwatson	/* XXX: range */
1507101099Srwatson	if (!mac_biba_dominate_single(obj, subj))
1508101099Srwatson		return (ESRCH);
1509101099Srwatson
1510101099Srwatson	return (0);
1511101099Srwatson}
1512101099Srwatson
1513101099Srwatsonstatic int
1514101099Srwatsonmac_biba_check_ifnet_relabel(struct ucred *cred, struct ifnet *ifnet,
1515101099Srwatson    struct label *ifnetlabel, struct label *newlabel)
1516101099Srwatson{
1517101099Srwatson	struct mac_biba *subj, *new;
1518105634Srwatson	int error;
1519101099Srwatson
1520101099Srwatson	subj = SLOT(&cred->cr_label);
1521101099Srwatson	new = SLOT(newlabel);
1522101099Srwatson
1523105634Srwatson	/*
1524105634Srwatson	 * If there is a Biba label update for the interface, it may
1525105634Srwatson	 * be an update of the single, range, or both.
1526105634Srwatson	 */
1527105634Srwatson	error = biba_atmostflags(new, MAC_BIBA_FLAGS_BOTH);
1528105634Srwatson	if (error)
1529105634Srwatson		return (error);
1530101099Srwatson
1531105634Srwatson	/*
1532106160Srwatson	 * Relabling network interfaces requires Biba privilege.
1533106160Srwatson	 */
1534106160Srwatson	error = mac_biba_subject_privileged(subj);
1535106160Srwatson	if (error)
1536106160Srwatson		return (error);
1537106160Srwatson
1538106160Srwatson	/*
1539105634Srwatson	 * If the Biba label is to be changed, authorize as appropriate.
1540105634Srwatson	 */
1541105634Srwatson	if (new->mb_flags & MAC_BIBA_FLAGS_BOTH) {
1542105634Srwatson		/*
1543105634Srwatson		 * Rely on the traditional superuser status for the Biba
1544105634Srwatson		 * interface relabel requirements.  XXXMAC: This will go
1545105634Srwatson		 * away.
1546105634Srwatson		 */
1547105634Srwatson		error = suser_cred(cred, 0);
1548105634Srwatson		if (error)
1549105634Srwatson			return (EPERM);
1550105634Srwatson
1551105634Srwatson		/*
1552105634Srwatson		 * XXXMAC: Additional consistency tests regarding the single
1553105634Srwatson		 * and the range of the new label might be performed here.
1554105634Srwatson		 */
1555105634Srwatson	}
1556105634Srwatson
1557105634Srwatson	return (0);
1558101099Srwatson}
1559101099Srwatson
1560103759Srwatsonstatic int
1561101099Srwatsonmac_biba_check_ifnet_transmit(struct ifnet *ifnet, struct label *ifnetlabel,
1562101099Srwatson    struct mbuf *m, struct label *mbuflabel)
1563101099Srwatson{
1564101099Srwatson	struct mac_biba *p, *i;
1565103761Srwatson
1566101099Srwatson	if (!mac_biba_enabled)
1567101099Srwatson		return (0);
1568101099Srwatson
1569101099Srwatson	p = SLOT(mbuflabel);
1570101099Srwatson	i = SLOT(ifnetlabel);
1571103759Srwatson
1572101099Srwatson	return (mac_biba_single_in_range(p, i) ? 0 : EACCES);
1573101099Srwatson}
1574101099Srwatson
1575101099Srwatsonstatic int
1576101099Srwatsonmac_biba_check_mount_stat(struct ucred *cred, struct mount *mp,
1577101099Srwatson    struct label *mntlabel)
1578101099Srwatson{
1579101099Srwatson	struct mac_biba *subj, *obj;
1580101099Srwatson
1581101099Srwatson	if (!mac_biba_enabled)
1582101099Srwatson		return (0);
1583101099Srwatson
1584101099Srwatson	subj = SLOT(&cred->cr_label);
1585101099Srwatson	obj = SLOT(mntlabel);
1586101099Srwatson
1587101099Srwatson	if (!mac_biba_dominate_single(obj, subj))
1588101099Srwatson		return (EACCES);
1589101099Srwatson
1590101099Srwatson	return (0);
1591101099Srwatson}
1592101099Srwatson
1593101099Srwatsonstatic int
1594101099Srwatsonmac_biba_check_pipe_ioctl(struct ucred *cred, struct pipe *pipe,
1595101099Srwatson    struct label *pipelabel, unsigned long cmd, void /* caddr_t */ *data)
1596101099Srwatson{
1597103759Srwatson
1598101099Srwatson	if(!mac_biba_enabled)
1599101099Srwatson		return (0);
1600101099Srwatson
1601101099Srwatson	/* XXX: This will be implemented soon... */
1602101099Srwatson
1603101099Srwatson	return (0);
1604101099Srwatson}
1605101099Srwatson
1606101099Srwatsonstatic int
1607102115Srwatsonmac_biba_check_pipe_poll(struct ucred *cred, struct pipe *pipe,
1608102115Srwatson    struct label *pipelabel)
1609101099Srwatson{
1610101099Srwatson	struct mac_biba *subj, *obj;
1611101099Srwatson
1612101099Srwatson	if (!mac_biba_enabled)
1613101099Srwatson		return (0);
1614101099Srwatson
1615101099Srwatson	subj = SLOT(&cred->cr_label);
1616101099Srwatson	obj = SLOT((pipelabel));
1617101099Srwatson
1618102115Srwatson	if (!mac_biba_dominate_single(obj, subj))
1619102115Srwatson		return (EACCES);
1620101099Srwatson
1621101099Srwatson	return (0);
1622101099Srwatson}
1623101099Srwatson
1624101099Srwatsonstatic int
1625102115Srwatsonmac_biba_check_pipe_read(struct ucred *cred, struct pipe *pipe,
1626102115Srwatson    struct label *pipelabel)
1627102115Srwatson{
1628102115Srwatson	struct mac_biba *subj, *obj;
1629102115Srwatson
1630102115Srwatson	if (!mac_biba_enabled)
1631102115Srwatson		return (0);
1632102115Srwatson
1633102115Srwatson	subj = SLOT(&cred->cr_label);
1634102115Srwatson	obj = SLOT((pipelabel));
1635102115Srwatson
1636102115Srwatson	if (!mac_biba_dominate_single(obj, subj))
1637102115Srwatson		return (EACCES);
1638102115Srwatson
1639102115Srwatson	return (0);
1640102115Srwatson}
1641102115Srwatson
1642102115Srwatsonstatic int
1643101099Srwatsonmac_biba_check_pipe_relabel(struct ucred *cred, struct pipe *pipe,
1644101099Srwatson    struct label *pipelabel, struct label *newlabel)
1645101099Srwatson{
1646101099Srwatson	struct mac_biba *subj, *obj, *new;
1647105634Srwatson	int error;
1648101099Srwatson
1649101099Srwatson	new = SLOT(newlabel);
1650101099Srwatson	subj = SLOT(&cred->cr_label);
1651101099Srwatson	obj = SLOT(pipelabel);
1652101099Srwatson
1653101099Srwatson	/*
1654105634Srwatson	 * If there is a Biba label update for a pipe, it must be a
1655105634Srwatson	 * single update.
1656101099Srwatson	 */
1657105634Srwatson	error = biba_atmostflags(new, MAC_BIBA_FLAG_SINGLE);
1658105634Srwatson	if (error)
1659105634Srwatson		return (error);
1660101099Srwatson
1661101099Srwatson	/*
1662105634Srwatson	 * To perform a relabel of a pipe (Biba label or not), Biba must
1663105634Srwatson	 * authorize the relabel.
1664101099Srwatson	 */
1665105634Srwatson	if (!mac_biba_single_in_range(obj, subj))
1666101099Srwatson		return (EPERM);
1667101099Srwatson
1668101099Srwatson	/*
1669105634Srwatson	 * If the Biba label is to be changed, authorize as appropriate.
1670101099Srwatson	 */
1671105634Srwatson	if (new->mb_flags & MAC_BIBA_FLAG_SINGLE) {
1672105634Srwatson		/*
1673105634Srwatson		 * To change the Biba label on a pipe, the new pipe label
1674105634Srwatson		 * must be in the subject range.
1675105634Srwatson		 */
1676105634Srwatson		if (!mac_biba_single_in_range(new, subj))
1677105634Srwatson			return (EPERM);
1678101099Srwatson
1679105634Srwatson		/*
1680105634Srwatson		 * To change the Biba label on a pipe to be EQUAL, the
1681105634Srwatson		 * subject must have appropriate privilege.
1682105634Srwatson		 */
1683105634Srwatson		if (mac_biba_contains_equal(new)) {
1684106090Srwatson			error = mac_biba_subject_privileged(subj);
1685105634Srwatson			if (error)
1686105634Srwatson				return (error);
1687105634Srwatson		}
1688105634Srwatson	}
1689105634Srwatson
1690101099Srwatson	return (0);
1691101099Srwatson}
1692101099Srwatson
1693101099Srwatsonstatic int
1694102115Srwatsonmac_biba_check_pipe_stat(struct ucred *cred, struct pipe *pipe,
1695102115Srwatson    struct label *pipelabel)
1696102115Srwatson{
1697102115Srwatson	struct mac_biba *subj, *obj;
1698102115Srwatson
1699102115Srwatson	if (!mac_biba_enabled)
1700102115Srwatson		return (0);
1701102115Srwatson
1702102115Srwatson	subj = SLOT(&cred->cr_label);
1703102115Srwatson	obj = SLOT((pipelabel));
1704102115Srwatson
1705102115Srwatson	if (!mac_biba_dominate_single(obj, subj))
1706102115Srwatson		return (EACCES);
1707102115Srwatson
1708102115Srwatson	return (0);
1709102115Srwatson}
1710102115Srwatson
1711102115Srwatsonstatic int
1712102115Srwatsonmac_biba_check_pipe_write(struct ucred *cred, struct pipe *pipe,
1713102115Srwatson    struct label *pipelabel)
1714102115Srwatson{
1715102115Srwatson	struct mac_biba *subj, *obj;
1716102115Srwatson
1717102115Srwatson	if (!mac_biba_enabled)
1718102115Srwatson		return (0);
1719102115Srwatson
1720102115Srwatson	subj = SLOT(&cred->cr_label);
1721102115Srwatson	obj = SLOT((pipelabel));
1722102115Srwatson
1723102115Srwatson	if (!mac_biba_dominate_single(subj, obj))
1724102115Srwatson		return (EACCES);
1725102115Srwatson
1726102115Srwatson	return (0);
1727102115Srwatson}
1728102115Srwatson
1729102115Srwatsonstatic int
1730101099Srwatsonmac_biba_check_proc_debug(struct ucred *cred, struct proc *proc)
1731101099Srwatson{
1732101099Srwatson	struct mac_biba *subj, *obj;
1733101099Srwatson
1734101099Srwatson	if (!mac_biba_enabled)
1735101099Srwatson		return (0);
1736101099Srwatson
1737101099Srwatson	subj = SLOT(&cred->cr_label);
1738101099Srwatson	obj = SLOT(&proc->p_ucred->cr_label);
1739101099Srwatson
1740101099Srwatson	/* XXX: range checks */
1741101099Srwatson	if (!mac_biba_dominate_single(obj, subj))
1742101099Srwatson		return (ESRCH);
1743101099Srwatson	if (!mac_biba_dominate_single(subj, obj))
1744101099Srwatson		return (EACCES);
1745101099Srwatson
1746101099Srwatson	return (0);
1747101099Srwatson}
1748101099Srwatson
1749101099Srwatsonstatic int
1750101099Srwatsonmac_biba_check_proc_sched(struct ucred *cred, struct proc *proc)
1751101099Srwatson{
1752101099Srwatson	struct mac_biba *subj, *obj;
1753103759Srwatson
1754101099Srwatson	if (!mac_biba_enabled)
1755101099Srwatson		return (0);
1756101099Srwatson
1757101099Srwatson	subj = SLOT(&cred->cr_label);
1758101099Srwatson	obj = SLOT(&proc->p_ucred->cr_label);
1759103759Srwatson
1760101099Srwatson	/* XXX: range checks */
1761101099Srwatson	if (!mac_biba_dominate_single(obj, subj))
1762101099Srwatson		return (ESRCH);
1763101099Srwatson	if (!mac_biba_dominate_single(subj, obj))
1764101099Srwatson		return (EACCES);
1765101099Srwatson
1766101099Srwatson	return (0);
1767101099Srwatson}
1768101099Srwatson
1769101099Srwatsonstatic int
1770101099Srwatsonmac_biba_check_proc_signal(struct ucred *cred, struct proc *proc, int signum)
1771101099Srwatson{
1772101099Srwatson	struct mac_biba *subj, *obj;
1773103759Srwatson
1774101099Srwatson	if (!mac_biba_enabled)
1775101099Srwatson		return (0);
1776101099Srwatson
1777101099Srwatson	subj = SLOT(&cred->cr_label);
1778101099Srwatson	obj = SLOT(&proc->p_ucred->cr_label);
1779103759Srwatson
1780101099Srwatson	/* XXX: range checks */
1781101099Srwatson	if (!mac_biba_dominate_single(obj, subj))
1782101099Srwatson		return (ESRCH);
1783101099Srwatson	if (!mac_biba_dominate_single(subj, obj))
1784101099Srwatson		return (EACCES);
1785101099Srwatson
1786101099Srwatson	return (0);
1787101099Srwatson}
1788101099Srwatson
1789101099Srwatsonstatic int
1790101934Srwatsonmac_biba_check_socket_deliver(struct socket *so, struct label *socketlabel,
1791101099Srwatson    struct mbuf *m, struct label *mbuflabel)
1792101099Srwatson{
1793101099Srwatson	struct mac_biba *p, *s;
1794101099Srwatson
1795101099Srwatson	if (!mac_biba_enabled)
1796101099Srwatson		return (0);
1797101099Srwatson
1798101099Srwatson	p = SLOT(mbuflabel);
1799101099Srwatson	s = SLOT(socketlabel);
1800101099Srwatson
1801101099Srwatson	return (mac_biba_equal_single(p, s) ? 0 : EACCES);
1802101099Srwatson}
1803101099Srwatson
1804101099Srwatsonstatic int
1805101099Srwatsonmac_biba_check_socket_relabel(struct ucred *cred, struct socket *socket,
1806101099Srwatson    struct label *socketlabel, struct label *newlabel)
1807101099Srwatson{
1808101099Srwatson	struct mac_biba *subj, *obj, *new;
1809105634Srwatson	int error;
1810101099Srwatson
1811101099Srwatson	new = SLOT(newlabel);
1812101099Srwatson	subj = SLOT(&cred->cr_label);
1813101099Srwatson	obj = SLOT(socketlabel);
1814101099Srwatson
1815101099Srwatson	/*
1816105634Srwatson	 * If there is a Biba label update for the socket, it may be
1817105634Srwatson	 * an update of single.
1818101099Srwatson	 */
1819105634Srwatson	error = biba_atmostflags(new, MAC_BIBA_FLAG_SINGLE);
1820105634Srwatson	if (error)
1821105634Srwatson		return (error);
1822101099Srwatson
1823101099Srwatson	/*
1824105634Srwatson	 * To relabel a socket, the old socket single must be in the subject
1825101099Srwatson	 * range.
1826101099Srwatson	 */
1827105634Srwatson	if (!mac_biba_single_in_range(obj, subj))
1828101099Srwatson		return (EPERM);
1829101099Srwatson
1830101099Srwatson	/*
1831105634Srwatson	 * If the Biba label is to be changed, authorize as appropriate.
1832101099Srwatson	 */
1833105634Srwatson	if (new->mb_flags & MAC_BIBA_FLAG_SINGLE) {
1834105634Srwatson		/*
1835105634Srwatson		 * To relabel a socket, the new socket single must be in
1836105634Srwatson		 * the subject range.
1837105634Srwatson		 */
1838105634Srwatson		if (!mac_biba_single_in_range(new, subj))
1839105634Srwatson			return (EPERM);
1840101099Srwatson
1841105634Srwatson		/*
1842105634Srwatson		 * To change the Biba label on the socket to contain EQUAL,
1843105634Srwatson		 * the subject must have appropriate privilege.
1844105634Srwatson		 */
1845105634Srwatson		if (mac_biba_contains_equal(new)) {
1846106090Srwatson			error = mac_biba_subject_privileged(subj);
1847105634Srwatson			if (error)
1848105634Srwatson				return (error);
1849105634Srwatson		}
1850105634Srwatson	}
1851105634Srwatson
1852101099Srwatson	return (0);
1853101099Srwatson}
1854101099Srwatson
1855101099Srwatsonstatic int
1856101099Srwatsonmac_biba_check_socket_visible(struct ucred *cred, struct socket *socket,
1857101099Srwatson    struct label *socketlabel)
1858101099Srwatson{
1859101099Srwatson	struct mac_biba *subj, *obj;
1860101099Srwatson
1861105722Srwatson	if (!mac_biba_enabled)
1862105722Srwatson		return (0);
1863105722Srwatson
1864101099Srwatson	subj = SLOT(&cred->cr_label);
1865101099Srwatson	obj = SLOT(socketlabel);
1866101099Srwatson
1867101099Srwatson	if (!mac_biba_dominate_single(obj, subj))
1868101099Srwatson		return (ENOENT);
1869101099Srwatson
1870101099Srwatson	return (0);
1871101099Srwatson}
1872101099Srwatson
1873101099Srwatsonstatic int
1874101099Srwatsonmac_biba_check_vnode_chdir(struct ucred *cred, struct vnode *dvp,
1875101099Srwatson    struct label *dlabel)
1876101099Srwatson{
1877101099Srwatson	struct mac_biba *subj, *obj;
1878101099Srwatson
1879101099Srwatson	if (!mac_biba_enabled)
1880101099Srwatson		return (0);
1881101099Srwatson
1882101099Srwatson	subj = SLOT(&cred->cr_label);
1883101099Srwatson	obj = SLOT(dlabel);
1884101099Srwatson
1885101099Srwatson	if (!mac_biba_dominate_single(obj, subj))
1886101099Srwatson		return (EACCES);
1887101099Srwatson
1888101099Srwatson	return (0);
1889101099Srwatson}
1890101099Srwatson
1891101099Srwatsonstatic int
1892101099Srwatsonmac_biba_check_vnode_chroot(struct ucred *cred, struct vnode *dvp,
1893101099Srwatson    struct label *dlabel)
1894101099Srwatson{
1895101099Srwatson	struct mac_biba *subj, *obj;
1896101099Srwatson
1897101099Srwatson	if (!mac_biba_enabled)
1898101099Srwatson		return (0);
1899101099Srwatson
1900101099Srwatson	subj = SLOT(&cred->cr_label);
1901101099Srwatson	obj = SLOT(dlabel);
1902101099Srwatson
1903101099Srwatson	if (!mac_biba_dominate_single(obj, subj))
1904101099Srwatson		return (EACCES);
1905101099Srwatson
1906101099Srwatson	return (0);
1907101099Srwatson}
1908101099Srwatson
1909101099Srwatsonstatic int
1910101099Srwatsonmac_biba_check_vnode_create(struct ucred *cred, struct vnode *dvp,
1911101099Srwatson    struct label *dlabel, struct componentname *cnp, struct vattr *vap)
1912101099Srwatson{
1913101099Srwatson	struct mac_biba *subj, *obj;
1914101099Srwatson
1915101099Srwatson	if (!mac_biba_enabled)
1916101099Srwatson		return (0);
1917101099Srwatson
1918101099Srwatson	subj = SLOT(&cred->cr_label);
1919101099Srwatson	obj = SLOT(dlabel);
1920101099Srwatson
1921101099Srwatson	if (!mac_biba_dominate_single(subj, obj))
1922101099Srwatson		return (EACCES);
1923101099Srwatson
1924101099Srwatson	return (0);
1925101099Srwatson}
1926101099Srwatson
1927101099Srwatsonstatic int
1928101099Srwatsonmac_biba_check_vnode_delete(struct ucred *cred, struct vnode *dvp,
1929101099Srwatson    struct label *dlabel, struct vnode *vp, struct label *label,
1930101099Srwatson    struct componentname *cnp)
1931101099Srwatson{
1932101099Srwatson	struct mac_biba *subj, *obj;
1933101099Srwatson
1934101099Srwatson	if (!mac_biba_enabled)
1935101099Srwatson		return (0);
1936101099Srwatson
1937101099Srwatson	subj = SLOT(&cred->cr_label);
1938101099Srwatson	obj = SLOT(dlabel);
1939101099Srwatson
1940101099Srwatson	if (!mac_biba_dominate_single(subj, obj))
1941101099Srwatson		return (EACCES);
1942101099Srwatson
1943101099Srwatson	obj = SLOT(label);
1944101099Srwatson
1945101099Srwatson	if (!mac_biba_dominate_single(subj, obj))
1946101099Srwatson		return (EACCES);
1947101099Srwatson
1948101099Srwatson	return (0);
1949101099Srwatson}
1950101099Srwatson
1951101099Srwatsonstatic int
1952101099Srwatsonmac_biba_check_vnode_deleteacl(struct ucred *cred, struct vnode *vp,
1953101099Srwatson    struct label *label, acl_type_t type)
1954101099Srwatson{
1955101099Srwatson	struct mac_biba *subj, *obj;
1956101099Srwatson
1957101099Srwatson	if (!mac_biba_enabled)
1958101099Srwatson		return (0);
1959101099Srwatson
1960101099Srwatson	subj = SLOT(&cred->cr_label);
1961101099Srwatson	obj = SLOT(label);
1962101099Srwatson
1963101099Srwatson	if (!mac_biba_dominate_single(subj, obj))
1964101099Srwatson		return (EACCES);
1965101099Srwatson
1966101099Srwatson	return (0);
1967101099Srwatson}
1968101099Srwatson
1969101099Srwatsonstatic int
1970101099Srwatsonmac_biba_check_vnode_exec(struct ucred *cred, struct vnode *vp,
1971101099Srwatson    struct label *label)
1972101099Srwatson{
1973101099Srwatson	struct mac_biba *subj, *obj;
1974101099Srwatson
1975101099Srwatson	if (!mac_biba_enabled)
1976101099Srwatson		return (0);
1977101099Srwatson
1978101099Srwatson	subj = SLOT(&cred->cr_label);
1979101099Srwatson	obj = SLOT(label);
1980101099Srwatson
1981101099Srwatson	if (!mac_biba_dominate_single(obj, subj))
1982101099Srwatson		return (EACCES);
1983101099Srwatson
1984101099Srwatson	return (0);
1985101099Srwatson}
1986101099Srwatson
1987101099Srwatsonstatic int
1988101099Srwatsonmac_biba_check_vnode_getacl(struct ucred *cred, struct vnode *vp,
1989101099Srwatson    struct label *label, acl_type_t type)
1990101099Srwatson{
1991101099Srwatson	struct mac_biba *subj, *obj;
1992101099Srwatson
1993101099Srwatson	if (!mac_biba_enabled)
1994101099Srwatson		return (0);
1995101099Srwatson
1996101099Srwatson	subj = SLOT(&cred->cr_label);
1997101099Srwatson	obj = SLOT(label);
1998101099Srwatson
1999101099Srwatson	if (!mac_biba_dominate_single(obj, subj))
2000101099Srwatson		return (EACCES);
2001101099Srwatson
2002101099Srwatson	return (0);
2003101099Srwatson}
2004101099Srwatson
2005101099Srwatsonstatic int
2006101099Srwatsonmac_biba_check_vnode_getextattr(struct ucred *cred, struct vnode *vp,
2007101099Srwatson    struct label *label, int attrnamespace, const char *name, struct uio *uio)
2008101099Srwatson{
2009101099Srwatson	struct mac_biba *subj, *obj;
2010101099Srwatson
2011101099Srwatson	if (!mac_biba_enabled)
2012101099Srwatson		return (0);
2013101099Srwatson
2014101099Srwatson	subj = SLOT(&cred->cr_label);
2015101099Srwatson	obj = SLOT(label);
2016101099Srwatson
2017101099Srwatson	if (!mac_biba_dominate_single(obj, subj))
2018101099Srwatson		return (EACCES);
2019101099Srwatson
2020101099Srwatson	return (0);
2021101099Srwatson}
2022101099Srwatson
2023101099Srwatsonstatic int
2024104530Srwatsonmac_biba_check_vnode_link(struct ucred *cred, struct vnode *dvp,
2025104530Srwatson    struct label *dlabel, struct vnode *vp, struct label *label,
2026104530Srwatson    struct componentname *cnp)
2027104530Srwatson{
2028104530Srwatson	struct mac_biba *subj, *obj;
2029104530Srwatson
2030104530Srwatson	if (!mac_biba_enabled)
2031104530Srwatson		return (0);
2032104530Srwatson
2033104530Srwatson	subj = SLOT(&cred->cr_label);
2034104530Srwatson	obj = SLOT(dlabel);
2035104530Srwatson
2036104530Srwatson	if (!mac_biba_dominate_single(subj, obj))
2037104530Srwatson		return (EACCES);
2038104530Srwatson
2039104530Srwatson	obj = SLOT(label);
2040104530Srwatson
2041104530Srwatson	if (!mac_biba_dominate_single(subj, obj))
2042104530Srwatson		return (EACCES);
2043104530Srwatson
2044104530Srwatson	return (0);
2045104530Srwatson}
2046104530Srwatson
2047104530Srwatsonstatic int
2048103759Srwatsonmac_biba_check_vnode_lookup(struct ucred *cred, struct vnode *dvp,
2049101099Srwatson    struct label *dlabel, struct componentname *cnp)
2050101099Srwatson{
2051101099Srwatson	struct mac_biba *subj, *obj;
2052103759Srwatson
2053101099Srwatson	if (!mac_biba_enabled)
2054101099Srwatson		return (0);
2055103759Srwatson
2056101099Srwatson	subj = SLOT(&cred->cr_label);
2057101099Srwatson	obj = SLOT(dlabel);
2058103759Srwatson
2059101099Srwatson	if (!mac_biba_dominate_single(obj, subj))
2060101099Srwatson		return (EACCES);
2061101099Srwatson
2062103759Srwatson	return (0);
2063101099Srwatson}
2064101099Srwatson
2065101099Srwatsonstatic int
2066104546Srwatsonmac_biba_check_vnode_mmap(struct ucred *cred, struct vnode *vp,
2067104546Srwatson    struct label *label, int prot)
2068104546Srwatson{
2069104546Srwatson	struct mac_biba *subj, *obj;
2070104546Srwatson
2071104546Srwatson	/*
2072104546Srwatson	 * Rely on the use of open()-time protections to handle
2073104546Srwatson	 * non-revocation cases.
2074104546Srwatson	 */
2075105637Srwatson	if (!mac_biba_enabled || !revocation_enabled)
2076104546Srwatson		return (0);
2077104546Srwatson
2078104546Srwatson	subj = SLOT(&cred->cr_label);
2079104546Srwatson	obj = SLOT(label);
2080104546Srwatson
2081104546Srwatson	if (prot & (VM_PROT_READ | VM_PROT_EXECUTE)) {
2082104546Srwatson		if (!mac_biba_dominate_single(obj, subj))
2083104546Srwatson			return (EACCES);
2084104546Srwatson	}
2085104546Srwatson	if (prot & VM_PROT_WRITE) {
2086104546Srwatson		if (!mac_biba_dominate_single(subj, obj))
2087104546Srwatson			return (EACCES);
2088104546Srwatson	}
2089104546Srwatson
2090104569Srwatson	return (0);
2091104546Srwatson}
2092104546Srwatson
2093104546Srwatsonstatic int
2094101099Srwatsonmac_biba_check_vnode_open(struct ucred *cred, struct vnode *vp,
2095101099Srwatson    struct label *vnodelabel, mode_t acc_mode)
2096101099Srwatson{
2097101099Srwatson	struct mac_biba *subj, *obj;
2098101099Srwatson
2099101099Srwatson	if (!mac_biba_enabled)
2100101099Srwatson		return (0);
2101101099Srwatson
2102101099Srwatson	subj = SLOT(&cred->cr_label);
2103101099Srwatson	obj = SLOT(vnodelabel);
2104101099Srwatson
2105101099Srwatson	/* XXX privilege override for admin? */
2106101099Srwatson	if (acc_mode & (VREAD | VEXEC | VSTAT)) {
2107101099Srwatson		if (!mac_biba_dominate_single(obj, subj))
2108101099Srwatson			return (EACCES);
2109101099Srwatson	}
2110101099Srwatson	if (acc_mode & (VWRITE | VAPPEND | VADMIN)) {
2111101099Srwatson		if (!mac_biba_dominate_single(subj, obj))
2112101099Srwatson			return (EACCES);
2113101099Srwatson	}
2114101099Srwatson
2115101099Srwatson	return (0);
2116101099Srwatson}
2117101099Srwatson
2118101099Srwatsonstatic int
2119102129Srwatsonmac_biba_check_vnode_poll(struct ucred *active_cred, struct ucred *file_cred,
2120102129Srwatson    struct vnode *vp, struct label *label)
2121102112Srwatson{
2122102112Srwatson	struct mac_biba *subj, *obj;
2123102112Srwatson
2124105637Srwatson	if (!mac_biba_enabled || !revocation_enabled)
2125102112Srwatson		return (0);
2126102112Srwatson
2127102129Srwatson	subj = SLOT(&active_cred->cr_label);
2128102112Srwatson	obj = SLOT(label);
2129102112Srwatson
2130102112Srwatson	if (!mac_biba_dominate_single(obj, subj))
2131102112Srwatson		return (EACCES);
2132102112Srwatson
2133102112Srwatson	return (0);
2134102112Srwatson}
2135102112Srwatson
2136102112Srwatsonstatic int
2137102129Srwatsonmac_biba_check_vnode_read(struct ucred *active_cred, struct ucred *file_cred,
2138102129Srwatson    struct vnode *vp, struct label *label)
2139102112Srwatson{
2140102112Srwatson	struct mac_biba *subj, *obj;
2141102112Srwatson
2142105637Srwatson	if (!mac_biba_enabled || !revocation_enabled)
2143102112Srwatson		return (0);
2144102112Srwatson
2145102129Srwatson	subj = SLOT(&active_cred->cr_label);
2146102112Srwatson	obj = SLOT(label);
2147102112Srwatson
2148102112Srwatson	if (!mac_biba_dominate_single(obj, subj))
2149102112Srwatson		return (EACCES);
2150102112Srwatson
2151102112Srwatson	return (0);
2152102112Srwatson}
2153102112Srwatson
2154102112Srwatsonstatic int
2155101099Srwatsonmac_biba_check_vnode_readdir(struct ucred *cred, struct vnode *dvp,
2156101099Srwatson    struct label *dlabel)
2157101099Srwatson{
2158101099Srwatson	struct mac_biba *subj, *obj;
2159101099Srwatson
2160101099Srwatson	if (!mac_biba_enabled)
2161101099Srwatson		return (0);
2162101099Srwatson
2163101099Srwatson	subj = SLOT(&cred->cr_label);
2164101099Srwatson	obj = SLOT(dlabel);
2165101099Srwatson
2166101099Srwatson	if (!mac_biba_dominate_single(obj, subj))
2167101099Srwatson		return (EACCES);
2168101099Srwatson
2169101099Srwatson	return (0);
2170101099Srwatson}
2171101099Srwatson
2172101099Srwatsonstatic int
2173101099Srwatsonmac_biba_check_vnode_readlink(struct ucred *cred, struct vnode *vp,
2174101099Srwatson    struct label *label)
2175101099Srwatson{
2176101099Srwatson	struct mac_biba *subj, *obj;
2177101099Srwatson
2178101099Srwatson	if (!mac_biba_enabled)
2179101099Srwatson		return (0);
2180101099Srwatson
2181101099Srwatson	subj = SLOT(&cred->cr_label);
2182101099Srwatson	obj = SLOT(label);
2183101099Srwatson
2184101099Srwatson	if (!mac_biba_dominate_single(obj, subj))
2185101099Srwatson		return (EACCES);
2186101099Srwatson
2187101099Srwatson	return (0);
2188101099Srwatson}
2189101099Srwatson
2190101099Srwatsonstatic int
2191101099Srwatsonmac_biba_check_vnode_relabel(struct ucred *cred, struct vnode *vp,
2192101099Srwatson    struct label *vnodelabel, struct label *newlabel)
2193101099Srwatson{
2194101099Srwatson	struct mac_biba *old, *new, *subj;
2195105634Srwatson	int error;
2196101099Srwatson
2197101099Srwatson	old = SLOT(vnodelabel);
2198101099Srwatson	new = SLOT(newlabel);
2199101099Srwatson	subj = SLOT(&cred->cr_label);
2200101099Srwatson
2201101099Srwatson	/*
2202105634Srwatson	 * If there is a Biba label update for the vnode, it must be a
2203105634Srwatson	 * single label.
2204101099Srwatson	 */
2205105634Srwatson	error = biba_atmostflags(new, MAC_BIBA_FLAG_SINGLE);
2206105634Srwatson	if (error)
2207105634Srwatson		return (error);
2208101099Srwatson
2209101099Srwatson	/*
2210105634Srwatson	 * To perform a relabel of the vnode (Biba label or not), Biba must
2211105634Srwatson	 * authorize the relabel.
2212101099Srwatson	 */
2213105634Srwatson	if (!mac_biba_single_in_range(old, subj))
2214101099Srwatson		return (EPERM);
2215101099Srwatson
2216101099Srwatson	/*
2217105634Srwatson	 * If the Biba label is to be changed, authorize as appropriate.
2218101099Srwatson	 */
2219105634Srwatson	if (new->mb_flags & MAC_BIBA_FLAG_SINGLE) {
2220105634Srwatson		/*
2221105634Srwatson		 * To change the Biba label on a vnode, the new vnode label
2222105634Srwatson		 * must be in the subject range.
2223105634Srwatson		 */
2224105634Srwatson		if (!mac_biba_single_in_range(new, subj))
2225105634Srwatson			return (EPERM);
2226101099Srwatson
2227105634Srwatson		/*
2228105634Srwatson		 * To change the Biba label on the vnode to be EQUAL,
2229105634Srwatson		 * the subject must have appropriate privilege.
2230105634Srwatson		 */
2231105634Srwatson		if (mac_biba_contains_equal(new)) {
2232106090Srwatson			error = mac_biba_subject_privileged(subj);
2233105634Srwatson			if (error)
2234105634Srwatson				return (error);
2235105634Srwatson		}
2236105634Srwatson	}
2237105634Srwatson
2238105634Srwatson	return (0);
2239101099Srwatson}
2240101099Srwatson
2241101099Srwatsonstatic int
2242101099Srwatsonmac_biba_check_vnode_rename_from(struct ucred *cred, struct vnode *dvp,
2243101099Srwatson    struct label *dlabel, struct vnode *vp, struct label *label,
2244101099Srwatson    struct componentname *cnp)
2245101099Srwatson{
2246101099Srwatson	struct mac_biba *subj, *obj;
2247101099Srwatson
2248101099Srwatson	if (!mac_biba_enabled)
2249101099Srwatson		return (0);
2250101099Srwatson
2251101099Srwatson	subj = SLOT(&cred->cr_label);
2252101099Srwatson	obj = SLOT(dlabel);
2253101099Srwatson
2254101099Srwatson	if (!mac_biba_dominate_single(subj, obj))
2255101099Srwatson		return (EACCES);
2256101099Srwatson
2257101099Srwatson	obj = SLOT(label);
2258101099Srwatson
2259101099Srwatson	if (!mac_biba_dominate_single(subj, obj))
2260101099Srwatson		return (EACCES);
2261101099Srwatson
2262101099Srwatson	return (0);
2263101099Srwatson}
2264101099Srwatson
2265101099Srwatsonstatic int
2266101099Srwatsonmac_biba_check_vnode_rename_to(struct ucred *cred, struct vnode *dvp,
2267101099Srwatson    struct label *dlabel, struct vnode *vp, struct label *label, int samedir,
2268101099Srwatson    struct componentname *cnp)
2269101099Srwatson{
2270101099Srwatson	struct mac_biba *subj, *obj;
2271101099Srwatson
2272101099Srwatson	if (!mac_biba_enabled)
2273101099Srwatson		return (0);
2274101099Srwatson
2275101099Srwatson	subj = SLOT(&cred->cr_label);
2276101099Srwatson	obj = SLOT(dlabel);
2277101099Srwatson
2278101099Srwatson	if (!mac_biba_dominate_single(subj, obj))
2279101099Srwatson		return (EACCES);
2280101099Srwatson
2281101099Srwatson	if (vp != NULL) {
2282101099Srwatson		obj = SLOT(label);
2283101099Srwatson
2284101099Srwatson		if (!mac_biba_dominate_single(subj, obj))
2285101099Srwatson			return (EACCES);
2286101099Srwatson	}
2287101099Srwatson
2288101099Srwatson	return (0);
2289101099Srwatson}
2290101099Srwatson
2291101099Srwatsonstatic int
2292101099Srwatsonmac_biba_check_vnode_revoke(struct ucred *cred, struct vnode *vp,
2293101099Srwatson    struct label *label)
2294101099Srwatson{
2295101099Srwatson	struct mac_biba *subj, *obj;
2296101099Srwatson
2297101099Srwatson	if (!mac_biba_enabled)
2298101099Srwatson		return (0);
2299101099Srwatson
2300101099Srwatson	subj = SLOT(&cred->cr_label);
2301101099Srwatson	obj = SLOT(label);
2302101099Srwatson
2303101099Srwatson	if (!mac_biba_dominate_single(subj, obj))
2304101099Srwatson		return (EACCES);
2305101099Srwatson
2306101099Srwatson	return (0);
2307101099Srwatson}
2308101099Srwatson
2309101099Srwatsonstatic int
2310101099Srwatsonmac_biba_check_vnode_setacl(struct ucred *cred, struct vnode *vp,
2311101099Srwatson    struct label *label, acl_type_t type, struct acl *acl)
2312101099Srwatson{
2313101099Srwatson	struct mac_biba *subj, *obj;
2314101099Srwatson
2315101099Srwatson	if (!mac_biba_enabled)
2316101099Srwatson		return (0);
2317101099Srwatson
2318101099Srwatson	subj = SLOT(&cred->cr_label);
2319101099Srwatson	obj = SLOT(label);
2320101099Srwatson
2321101099Srwatson	if (!mac_biba_dominate_single(subj, obj))
2322101099Srwatson		return (EACCES);
2323101099Srwatson
2324101099Srwatson	return (0);
2325101099Srwatson}
2326101099Srwatson
2327101099Srwatsonstatic int
2328101099Srwatsonmac_biba_check_vnode_setextattr(struct ucred *cred, struct vnode *vp,
2329101099Srwatson    struct label *vnodelabel, int attrnamespace, const char *name,
2330101099Srwatson    struct uio *uio)
2331101099Srwatson{
2332101099Srwatson	struct mac_biba *subj, *obj;
2333101099Srwatson
2334101099Srwatson	if (!mac_biba_enabled)
2335101099Srwatson		return (0);
2336101099Srwatson
2337101099Srwatson	subj = SLOT(&cred->cr_label);
2338101099Srwatson	obj = SLOT(vnodelabel);
2339101099Srwatson
2340101099Srwatson	if (!mac_biba_dominate_single(subj, obj))
2341101099Srwatson		return (EACCES);
2342101099Srwatson
2343101099Srwatson	/* XXX: protect the MAC EA in a special way? */
2344101099Srwatson
2345101099Srwatson	return (0);
2346101099Srwatson}
2347101099Srwatson
2348101099Srwatsonstatic int
2349101099Srwatsonmac_biba_check_vnode_setflags(struct ucred *cred, struct vnode *vp,
2350101099Srwatson    struct label *vnodelabel, u_long flags)
2351101099Srwatson{
2352101099Srwatson	struct mac_biba *subj, *obj;
2353101099Srwatson
2354101099Srwatson	if (!mac_biba_enabled)
2355101099Srwatson		return (0);
2356101099Srwatson
2357101099Srwatson	subj = SLOT(&cred->cr_label);
2358101099Srwatson	obj = SLOT(vnodelabel);
2359101099Srwatson
2360101099Srwatson	if (!mac_biba_dominate_single(subj, obj))
2361101099Srwatson		return (EACCES);
2362101099Srwatson
2363101099Srwatson	return (0);
2364101099Srwatson}
2365101099Srwatson
2366101099Srwatsonstatic int
2367101099Srwatsonmac_biba_check_vnode_setmode(struct ucred *cred, struct vnode *vp,
2368101099Srwatson    struct label *vnodelabel, mode_t mode)
2369101099Srwatson{
2370101099Srwatson	struct mac_biba *subj, *obj;
2371101099Srwatson
2372101099Srwatson	if (!mac_biba_enabled)
2373101099Srwatson		return (0);
2374101099Srwatson
2375101099Srwatson	subj = SLOT(&cred->cr_label);
2376101099Srwatson	obj = SLOT(vnodelabel);
2377101099Srwatson
2378101099Srwatson	if (!mac_biba_dominate_single(subj, obj))
2379101099Srwatson		return (EACCES);
2380101099Srwatson
2381101099Srwatson	return (0);
2382101099Srwatson}
2383101099Srwatson
2384101099Srwatsonstatic int
2385101099Srwatsonmac_biba_check_vnode_setowner(struct ucred *cred, struct vnode *vp,
2386101099Srwatson    struct label *vnodelabel, uid_t uid, gid_t gid)
2387101099Srwatson{
2388101099Srwatson	struct mac_biba *subj, *obj;
2389101099Srwatson
2390101099Srwatson	if (!mac_biba_enabled)
2391101099Srwatson		return (0);
2392101099Srwatson
2393101099Srwatson	subj = SLOT(&cred->cr_label);
2394101099Srwatson	obj = SLOT(vnodelabel);
2395101099Srwatson
2396101099Srwatson	if (!mac_biba_dominate_single(subj, obj))
2397101099Srwatson		return (EACCES);
2398101099Srwatson
2399101099Srwatson	return (0);
2400101099Srwatson}
2401101099Srwatson
2402101099Srwatsonstatic int
2403101099Srwatsonmac_biba_check_vnode_setutimes(struct ucred *cred, struct vnode *vp,
2404101099Srwatson    struct label *vnodelabel, struct timespec atime, struct timespec mtime)
2405101099Srwatson{
2406101099Srwatson	struct mac_biba *subj, *obj;
2407101099Srwatson
2408101099Srwatson	if (!mac_biba_enabled)
2409101099Srwatson		return (0);
2410101099Srwatson
2411101099Srwatson	subj = SLOT(&cred->cr_label);
2412101099Srwatson	obj = SLOT(vnodelabel);
2413101099Srwatson
2414101099Srwatson	if (!mac_biba_dominate_single(subj, obj))
2415101099Srwatson		return (EACCES);
2416101099Srwatson
2417101099Srwatson	return (0);
2418101099Srwatson}
2419101099Srwatson
2420101099Srwatsonstatic int
2421102129Srwatsonmac_biba_check_vnode_stat(struct ucred *active_cred, struct ucred *file_cred,
2422102129Srwatson    struct vnode *vp, struct label *vnodelabel)
2423101099Srwatson{
2424101099Srwatson	struct mac_biba *subj, *obj;
2425101099Srwatson
2426101099Srwatson	if (!mac_biba_enabled)
2427101099Srwatson		return (0);
2428101099Srwatson
2429102129Srwatson	subj = SLOT(&active_cred->cr_label);
2430101099Srwatson	obj = SLOT(vnodelabel);
2431101099Srwatson
2432101099Srwatson	if (!mac_biba_dominate_single(obj, subj))
2433101099Srwatson		return (EACCES);
2434101099Srwatson
2435101099Srwatson	return (0);
2436101099Srwatson}
2437101099Srwatson
2438102112Srwatsonstatic int
2439102129Srwatsonmac_biba_check_vnode_write(struct ucred *active_cred,
2440102129Srwatson    struct ucred *file_cred, struct vnode *vp, struct label *label)
2441102112Srwatson{
2442102112Srwatson	struct mac_biba *subj, *obj;
2443102112Srwatson
2444105637Srwatson	if (!mac_biba_enabled || !revocation_enabled)
2445102112Srwatson		return (0);
2446102112Srwatson
2447102129Srwatson	subj = SLOT(&active_cred->cr_label);
2448102112Srwatson	obj = SLOT(label);
2449102112Srwatson
2450102112Srwatson	if (!mac_biba_dominate_single(subj, obj))
2451102112Srwatson		return (EACCES);
2452102112Srwatson
2453102112Srwatson	return (0);
2454102112Srwatson}
2455102112Srwatson
2456101099Srwatsonstatic struct mac_policy_op_entry mac_biba_ops[] =
2457101099Srwatson{
2458101099Srwatson	{ MAC_DESTROY,
2459101099Srwatson	    (macop_t)mac_biba_destroy },
2460101099Srwatson	{ MAC_INIT,
2461101099Srwatson	    (macop_t)mac_biba_init },
2462104514Srwatson	{ MAC_INIT_BPFDESC_LABEL,
2463104514Srwatson	    (macop_t)mac_biba_init_label },
2464104514Srwatson	{ MAC_INIT_CRED_LABEL,
2465104514Srwatson	    (macop_t)mac_biba_init_label },
2466104514Srwatson	{ MAC_INIT_DEVFSDIRENT_LABEL,
2467104514Srwatson	    (macop_t)mac_biba_init_label },
2468104514Srwatson	{ MAC_INIT_IFNET_LABEL,
2469104514Srwatson	    (macop_t)mac_biba_init_label },
2470104514Srwatson	{ MAC_INIT_IPQ_LABEL,
2471104514Srwatson	    (macop_t)mac_biba_init_label },
2472104514Srwatson	{ MAC_INIT_MBUF_LABEL,
2473104514Srwatson	    (macop_t)mac_biba_init_label_waitcheck },
2474104514Srwatson	{ MAC_INIT_MOUNT_LABEL,
2475104514Srwatson	    (macop_t)mac_biba_init_label },
2476104514Srwatson	{ MAC_INIT_MOUNT_FS_LABEL,
2477104514Srwatson	    (macop_t)mac_biba_init_label },
2478104514Srwatson	{ MAC_INIT_PIPE_LABEL,
2479104514Srwatson	    (macop_t)mac_biba_init_label },
2480104514Srwatson	{ MAC_INIT_SOCKET_LABEL,
2481104541Srwatson	    (macop_t)mac_biba_init_label_waitcheck },
2482104514Srwatson	{ MAC_INIT_SOCKET_PEER_LABEL,
2483104541Srwatson	    (macop_t)mac_biba_init_label_waitcheck },
2484104514Srwatson	{ MAC_INIT_VNODE_LABEL,
2485104514Srwatson	    (macop_t)mac_biba_init_label },
2486104514Srwatson	{ MAC_DESTROY_BPFDESC_LABEL,
2487104514Srwatson	    (macop_t)mac_biba_destroy_label },
2488104514Srwatson	{ MAC_DESTROY_CRED_LABEL,
2489104514Srwatson	    (macop_t)mac_biba_destroy_label },
2490104514Srwatson	{ MAC_DESTROY_DEVFSDIRENT_LABEL,
2491104514Srwatson	    (macop_t)mac_biba_destroy_label },
2492104514Srwatson	{ MAC_DESTROY_IFNET_LABEL,
2493104514Srwatson	    (macop_t)mac_biba_destroy_label },
2494104514Srwatson	{ MAC_DESTROY_IPQ_LABEL,
2495104514Srwatson	    (macop_t)mac_biba_destroy_label },
2496104514Srwatson	{ MAC_DESTROY_MBUF_LABEL,
2497104514Srwatson	    (macop_t)mac_biba_destroy_label },
2498104514Srwatson	{ MAC_DESTROY_MOUNT_LABEL,
2499104514Srwatson	    (macop_t)mac_biba_destroy_label },
2500104514Srwatson	{ MAC_DESTROY_MOUNT_FS_LABEL,
2501104514Srwatson	    (macop_t)mac_biba_destroy_label },
2502104514Srwatson	{ MAC_DESTROY_PIPE_LABEL,
2503104514Srwatson	    (macop_t)mac_biba_destroy_label },
2504104514Srwatson	{ MAC_DESTROY_SOCKET_LABEL,
2505104514Srwatson	    (macop_t)mac_biba_destroy_label },
2506104514Srwatson	{ MAC_DESTROY_SOCKET_PEER_LABEL,
2507104514Srwatson	    (macop_t)mac_biba_destroy_label },
2508104514Srwatson	{ MAC_DESTROY_VNODE_LABEL,
2509104514Srwatson	    (macop_t)mac_biba_destroy_label },
2510105696Srwatson	{ MAC_COPY_PIPE_LABEL,
2511105696Srwatson	    (macop_t)mac_biba_copy_label },
2512105696Srwatson	{ MAC_COPY_VNODE_LABEL,
2513105696Srwatson	    (macop_t)mac_biba_copy_label },
2514105696Srwatson	{ MAC_EXTERNALIZE_CRED_LABEL,
2515105696Srwatson	    (macop_t)mac_biba_externalize_label },
2516105696Srwatson	{ MAC_EXTERNALIZE_IFNET_LABEL,
2517105696Srwatson	    (macop_t)mac_biba_externalize_label },
2518105696Srwatson	{ MAC_EXTERNALIZE_PIPE_LABEL,
2519105696Srwatson	    (macop_t)mac_biba_externalize_label },
2520105696Srwatson	{ MAC_EXTERNALIZE_SOCKET_LABEL,
2521105696Srwatson	    (macop_t)mac_biba_externalize_label },
2522105696Srwatson	{ MAC_EXTERNALIZE_SOCKET_PEER_LABEL,
2523105696Srwatson	    (macop_t)mac_biba_externalize_label },
2524105696Srwatson	{ MAC_EXTERNALIZE_VNODE_LABEL,
2525105696Srwatson	    (macop_t)mac_biba_externalize_label },
2526105696Srwatson	{ MAC_INTERNALIZE_CRED_LABEL,
2527105696Srwatson	    (macop_t)mac_biba_internalize_label },
2528105696Srwatson	{ MAC_INTERNALIZE_IFNET_LABEL,
2529105696Srwatson	    (macop_t)mac_biba_internalize_label },
2530105696Srwatson	{ MAC_INTERNALIZE_PIPE_LABEL,
2531105696Srwatson	    (macop_t)mac_biba_internalize_label },
2532105696Srwatson	{ MAC_INTERNALIZE_SOCKET_LABEL,
2533105696Srwatson	    (macop_t)mac_biba_internalize_label },
2534105696Srwatson	{ MAC_INTERNALIZE_VNODE_LABEL,
2535105696Srwatson	    (macop_t)mac_biba_internalize_label },
2536101099Srwatson	{ MAC_CREATE_DEVFS_DEVICE,
2537101099Srwatson	    (macop_t)mac_biba_create_devfs_device },
2538101099Srwatson	{ MAC_CREATE_DEVFS_DIRECTORY,
2539101099Srwatson	    (macop_t)mac_biba_create_devfs_directory },
2540104535Srwatson	{ MAC_CREATE_DEVFS_SYMLINK,
2541104535Srwatson	    (macop_t)mac_biba_create_devfs_symlink },
2542101099Srwatson	{ MAC_CREATE_DEVFS_VNODE,
2543101099Srwatson	    (macop_t)mac_biba_create_devfs_vnode },
2544101099Srwatson	{ MAC_CREATE_MOUNT,
2545101099Srwatson	    (macop_t)mac_biba_create_mount },
2546101099Srwatson	{ MAC_CREATE_ROOT_MOUNT,
2547101099Srwatson	    (macop_t)mac_biba_create_root_mount },
2548101099Srwatson	{ MAC_RELABEL_VNODE,
2549101099Srwatson	    (macop_t)mac_biba_relabel_vnode },
2550101099Srwatson	{ MAC_UPDATE_DEVFSDIRENT,
2551101099Srwatson	    (macop_t)mac_biba_update_devfsdirent },
2552105988Srwatson	{ MAC_ASSOCIATE_VNODE_DEVFS,
2553105988Srwatson	    (macop_t)mac_biba_associate_vnode_devfs },
2554105988Srwatson	{ MAC_ASSOCIATE_VNODE_EXTATTR,
2555105988Srwatson	    (macop_t)mac_biba_associate_vnode_extattr },
2556105988Srwatson	{ MAC_ASSOCIATE_VNODE_SINGLELABEL,
2557105988Srwatson	    (macop_t)mac_biba_associate_vnode_singlelabel },
2558105988Srwatson	{ MAC_CREATE_VNODE_EXTATTR,
2559105988Srwatson	    (macop_t)mac_biba_create_vnode_extattr },
2560105988Srwatson	{ MAC_SETLABEL_VNODE_EXTATTR,
2561105988Srwatson	    (macop_t)mac_biba_setlabel_vnode_extattr },
2562101099Srwatson	{ MAC_CREATE_MBUF_FROM_SOCKET,
2563101099Srwatson	    (macop_t)mac_biba_create_mbuf_from_socket },
2564101099Srwatson	{ MAC_CREATE_PIPE,
2565101099Srwatson	    (macop_t)mac_biba_create_pipe },
2566101099Srwatson	{ MAC_CREATE_SOCKET,
2567101099Srwatson	    (macop_t)mac_biba_create_socket },
2568101099Srwatson	{ MAC_CREATE_SOCKET_FROM_SOCKET,
2569101099Srwatson	    (macop_t)mac_biba_create_socket_from_socket },
2570101099Srwatson	{ MAC_RELABEL_PIPE,
2571101099Srwatson	    (macop_t)mac_biba_relabel_pipe },
2572101099Srwatson	{ MAC_RELABEL_SOCKET,
2573101099Srwatson	    (macop_t)mac_biba_relabel_socket },
2574101099Srwatson	{ MAC_SET_SOCKET_PEER_FROM_MBUF,
2575101099Srwatson	    (macop_t)mac_biba_set_socket_peer_from_mbuf },
2576101099Srwatson	{ MAC_SET_SOCKET_PEER_FROM_SOCKET,
2577101099Srwatson	    (macop_t)mac_biba_set_socket_peer_from_socket },
2578101099Srwatson	{ MAC_CREATE_BPFDESC,
2579101099Srwatson	    (macop_t)mac_biba_create_bpfdesc },
2580101099Srwatson	{ MAC_CREATE_DATAGRAM_FROM_IPQ,
2581101099Srwatson	    (macop_t)mac_biba_create_datagram_from_ipq },
2582101099Srwatson	{ MAC_CREATE_FRAGMENT,
2583101099Srwatson	    (macop_t)mac_biba_create_fragment },
2584101099Srwatson	{ MAC_CREATE_IFNET,
2585101099Srwatson	    (macop_t)mac_biba_create_ifnet },
2586101099Srwatson	{ MAC_CREATE_IPQ,
2587101099Srwatson	    (macop_t)mac_biba_create_ipq },
2588101099Srwatson	{ MAC_CREATE_MBUF_FROM_MBUF,
2589101099Srwatson	    (macop_t)mac_biba_create_mbuf_from_mbuf },
2590101099Srwatson	{ MAC_CREATE_MBUF_LINKLAYER,
2591101099Srwatson	    (macop_t)mac_biba_create_mbuf_linklayer },
2592101099Srwatson	{ MAC_CREATE_MBUF_FROM_BPFDESC,
2593101099Srwatson	    (macop_t)mac_biba_create_mbuf_from_bpfdesc },
2594101099Srwatson	{ MAC_CREATE_MBUF_FROM_IFNET,
2595101099Srwatson	    (macop_t)mac_biba_create_mbuf_from_ifnet },
2596101099Srwatson	{ MAC_CREATE_MBUF_MULTICAST_ENCAP,
2597101099Srwatson	    (macop_t)mac_biba_create_mbuf_multicast_encap },
2598101099Srwatson	{ MAC_CREATE_MBUF_NETLAYER,
2599101099Srwatson	    (macop_t)mac_biba_create_mbuf_netlayer },
2600101099Srwatson	{ MAC_FRAGMENT_MATCH,
2601101099Srwatson	    (macop_t)mac_biba_fragment_match },
2602101099Srwatson	{ MAC_RELABEL_IFNET,
2603101099Srwatson	    (macop_t)mac_biba_relabel_ifnet },
2604101099Srwatson	{ MAC_UPDATE_IPQ,
2605101099Srwatson	    (macop_t)mac_biba_update_ipq },
2606101099Srwatson	{ MAC_CREATE_CRED,
2607101099Srwatson	    (macop_t)mac_biba_create_cred },
2608101099Srwatson	{ MAC_EXECVE_TRANSITION,
2609101099Srwatson	    (macop_t)mac_biba_execve_transition },
2610101099Srwatson	{ MAC_EXECVE_WILL_TRANSITION,
2611101099Srwatson	    (macop_t)mac_biba_execve_will_transition },
2612101099Srwatson	{ MAC_CREATE_PROC0,
2613101099Srwatson	    (macop_t)mac_biba_create_proc0 },
2614101099Srwatson	{ MAC_CREATE_PROC1,
2615101099Srwatson	    (macop_t)mac_biba_create_proc1 },
2616101099Srwatson	{ MAC_RELABEL_CRED,
2617101099Srwatson	    (macop_t)mac_biba_relabel_cred },
2618101099Srwatson	{ MAC_CHECK_BPFDESC_RECEIVE,
2619101099Srwatson	    (macop_t)mac_biba_check_bpfdesc_receive },
2620101099Srwatson	{ MAC_CHECK_CRED_RELABEL,
2621101099Srwatson	    (macop_t)mac_biba_check_cred_relabel },
2622101099Srwatson	{ MAC_CHECK_CRED_VISIBLE,
2623101099Srwatson	    (macop_t)mac_biba_check_cred_visible },
2624101099Srwatson	{ MAC_CHECK_IFNET_RELABEL,
2625101099Srwatson	    (macop_t)mac_biba_check_ifnet_relabel },
2626101099Srwatson	{ MAC_CHECK_IFNET_TRANSMIT,
2627101099Srwatson	    (macop_t)mac_biba_check_ifnet_transmit },
2628101099Srwatson	{ MAC_CHECK_MOUNT_STAT,
2629101099Srwatson	    (macop_t)mac_biba_check_mount_stat },
2630101099Srwatson	{ MAC_CHECK_PIPE_IOCTL,
2631101099Srwatson	    (macop_t)mac_biba_check_pipe_ioctl },
2632102115Srwatson	{ MAC_CHECK_PIPE_POLL,
2633102115Srwatson	    (macop_t)mac_biba_check_pipe_poll },
2634102115Srwatson	{ MAC_CHECK_PIPE_READ,
2635102115Srwatson	    (macop_t)mac_biba_check_pipe_read },
2636101099Srwatson	{ MAC_CHECK_PIPE_RELABEL,
2637101099Srwatson	    (macop_t)mac_biba_check_pipe_relabel },
2638102115Srwatson	{ MAC_CHECK_PIPE_STAT,
2639102115Srwatson	    (macop_t)mac_biba_check_pipe_stat },
2640102115Srwatson	{ MAC_CHECK_PIPE_WRITE,
2641102115Srwatson	    (macop_t)mac_biba_check_pipe_write },
2642101099Srwatson	{ MAC_CHECK_PROC_DEBUG,
2643101099Srwatson	    (macop_t)mac_biba_check_proc_debug },
2644101099Srwatson	{ MAC_CHECK_PROC_SCHED,
2645101099Srwatson	    (macop_t)mac_biba_check_proc_sched },
2646101099Srwatson	{ MAC_CHECK_PROC_SIGNAL,
2647101099Srwatson	    (macop_t)mac_biba_check_proc_signal },
2648101934Srwatson	{ MAC_CHECK_SOCKET_DELIVER,
2649101934Srwatson	    (macop_t)mac_biba_check_socket_deliver },
2650101099Srwatson	{ MAC_CHECK_SOCKET_RELABEL,
2651101099Srwatson	    (macop_t)mac_biba_check_socket_relabel },
2652101099Srwatson	{ MAC_CHECK_SOCKET_VISIBLE,
2653101099Srwatson	    (macop_t)mac_biba_check_socket_visible },
2654101099Srwatson	{ MAC_CHECK_VNODE_ACCESS,
2655105635Srwatson	    (macop_t)mac_biba_check_vnode_open },
2656101099Srwatson	{ MAC_CHECK_VNODE_CHDIR,
2657101099Srwatson	    (macop_t)mac_biba_check_vnode_chdir },
2658101099Srwatson	{ MAC_CHECK_VNODE_CHROOT,
2659101099Srwatson	    (macop_t)mac_biba_check_vnode_chroot },
2660101099Srwatson	{ MAC_CHECK_VNODE_CREATE,
2661101099Srwatson	    (macop_t)mac_biba_check_vnode_create },
2662101099Srwatson	{ MAC_CHECK_VNODE_DELETE,
2663101099Srwatson	    (macop_t)mac_biba_check_vnode_delete },
2664101099Srwatson	{ MAC_CHECK_VNODE_DELETEACL,
2665101099Srwatson	    (macop_t)mac_biba_check_vnode_deleteacl },
2666101099Srwatson	{ MAC_CHECK_VNODE_EXEC,
2667101099Srwatson	    (macop_t)mac_biba_check_vnode_exec },
2668101099Srwatson	{ MAC_CHECK_VNODE_GETACL,
2669101099Srwatson	    (macop_t)mac_biba_check_vnode_getacl },
2670101099Srwatson	{ MAC_CHECK_VNODE_GETEXTATTR,
2671101099Srwatson	    (macop_t)mac_biba_check_vnode_getextattr },
2672104530Srwatson	{ MAC_CHECK_VNODE_LINK,
2673104530Srwatson	    (macop_t)mac_biba_check_vnode_link },
2674101099Srwatson	{ MAC_CHECK_VNODE_LOOKUP,
2675101099Srwatson	    (macop_t)mac_biba_check_vnode_lookup },
2676104546Srwatson	{ MAC_CHECK_VNODE_MMAP,
2677104546Srwatson	    (macop_t)mac_biba_check_vnode_mmap },
2678104546Srwatson	{ MAC_CHECK_VNODE_MPROTECT,
2679104546Srwatson	    (macop_t)mac_biba_check_vnode_mmap },
2680101099Srwatson	{ MAC_CHECK_VNODE_OPEN,
2681101099Srwatson	    (macop_t)mac_biba_check_vnode_open },
2682102112Srwatson	{ MAC_CHECK_VNODE_POLL,
2683102112Srwatson	    (macop_t)mac_biba_check_vnode_poll },
2684102112Srwatson	{ MAC_CHECK_VNODE_READ,
2685102112Srwatson	    (macop_t)mac_biba_check_vnode_read },
2686101099Srwatson	{ MAC_CHECK_VNODE_READDIR,
2687101099Srwatson	    (macop_t)mac_biba_check_vnode_readdir },
2688101099Srwatson	{ MAC_CHECK_VNODE_READLINK,
2689101099Srwatson	    (macop_t)mac_biba_check_vnode_readlink },
2690101099Srwatson	{ MAC_CHECK_VNODE_RELABEL,
2691101099Srwatson	    (macop_t)mac_biba_check_vnode_relabel },
2692101099Srwatson	{ MAC_CHECK_VNODE_RENAME_FROM,
2693101099Srwatson	    (macop_t)mac_biba_check_vnode_rename_from },
2694101099Srwatson	{ MAC_CHECK_VNODE_RENAME_TO,
2695101099Srwatson	    (macop_t)mac_biba_check_vnode_rename_to },
2696101099Srwatson	{ MAC_CHECK_VNODE_REVOKE,
2697101099Srwatson	    (macop_t)mac_biba_check_vnode_revoke },
2698101099Srwatson	{ MAC_CHECK_VNODE_SETACL,
2699101099Srwatson	    (macop_t)mac_biba_check_vnode_setacl },
2700101099Srwatson	{ MAC_CHECK_VNODE_SETEXTATTR,
2701101099Srwatson	    (macop_t)mac_biba_check_vnode_setextattr },
2702101099Srwatson	{ MAC_CHECK_VNODE_SETFLAGS,
2703101099Srwatson	    (macop_t)mac_biba_check_vnode_setflags },
2704101099Srwatson	{ MAC_CHECK_VNODE_SETMODE,
2705101099Srwatson	    (macop_t)mac_biba_check_vnode_setmode },
2706101099Srwatson	{ MAC_CHECK_VNODE_SETOWNER,
2707101099Srwatson	    (macop_t)mac_biba_check_vnode_setowner },
2708101099Srwatson	{ MAC_CHECK_VNODE_SETUTIMES,
2709101099Srwatson	    (macop_t)mac_biba_check_vnode_setutimes },
2710101099Srwatson	{ MAC_CHECK_VNODE_STAT,
2711101099Srwatson	    (macop_t)mac_biba_check_vnode_stat },
2712102112Srwatson	{ MAC_CHECK_VNODE_WRITE,
2713102112Srwatson	    (macop_t)mac_biba_check_vnode_write },
2714101099Srwatson	{ MAC_OP_LAST, NULL }
2715101099Srwatson};
2716101099Srwatson
2717101099SrwatsonMAC_POLICY_SET(mac_biba_ops, trustedbsd_mac_biba, "TrustedBSD MAC/Biba",
2718101099Srwatson    MPC_LOADTIME_FLAG_NOTLATE, &mac_biba_slot);
2719