mac_biba.c revision 105638
1/*-
2 * Copyright (c) 1999, 2000, 2001, 2002 Robert N. M. Watson
3 * Copyright (c) 2001, 2002 Networks Associates Technology, Inc.
4 * All rights reserved.
5 *
6 * This software was developed by Robert Watson for the TrustedBSD Project.
7 *
8 * This software was developed for the FreeBSD Project in part by NAI Labs,
9 * the Security Research Division of Network Associates, Inc. under
10 * DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA
11 * CHATS research program.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 *    notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 *    notice, this list of conditions and the following disclaimer in the
20 *    documentation and/or other materials provided with the distribution.
21 * 3. The names of the authors may not be used to endorse or promote
22 *    products derived from this software without specific prior written
23 *    permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 *
37 * $FreeBSD: head/sys/security/mac_biba/mac_biba.c 105638 2002-10-21 18:05:12Z rwatson $
38 */
39
40/*
41 * Developed by the TrustedBSD Project.
42 * Biba fixed label mandatory integrity policy.
43 */
44
45#include <sys/types.h>
46#include <sys/param.h>
47#include <sys/acl.h>
48#include <sys/conf.h>
49#include <sys/kernel.h>
50#include <sys/mac.h>
51#include <sys/malloc.h>
52#include <sys/mount.h>
53#include <sys/proc.h>
54#include <sys/systm.h>
55#include <sys/sysproto.h>
56#include <sys/sysent.h>
57#include <sys/vnode.h>
58#include <sys/file.h>
59#include <sys/socket.h>
60#include <sys/socketvar.h>
61#include <sys/pipe.h>
62#include <sys/sysctl.h>
63
64#include <fs/devfs/devfs.h>
65
66#include <net/bpfdesc.h>
67#include <net/if.h>
68#include <net/if_types.h>
69#include <net/if_var.h>
70
71#include <netinet/in.h>
72#include <netinet/ip_var.h>
73
74#include <vm/vm.h>
75
76#include <sys/mac_policy.h>
77
78#include <security/mac_biba/mac_biba.h>
79
80SYSCTL_DECL(_security_mac);
81
82SYSCTL_NODE(_security_mac, OID_AUTO, biba, CTLFLAG_RW, 0,
83    "TrustedBSD mac_biba policy controls");
84
85static int	mac_biba_enabled = 0;
86SYSCTL_INT(_security_mac_biba, OID_AUTO, enabled, CTLFLAG_RW,
87    &mac_biba_enabled, 0, "Enforce MAC/Biba policy");
88TUNABLE_INT("security.mac.biba.enabled", &mac_biba_enabled);
89
90static int	destroyed_not_inited;
91SYSCTL_INT(_security_mac_biba, OID_AUTO, destroyed_not_inited, CTLFLAG_RD,
92    &destroyed_not_inited, 0, "Count of labels destroyed but not inited");
93
94static int	trust_all_interfaces = 0;
95SYSCTL_INT(_security_mac_biba, OID_AUTO, trust_all_interfaces, CTLFLAG_RD,
96    &trust_all_interfaces, 0, "Consider all interfaces 'trusted' by MAC/Biba");
97TUNABLE_INT("security.mac.biba.trust_all_interfaces", &trust_all_interfaces);
98
99static char	trusted_interfaces[128];
100SYSCTL_STRING(_security_mac_biba, OID_AUTO, trusted_interfaces, CTLFLAG_RD,
101    trusted_interfaces, 0, "Interfaces considered 'trusted' by MAC/Biba");
102TUNABLE_STR("security.mac.biba.trusted_interfaces", trusted_interfaces,
103    sizeof(trusted_interfaces));
104
105static int	ptys_equal = 0;
106SYSCTL_INT(_security_mac_biba, OID_AUTO, ptys_equal, CTLFLAG_RW,
107    &ptys_equal, 0, "Label pty devices as biba/equal on create");
108TUNABLE_INT("security.mac.biba.ptys_equal", &ptys_equal);
109
110static int	revocation_enabled = 0;
111SYSCTL_INT(_security_mac_biba, OID_AUTO, revocation_enabled, CTLFLAG_RW,
112    &revocation_enabled, 0, "Revoke access to objects on relabel");
113TUNABLE_INT("security.mac.biba.revocation_enabled", &revocation_enabled);
114
115static int	mac_biba_slot;
116#define	SLOT(l)	((struct mac_biba *)LABEL_TO_SLOT((l), mac_biba_slot).l_ptr)
117
118MALLOC_DEFINE(M_MACBIBA, "biba label", "MAC/Biba labels");
119
120static struct mac_biba *
121biba_alloc(int flag)
122{
123	struct mac_biba *mac_biba;
124
125	mac_biba = malloc(sizeof(struct mac_biba), M_MACBIBA, M_ZERO | flag);
126
127	return (mac_biba);
128}
129
130static void
131biba_free(struct mac_biba *mac_biba)
132{
133
134	if (mac_biba != NULL)
135		free(mac_biba, M_MACBIBA);
136	else
137		atomic_add_int(&destroyed_not_inited, 1);
138}
139
140static int
141biba_atmostflags(struct mac_biba *mac_biba, int flags)
142{
143
144	if ((mac_biba->mb_flags & flags) != mac_biba->mb_flags)
145		return (EINVAL);
146	return (0);
147}
148
149static int
150mac_biba_dominate_element(struct mac_biba_element *a,
151    struct mac_biba_element *b)
152{
153
154	switch(a->mbe_type) {
155	case MAC_BIBA_TYPE_EQUAL:
156	case MAC_BIBA_TYPE_HIGH:
157		return (1);
158
159	case MAC_BIBA_TYPE_LOW:
160		switch (b->mbe_type) {
161		case MAC_BIBA_TYPE_GRADE:
162		case MAC_BIBA_TYPE_HIGH:
163			return (0);
164
165		case MAC_BIBA_TYPE_EQUAL:
166		case MAC_BIBA_TYPE_LOW:
167			return (1);
168
169		default:
170			panic("mac_biba_dominate_element: b->mbe_type invalid");
171		}
172
173	case MAC_BIBA_TYPE_GRADE:
174		switch (b->mbe_type) {
175		case MAC_BIBA_TYPE_EQUAL:
176		case MAC_BIBA_TYPE_LOW:
177			return (1);
178
179		case MAC_BIBA_TYPE_HIGH:
180			return (0);
181
182		case MAC_BIBA_TYPE_GRADE:
183			return (a->mbe_grade >= b->mbe_grade);
184
185		default:
186			panic("mac_biba_dominate_element: b->mbe_type invalid");
187		}
188
189	default:
190		panic("mac_biba_dominate_element: a->mbe_type invalid");
191	}
192
193	return (0);
194}
195
196static int
197mac_biba_range_in_range(struct mac_biba *rangea, struct mac_biba *rangeb)
198{
199
200	return (mac_biba_dominate_element(&rangeb->mb_rangehigh,
201	    &rangea->mb_rangehigh) &&
202	    mac_biba_dominate_element(&rangea->mb_rangelow,
203	    &rangeb->mb_rangelow));
204}
205
206static int
207mac_biba_single_in_range(struct mac_biba *single, struct mac_biba *range)
208{
209
210	KASSERT((single->mb_flags & MAC_BIBA_FLAG_SINGLE) != 0,
211	    ("mac_biba_single_in_range: a not single"));
212	KASSERT((range->mb_flags & MAC_BIBA_FLAG_RANGE) != 0,
213	    ("mac_biba_single_in_range: b not range"));
214
215	return (mac_biba_dominate_element(&range->mb_rangehigh,
216	    &single->mb_single) &&
217	    mac_biba_dominate_element(&single->mb_single,
218	    &range->mb_rangelow));
219
220	return (1);
221}
222
223static int
224mac_biba_dominate_single(struct mac_biba *a, struct mac_biba *b)
225{
226	KASSERT((a->mb_flags & MAC_BIBA_FLAG_SINGLE) != 0,
227	    ("mac_biba_dominate_single: a not single"));
228	KASSERT((b->mb_flags & MAC_BIBA_FLAG_SINGLE) != 0,
229	    ("mac_biba_dominate_single: b not single"));
230
231	return (mac_biba_dominate_element(&a->mb_single, &b->mb_single));
232}
233
234static int
235mac_biba_equal_element(struct mac_biba_element *a, struct mac_biba_element *b)
236{
237
238	if (a->mbe_type == MAC_BIBA_TYPE_EQUAL ||
239	    b->mbe_type == MAC_BIBA_TYPE_EQUAL)
240		return (1);
241
242	return (a->mbe_type == b->mbe_type && a->mbe_grade == b->mbe_grade);
243}
244
245static int
246mac_biba_equal_single(struct mac_biba *a, struct mac_biba *b)
247{
248
249	KASSERT((a->mb_flags & MAC_BIBA_FLAG_SINGLE) != 0,
250	    ("mac_biba_equal_single: a not single"));
251	KASSERT((b->mb_flags & MAC_BIBA_FLAG_SINGLE) != 0,
252	    ("mac_biba_equal_single: b not single"));
253
254	return (mac_biba_equal_element(&a->mb_single, &b->mb_single));
255}
256
257static int
258mac_biba_contains_equal(struct mac_biba *mac_biba)
259{
260
261	if (mac_biba->mb_flags & MAC_BIBA_FLAG_SINGLE)
262		if (mac_biba->mb_single.mbe_type == MAC_BIBA_TYPE_EQUAL)
263			return (1);
264
265	if (mac_biba->mb_flags & MAC_BIBA_FLAG_RANGE) {
266		if (mac_biba->mb_rangelow.mbe_type == MAC_BIBA_TYPE_EQUAL)
267			return (1);
268		if (mac_biba->mb_rangehigh.mbe_type == MAC_BIBA_TYPE_EQUAL)
269			return (1);
270	}
271
272	return (0);
273}
274
275static int
276mac_biba_subject_equal_ok(struct mac_biba *mac_biba)
277{
278
279	KASSERT((mac_biba->mb_flags & MAC_BIBA_FLAGS_BOTH) ==
280	    MAC_BIBA_FLAGS_BOTH,
281	    ("mac_biba_subject_equal_ok: subject doesn't have both labels"));
282
283	/* If the single is EQUAL, it's ok. */
284	if (mac_biba->mb_single.mbe_type == MAC_BIBA_TYPE_EQUAL)
285		return (0);
286
287	/* If either range endpoint is EQUAL, it's ok. */
288	if (mac_biba->mb_rangelow.mbe_type == MAC_BIBA_TYPE_EQUAL ||
289	    mac_biba->mb_rangehigh.mbe_type == MAC_BIBA_TYPE_EQUAL)
290		return (0);
291
292	/* If the range is low-high, it's ok. */
293	if (mac_biba->mb_rangelow.mbe_type == MAC_BIBA_TYPE_LOW &&
294	    mac_biba->mb_rangehigh.mbe_type == MAC_BIBA_TYPE_HIGH)
295		return (0);
296
297	/* It's not ok. */
298	return (EPERM);
299}
300
301static int
302mac_biba_valid(struct mac_biba *mac_biba)
303{
304
305	if (mac_biba->mb_flags & MAC_BIBA_FLAG_SINGLE) {
306		switch (mac_biba->mb_single.mbe_type) {
307		case MAC_BIBA_TYPE_GRADE:
308			break;
309
310		case MAC_BIBA_TYPE_EQUAL:
311		case MAC_BIBA_TYPE_HIGH:
312		case MAC_BIBA_TYPE_LOW:
313			if (mac_biba->mb_single.mbe_grade != 0)
314				return (EINVAL);
315			break;
316
317		default:
318			return (EINVAL);
319		}
320	} else {
321		if (mac_biba->mb_single.mbe_type != MAC_BIBA_TYPE_UNDEF)
322			return (EINVAL);
323	}
324
325	if (mac_biba->mb_flags & MAC_BIBA_FLAG_RANGE) {
326		switch (mac_biba->mb_rangelow.mbe_type) {
327		case MAC_BIBA_TYPE_GRADE:
328			break;
329
330		case MAC_BIBA_TYPE_EQUAL:
331		case MAC_BIBA_TYPE_HIGH:
332		case MAC_BIBA_TYPE_LOW:
333			if (mac_biba->mb_rangelow.mbe_grade != 0)
334				return (EINVAL);
335			break;
336
337		default:
338			return (EINVAL);
339		}
340
341		switch (mac_biba->mb_rangehigh.mbe_type) {
342		case MAC_BIBA_TYPE_GRADE:
343			break;
344
345		case MAC_BIBA_TYPE_EQUAL:
346		case MAC_BIBA_TYPE_HIGH:
347		case MAC_BIBA_TYPE_LOW:
348			if (mac_biba->mb_rangehigh.mbe_grade != 0)
349				return (EINVAL);
350			break;
351
352		default:
353			return (EINVAL);
354		}
355		if (!mac_biba_dominate_element(&mac_biba->mb_rangehigh,
356		    &mac_biba->mb_rangelow))
357			return (EINVAL);
358	} else {
359		if (mac_biba->mb_rangelow.mbe_type != MAC_BIBA_TYPE_UNDEF ||
360		    mac_biba->mb_rangehigh.mbe_type != MAC_BIBA_TYPE_UNDEF)
361			return (EINVAL);
362	}
363
364	return (0);
365}
366
367static void
368mac_biba_set_range(struct mac_biba *mac_biba, u_short typelow,
369    u_short gradelow, u_short typehigh, u_short gradehigh)
370{
371
372	mac_biba->mb_rangelow.mbe_type = typelow;
373	mac_biba->mb_rangelow.mbe_grade = gradelow;
374	mac_biba->mb_rangehigh.mbe_type = typehigh;
375	mac_biba->mb_rangehigh.mbe_grade = gradehigh;
376	mac_biba->mb_flags |= MAC_BIBA_FLAG_RANGE;
377}
378
379static void
380mac_biba_set_single(struct mac_biba *mac_biba, u_short type, u_short grade)
381{
382
383	mac_biba->mb_single.mbe_type = type;
384	mac_biba->mb_single.mbe_grade = grade;
385	mac_biba->mb_flags |= MAC_BIBA_FLAG_SINGLE;
386}
387
388static void
389mac_biba_copy_range(struct mac_biba *labelfrom, struct mac_biba *labelto)
390{
391	KASSERT((labelfrom->mb_flags & MAC_BIBA_FLAG_RANGE) != 0,
392	    ("mac_biba_copy_range: labelfrom not range"));
393
394	labelto->mb_rangelow = labelfrom->mb_rangelow;
395	labelto->mb_rangehigh = labelfrom->mb_rangehigh;
396	labelto->mb_flags |= MAC_BIBA_FLAG_RANGE;
397}
398
399static void
400mac_biba_copy_single(struct mac_biba *labelfrom, struct mac_biba *labelto)
401{
402
403	KASSERT((labelfrom->mb_flags & MAC_BIBA_FLAG_SINGLE) != 0,
404	    ("mac_biba_copy_single: labelfrom not single"));
405
406	labelto->mb_single = labelfrom->mb_single;
407	labelto->mb_flags |= MAC_BIBA_FLAG_SINGLE;
408}
409
410/*
411 * Policy module operations.
412 */
413static void
414mac_biba_destroy(struct mac_policy_conf *conf)
415{
416
417}
418
419static void
420mac_biba_init(struct mac_policy_conf *conf)
421{
422
423}
424
425/*
426 * Label operations.
427 */
428static void
429mac_biba_init_label(struct label *label)
430{
431
432	SLOT(label) = biba_alloc(M_WAITOK);
433}
434
435static int
436mac_biba_init_label_waitcheck(struct label *label, int flag)
437{
438
439	SLOT(label) = biba_alloc(flag);
440	if (SLOT(label) == NULL)
441		return (ENOMEM);
442
443	return (0);
444}
445
446static void
447mac_biba_destroy_label(struct label *label)
448{
449
450	biba_free(SLOT(label));
451	SLOT(label) = NULL;
452}
453
454static int
455mac_biba_externalize(struct label *label, struct mac *extmac)
456{
457	struct mac_biba *mac_biba;
458
459	mac_biba = SLOT(label);
460
461	if (mac_biba == NULL) {
462		printf("mac_biba_externalize: NULL pointer\n");
463		return (0);
464	}
465
466	extmac->m_biba = *mac_biba;
467
468	return (0);
469}
470
471static int
472mac_biba_internalize(struct label *label, struct mac *extmac)
473{
474	struct mac_biba *mac_biba;
475	int error;
476
477	mac_biba = SLOT(label);
478
479	error = mac_biba_valid(mac_biba);
480	if (error)
481		return (error);
482
483	*mac_biba = extmac->m_biba;
484
485	return (0);
486}
487
488/*
489 * Labeling event operations: file system objects, and things that look
490 * a lot like file system objects.
491 */
492static void
493mac_biba_create_devfs_device(dev_t dev, struct devfs_dirent *devfs_dirent,
494    struct label *label)
495{
496	struct mac_biba *mac_biba;
497	int biba_type;
498
499	mac_biba = SLOT(label);
500	if (strcmp(dev->si_name, "null") == 0 ||
501	    strcmp(dev->si_name, "zero") == 0 ||
502	    strcmp(dev->si_name, "random") == 0 ||
503	    strncmp(dev->si_name, "fd/", strlen("fd/")) == 0)
504		biba_type = MAC_BIBA_TYPE_EQUAL;
505	else if (ptys_equal &&
506	    (strncmp(dev->si_name, "ttyp", strlen("ttyp")) == 0 ||
507	    strncmp(dev->si_name, "ptyp", strlen("ptyp")) == 0))
508		biba_type = MAC_BIBA_TYPE_EQUAL;
509	else
510		biba_type = MAC_BIBA_TYPE_HIGH;
511	mac_biba_set_single(mac_biba, biba_type, 0);
512}
513
514static void
515mac_biba_create_devfs_directory(char *dirname, int dirnamelen,
516    struct devfs_dirent *devfs_dirent, struct label *label)
517{
518	struct mac_biba *mac_biba;
519
520	mac_biba = SLOT(label);
521	mac_biba_set_single(mac_biba, MAC_BIBA_TYPE_HIGH, 0);
522}
523
524static void
525mac_biba_create_devfs_symlink(struct ucred *cred, struct devfs_dirent *dd,
526    struct label *ddlabel, struct devfs_dirent *de, struct label *delabel)
527{
528	struct mac_biba *source, *dest;
529
530	source = SLOT(&cred->cr_label);
531	dest = SLOT(delabel);
532
533	mac_biba_copy_single(source, dest);
534}
535
536static void
537mac_biba_create_devfs_vnode(struct devfs_dirent *devfs_dirent,
538    struct label *direntlabel, struct vnode *vp, struct label *vnodelabel)
539{
540	struct mac_biba *source, *dest;
541
542	source = SLOT(direntlabel);
543	dest = SLOT(vnodelabel);
544	mac_biba_copy_single(source, dest);
545}
546
547static void
548mac_biba_create_vnode(struct ucred *cred, struct vnode *parent,
549    struct label *parentlabel, struct vnode *child, struct label *childlabel)
550{
551	struct mac_biba *source, *dest;
552
553	source = SLOT(&cred->cr_label);
554	dest = SLOT(childlabel);
555
556	mac_biba_copy_single(source, dest);
557}
558
559static void
560mac_biba_create_mount(struct ucred *cred, struct mount *mp,
561    struct label *mntlabel, struct label *fslabel)
562{
563	struct mac_biba *source, *dest;
564
565	source = SLOT(&cred->cr_label);
566	dest = SLOT(mntlabel);
567	mac_biba_copy_single(source, dest);
568	dest = SLOT(fslabel);
569	mac_biba_copy_single(source, dest);
570}
571
572static void
573mac_biba_create_root_mount(struct ucred *cred, struct mount *mp,
574    struct label *mntlabel, struct label *fslabel)
575{
576	struct mac_biba *mac_biba;
577
578	/* Always mount root as high integrity. */
579	mac_biba = SLOT(fslabel);
580	mac_biba_set_single(mac_biba, MAC_BIBA_TYPE_HIGH, 0);
581	mac_biba = SLOT(mntlabel);
582	mac_biba_set_single(mac_biba, MAC_BIBA_TYPE_HIGH, 0);
583}
584
585static void
586mac_biba_relabel_vnode(struct ucred *cred, struct vnode *vp,
587    struct label *vnodelabel, struct label *label)
588{
589	struct mac_biba *source, *dest;
590
591	source = SLOT(label);
592	dest = SLOT(vnodelabel);
593
594	mac_biba_copy_single(source, dest);
595}
596
597static void
598mac_biba_update_devfsdirent(struct devfs_dirent *devfs_dirent,
599    struct label *direntlabel, struct vnode *vp, struct label *vnodelabel)
600{
601	struct mac_biba *source, *dest;
602
603	source = SLOT(vnodelabel);
604	dest = SLOT(direntlabel);
605
606	mac_biba_copy_single(source, dest);
607}
608
609static void
610mac_biba_update_procfsvnode(struct vnode *vp, struct label *vnodelabel,
611    struct ucred *cred)
612{
613	struct mac_biba *source, *dest;
614
615	source = SLOT(&cred->cr_label);
616	dest = SLOT(vnodelabel);
617
618	/*
619	 * Only copy the single, not the range, since vnodes only have
620	 * a single.
621	 */
622	mac_biba_copy_single(source, dest);
623}
624
625static int
626mac_biba_update_vnode_from_externalized(struct vnode *vp,
627    struct label *vnodelabel, struct mac *extmac)
628{
629	struct mac_biba *source, *dest;
630	int error;
631
632	source = &extmac->m_biba;
633	dest = SLOT(vnodelabel);
634
635	error = mac_biba_valid(source);
636	if (error)
637		return (error);
638
639	if ((source->mb_flags & MAC_BIBA_FLAGS_BOTH) != MAC_BIBA_FLAG_SINGLE)
640		return (EINVAL);
641
642	mac_biba_copy_single(source, dest);
643
644	return (0);
645}
646
647static void
648mac_biba_update_vnode_from_mount(struct vnode *vp, struct label *vnodelabel,
649    struct mount *mp, struct label *fslabel)
650{
651	struct mac_biba *source, *dest;
652
653	source = SLOT(fslabel);
654	dest = SLOT(vnodelabel);
655
656	mac_biba_copy_single(source, dest);
657}
658
659/*
660 * Labeling event operations: IPC object.
661 */
662static void
663mac_biba_create_mbuf_from_socket(struct socket *so, struct label *socketlabel,
664    struct mbuf *m, struct label *mbuflabel)
665{
666	struct mac_biba *source, *dest;
667
668	source = SLOT(socketlabel);
669	dest = SLOT(mbuflabel);
670
671	mac_biba_copy_single(source, dest);
672}
673
674static void
675mac_biba_create_socket(struct ucred *cred, struct socket *socket,
676    struct label *socketlabel)
677{
678	struct mac_biba *source, *dest;
679
680	source = SLOT(&cred->cr_label);
681	dest = SLOT(socketlabel);
682
683	mac_biba_copy_single(source, dest);
684}
685
686static void
687mac_biba_create_pipe(struct ucred *cred, struct pipe *pipe,
688    struct label *pipelabel)
689{
690	struct mac_biba *source, *dest;
691
692	source = SLOT(&cred->cr_label);
693	dest = SLOT(pipelabel);
694
695	mac_biba_copy_single(source, dest);
696}
697
698static void
699mac_biba_create_socket_from_socket(struct socket *oldsocket,
700    struct label *oldsocketlabel, struct socket *newsocket,
701    struct label *newsocketlabel)
702{
703	struct mac_biba *source, *dest;
704
705	source = SLOT(oldsocketlabel);
706	dest = SLOT(newsocketlabel);
707
708	mac_biba_copy_single(source, dest);
709}
710
711static void
712mac_biba_relabel_socket(struct ucred *cred, struct socket *socket,
713    struct label *socketlabel, struct label *newlabel)
714{
715	struct mac_biba *source, *dest;
716
717	source = SLOT(newlabel);
718	dest = SLOT(socketlabel);
719
720	mac_biba_copy_single(source, dest);
721}
722
723static void
724mac_biba_relabel_pipe(struct ucred *cred, struct pipe *pipe,
725    struct label *pipelabel, struct label *newlabel)
726{
727	struct mac_biba *source, *dest;
728
729	source = SLOT(newlabel);
730	dest = SLOT(pipelabel);
731
732	mac_biba_copy_single(source, dest);
733}
734
735static void
736mac_biba_set_socket_peer_from_mbuf(struct mbuf *mbuf, struct label *mbuflabel,
737    struct socket *socket, struct label *socketpeerlabel)
738{
739	struct mac_biba *source, *dest;
740
741	source = SLOT(mbuflabel);
742	dest = SLOT(socketpeerlabel);
743
744	mac_biba_copy_single(source, dest);
745}
746
747/*
748 * Labeling event operations: network objects.
749 */
750static void
751mac_biba_set_socket_peer_from_socket(struct socket *oldsocket,
752    struct label *oldsocketlabel, struct socket *newsocket,
753    struct label *newsocketpeerlabel)
754{
755	struct mac_biba *source, *dest;
756
757	source = SLOT(oldsocketlabel);
758	dest = SLOT(newsocketpeerlabel);
759
760	mac_biba_copy_single(source, dest);
761}
762
763static void
764mac_biba_create_bpfdesc(struct ucred *cred, struct bpf_d *bpf_d,
765    struct label *bpflabel)
766{
767	struct mac_biba *source, *dest;
768
769	source = SLOT(&cred->cr_label);
770	dest = SLOT(bpflabel);
771
772	mac_biba_copy_single(source, dest);
773}
774
775static void
776mac_biba_create_ifnet(struct ifnet *ifnet, struct label *ifnetlabel)
777{
778	char tifname[IFNAMSIZ], ifname[IFNAMSIZ], *p, *q;
779	char tiflist[sizeof(trusted_interfaces)];
780	struct mac_biba *dest;
781	int len, grade;
782
783	dest = SLOT(ifnetlabel);
784
785	if (ifnet->if_type == IFT_LOOP) {
786		grade = MAC_BIBA_TYPE_EQUAL;
787		goto set;
788	}
789
790	if (trust_all_interfaces) {
791		grade = MAC_BIBA_TYPE_HIGH;
792		goto set;
793	}
794
795	grade = MAC_BIBA_TYPE_LOW;
796
797	if (trusted_interfaces[0] == '\0' ||
798	    !strvalid(trusted_interfaces, sizeof(trusted_interfaces)))
799		goto set;
800
801	for (p = trusted_interfaces, q = tiflist; *p != '\0'; p++, q++)
802		if(*p != ' ' && *p != '\t')
803			*q = *p;
804
805	snprintf(ifname, IFNAMSIZ, "%s%d", ifnet->if_name, ifnet->if_unit);
806
807	for (p = q = tiflist;; p++) {
808		if (*p == ',' || *p == '\0') {
809			len = p - q;
810			if (len < IFNAMSIZ) {
811				bzero(tifname, sizeof(tifname));
812				bcopy(q, tifname, len);
813				if (strcmp(tifname, ifname) == 0) {
814					grade = MAC_BIBA_TYPE_HIGH;
815					break;
816				}
817			}
818			if (*p == '\0')
819				break;
820			q = p + 1;
821		}
822	}
823set:
824	mac_biba_set_single(dest, grade, 0);
825	mac_biba_set_range(dest, grade, 0, grade, 0);
826}
827
828static void
829mac_biba_create_ipq(struct mbuf *fragment, struct label *fragmentlabel,
830    struct ipq *ipq, struct label *ipqlabel)
831{
832	struct mac_biba *source, *dest;
833
834	source = SLOT(fragmentlabel);
835	dest = SLOT(ipqlabel);
836
837	mac_biba_copy_single(source, dest);
838}
839
840static void
841mac_biba_create_datagram_from_ipq(struct ipq *ipq, struct label *ipqlabel,
842    struct mbuf *datagram, struct label *datagramlabel)
843{
844	struct mac_biba *source, *dest;
845
846	source = SLOT(ipqlabel);
847	dest = SLOT(datagramlabel);
848
849	/* Just use the head, since we require them all to match. */
850	mac_biba_copy_single(source, dest);
851}
852
853static void
854mac_biba_create_fragment(struct mbuf *datagram, struct label *datagramlabel,
855    struct mbuf *fragment, struct label *fragmentlabel)
856{
857	struct mac_biba *source, *dest;
858
859	source = SLOT(datagramlabel);
860	dest = SLOT(fragmentlabel);
861
862	mac_biba_copy_single(source, dest);
863}
864
865static void
866mac_biba_create_mbuf_from_mbuf(struct mbuf *oldmbuf,
867    struct label *oldmbuflabel, struct mbuf *newmbuf,
868    struct label *newmbuflabel)
869{
870	struct mac_biba *source, *dest;
871
872	source = SLOT(oldmbuflabel);
873	dest = SLOT(newmbuflabel);
874
875	mac_biba_copy_single(source, dest);
876}
877
878static void
879mac_biba_create_mbuf_linklayer(struct ifnet *ifnet, struct label *ifnetlabel,
880    struct mbuf *mbuf, struct label *mbuflabel)
881{
882	struct mac_biba *dest;
883
884	dest = SLOT(mbuflabel);
885
886	mac_biba_set_single(dest, MAC_BIBA_TYPE_EQUAL, 0);
887}
888
889static void
890mac_biba_create_mbuf_from_bpfdesc(struct bpf_d *bpf_d, struct label *bpflabel,
891    struct mbuf *mbuf, struct label *mbuflabel)
892{
893	struct mac_biba *source, *dest;
894
895	source = SLOT(bpflabel);
896	dest = SLOT(mbuflabel);
897
898	mac_biba_copy_single(source, dest);
899}
900
901static void
902mac_biba_create_mbuf_from_ifnet(struct ifnet *ifnet, struct label *ifnetlabel,
903    struct mbuf *m, struct label *mbuflabel)
904{
905	struct mac_biba *source, *dest;
906
907	source = SLOT(ifnetlabel);
908	dest = SLOT(mbuflabel);
909
910	mac_biba_copy_single(source, dest);
911}
912
913static void
914mac_biba_create_mbuf_multicast_encap(struct mbuf *oldmbuf,
915    struct label *oldmbuflabel, struct ifnet *ifnet, struct label *ifnetlabel,
916    struct mbuf *newmbuf, struct label *newmbuflabel)
917{
918	struct mac_biba *source, *dest;
919
920	source = SLOT(oldmbuflabel);
921	dest = SLOT(newmbuflabel);
922
923	mac_biba_copy_single(source, dest);
924}
925
926static void
927mac_biba_create_mbuf_netlayer(struct mbuf *oldmbuf, struct label *oldmbuflabel,
928    struct mbuf *newmbuf, struct label *newmbuflabel)
929{
930	struct mac_biba *source, *dest;
931
932	source = SLOT(oldmbuflabel);
933	dest = SLOT(newmbuflabel);
934
935	mac_biba_copy_single(source, dest);
936}
937
938static int
939mac_biba_fragment_match(struct mbuf *fragment, struct label *fragmentlabel,
940    struct ipq *ipq, struct label *ipqlabel)
941{
942	struct mac_biba *a, *b;
943
944	a = SLOT(ipqlabel);
945	b = SLOT(fragmentlabel);
946
947	return (mac_biba_equal_single(a, b));
948}
949
950static void
951mac_biba_relabel_ifnet(struct ucred *cred, struct ifnet *ifnet,
952    struct label *ifnetlabel, struct label *newlabel)
953{
954	struct mac_biba *source, *dest;
955
956	source = SLOT(newlabel);
957	dest = SLOT(ifnetlabel);
958
959	mac_biba_copy_single(source, dest);
960	mac_biba_copy_range(source, dest);
961}
962
963static void
964mac_biba_update_ipq(struct mbuf *fragment, struct label *fragmentlabel,
965    struct ipq *ipq, struct label *ipqlabel)
966{
967
968	/* NOOP: we only accept matching labels, so no need to update */
969}
970
971/*
972 * Labeling event operations: processes.
973 */
974static void
975mac_biba_create_cred(struct ucred *cred_parent, struct ucred *cred_child)
976{
977	struct mac_biba *source, *dest;
978
979	source = SLOT(&cred_parent->cr_label);
980	dest = SLOT(&cred_child->cr_label);
981
982	mac_biba_copy_single(source, dest);
983	mac_biba_copy_range(source, dest);
984}
985
986static void
987mac_biba_execve_transition(struct ucred *old, struct ucred *new,
988    struct vnode *vp, struct mac *vnodelabel)
989{
990	struct mac_biba *source, *dest;
991
992	source = SLOT(&old->cr_label);
993	dest = SLOT(&new->cr_label);
994
995	mac_biba_copy_single(source, dest);
996	mac_biba_copy_range(source, dest);
997}
998
999static int
1000mac_biba_execve_will_transition(struct ucred *old, struct vnode *vp,
1001    struct mac *vnodelabel)
1002{
1003
1004	return (0);
1005}
1006
1007static void
1008mac_biba_create_proc0(struct ucred *cred)
1009{
1010	struct mac_biba *dest;
1011
1012	dest = SLOT(&cred->cr_label);
1013
1014	mac_biba_set_single(dest, MAC_BIBA_TYPE_EQUAL, 0);
1015	mac_biba_set_range(dest, MAC_BIBA_TYPE_LOW, 0, MAC_BIBA_TYPE_HIGH, 0);
1016}
1017
1018static void
1019mac_biba_create_proc1(struct ucred *cred)
1020{
1021	struct mac_biba *dest;
1022
1023	dest = SLOT(&cred->cr_label);
1024
1025	mac_biba_set_single(dest, MAC_BIBA_TYPE_HIGH, 0);
1026	mac_biba_set_range(dest, MAC_BIBA_TYPE_LOW, 0, MAC_BIBA_TYPE_HIGH, 0);
1027}
1028
1029static void
1030mac_biba_relabel_cred(struct ucred *cred, struct label *newlabel)
1031{
1032	struct mac_biba *source, *dest;
1033
1034	source = SLOT(newlabel);
1035	dest = SLOT(&cred->cr_label);
1036
1037	mac_biba_copy_single(source, dest);
1038	mac_biba_copy_range(source, dest);
1039}
1040
1041/*
1042 * Access control checks.
1043 */
1044static int
1045mac_biba_check_bpfdesc_receive(struct bpf_d *bpf_d, struct label *bpflabel,
1046    struct ifnet *ifnet, struct label *ifnetlabel)
1047{
1048	struct mac_biba *a, *b;
1049
1050	if (!mac_biba_enabled)
1051		return (0);
1052
1053	a = SLOT(bpflabel);
1054	b = SLOT(ifnetlabel);
1055
1056	if (mac_biba_equal_single(a, b))
1057		return (0);
1058	return (EACCES);
1059}
1060
1061static int
1062mac_biba_check_cred_relabel(struct ucred *cred, struct label *newlabel)
1063{
1064	struct mac_biba *subj, *new;
1065	int error;
1066
1067	subj = SLOT(&cred->cr_label);
1068	new = SLOT(newlabel);
1069
1070	/*
1071	 * If there is a Biba label update for the credential, it may
1072	 * be an update of the single, range, or both.
1073	 */
1074	error = biba_atmostflags(new, MAC_BIBA_FLAGS_BOTH);
1075	if (error)
1076		return (error);
1077
1078	/*
1079	 * If the Biba label is to be changed, authorize as appropriate.
1080	 */
1081	if (new->mb_flags & MAC_BIBA_FLAGS_BOTH) {
1082		/*
1083		 * To change the Biba single label on a credential, the
1084		 * new single label must be in the current range.
1085		 */
1086		if (new->mb_flags & MAC_BIBA_FLAG_SINGLE &&
1087		    !mac_biba_single_in_range(new, subj))
1088			return (EPERM);
1089
1090		/*
1091		 * To change the Biba range on a credential, the new
1092		 * range label must be in the current range.
1093		 */
1094		if (new->mb_flags & MAC_BIBA_FLAG_RANGE &&
1095		    !mac_biba_range_in_range(new, subj))
1096			return (EPERM);
1097
1098		/*
1099		 * To have EQUAL in any component of the new credential
1100		 * Biba label, the subject must already have EQUAL in
1101		 * their label.
1102		 */
1103		if (mac_biba_contains_equal(new)) {
1104			error = mac_biba_subject_equal_ok(subj);
1105			if (error)
1106				return (error);
1107		}
1108
1109		/*
1110		 * XXXMAC: Additional consistency tests regarding the
1111		 * single and range of the new label might be performed
1112		 * here.
1113		 */
1114	}
1115
1116	return (0);
1117}
1118
1119static int
1120mac_biba_check_cred_visible(struct ucred *u1, struct ucred *u2)
1121{
1122	struct mac_biba *subj, *obj;
1123
1124	if (!mac_biba_enabled)
1125		return (0);
1126
1127	subj = SLOT(&u1->cr_label);
1128	obj = SLOT(&u2->cr_label);
1129
1130	/* XXX: range */
1131	if (!mac_biba_dominate_single(obj, subj))
1132		return (ESRCH);
1133
1134	return (0);
1135}
1136
1137static int
1138mac_biba_check_ifnet_relabel(struct ucred *cred, struct ifnet *ifnet,
1139    struct label *ifnetlabel, struct label *newlabel)
1140{
1141	struct mac_biba *subj, *new;
1142	int error;
1143
1144	subj = SLOT(&cred->cr_label);
1145	new = SLOT(newlabel);
1146
1147	/*
1148	 * If there is a Biba label update for the interface, it may
1149	 * be an update of the single, range, or both.
1150	 */
1151	error = biba_atmostflags(new, MAC_BIBA_FLAGS_BOTH);
1152	if (error)
1153		return (error);
1154
1155	/*
1156	 * If the Biba label is to be changed, authorize as appropriate.
1157	 */
1158	if (new->mb_flags & MAC_BIBA_FLAGS_BOTH) {
1159		/*
1160		 * Rely on the traditional superuser status for the Biba
1161		 * interface relabel requirements.  XXXMAC: This will go
1162		 * away.
1163		 */
1164		error = suser_cred(cred, 0);
1165		if (error)
1166			return (EPERM);
1167
1168		/*
1169		 * XXXMAC: Additional consistency tests regarding the single
1170		 * and the range of the new label might be performed here.
1171		 */
1172	}
1173
1174	return (0);
1175}
1176
1177static int
1178mac_biba_check_ifnet_transmit(struct ifnet *ifnet, struct label *ifnetlabel,
1179    struct mbuf *m, struct label *mbuflabel)
1180{
1181	struct mac_biba *p, *i;
1182
1183	if (!mac_biba_enabled)
1184		return (0);
1185
1186	p = SLOT(mbuflabel);
1187	i = SLOT(ifnetlabel);
1188
1189	return (mac_biba_single_in_range(p, i) ? 0 : EACCES);
1190}
1191
1192static int
1193mac_biba_check_mount_stat(struct ucred *cred, struct mount *mp,
1194    struct label *mntlabel)
1195{
1196	struct mac_biba *subj, *obj;
1197
1198	if (!mac_biba_enabled)
1199		return (0);
1200
1201	subj = SLOT(&cred->cr_label);
1202	obj = SLOT(mntlabel);
1203
1204	if (!mac_biba_dominate_single(obj, subj))
1205		return (EACCES);
1206
1207	return (0);
1208}
1209
1210static int
1211mac_biba_check_pipe_ioctl(struct ucred *cred, struct pipe *pipe,
1212    struct label *pipelabel, unsigned long cmd, void /* caddr_t */ *data)
1213{
1214
1215	if(!mac_biba_enabled)
1216		return (0);
1217
1218	/* XXX: This will be implemented soon... */
1219
1220	return (0);
1221}
1222
1223static int
1224mac_biba_check_pipe_poll(struct ucred *cred, struct pipe *pipe,
1225    struct label *pipelabel)
1226{
1227	struct mac_biba *subj, *obj;
1228
1229	if (!mac_biba_enabled)
1230		return (0);
1231
1232	subj = SLOT(&cred->cr_label);
1233	obj = SLOT((pipelabel));
1234
1235	if (!mac_biba_dominate_single(obj, subj))
1236		return (EACCES);
1237
1238	return (0);
1239}
1240
1241static int
1242mac_biba_check_pipe_read(struct ucred *cred, struct pipe *pipe,
1243    struct label *pipelabel)
1244{
1245	struct mac_biba *subj, *obj;
1246
1247	if (!mac_biba_enabled)
1248		return (0);
1249
1250	subj = SLOT(&cred->cr_label);
1251	obj = SLOT((pipelabel));
1252
1253	if (!mac_biba_dominate_single(obj, subj))
1254		return (EACCES);
1255
1256	return (0);
1257}
1258
1259static int
1260mac_biba_check_pipe_relabel(struct ucred *cred, struct pipe *pipe,
1261    struct label *pipelabel, struct label *newlabel)
1262{
1263	struct mac_biba *subj, *obj, *new;
1264	int error;
1265
1266	new = SLOT(newlabel);
1267	subj = SLOT(&cred->cr_label);
1268	obj = SLOT(pipelabel);
1269
1270	/*
1271	 * If there is a Biba label update for a pipe, it must be a
1272	 * single update.
1273	 */
1274	error = biba_atmostflags(new, MAC_BIBA_FLAG_SINGLE);
1275	if (error)
1276		return (error);
1277
1278	/*
1279	 * To perform a relabel of a pipe (Biba label or not), Biba must
1280	 * authorize the relabel.
1281	 */
1282	if (!mac_biba_single_in_range(obj, subj))
1283		return (EPERM);
1284
1285	/*
1286	 * If the Biba label is to be changed, authorize as appropriate.
1287	 */
1288	if (new->mb_flags & MAC_BIBA_FLAG_SINGLE) {
1289		/*
1290		 * To change the Biba label on a pipe, the new pipe label
1291		 * must be in the subject range.
1292		 */
1293		if (!mac_biba_single_in_range(new, subj))
1294			return (EPERM);
1295
1296		/*
1297		 * To change the Biba label on a pipe to be EQUAL, the
1298		 * subject must have appropriate privilege.
1299		 */
1300		if (mac_biba_contains_equal(new)) {
1301			error = mac_biba_subject_equal_ok(subj);
1302			if (error)
1303				return (error);
1304		}
1305	}
1306
1307	return (0);
1308}
1309
1310static int
1311mac_biba_check_pipe_stat(struct ucred *cred, struct pipe *pipe,
1312    struct label *pipelabel)
1313{
1314	struct mac_biba *subj, *obj;
1315
1316	if (!mac_biba_enabled)
1317		return (0);
1318
1319	subj = SLOT(&cred->cr_label);
1320	obj = SLOT((pipelabel));
1321
1322	if (!mac_biba_dominate_single(obj, subj))
1323		return (EACCES);
1324
1325	return (0);
1326}
1327
1328static int
1329mac_biba_check_pipe_write(struct ucred *cred, struct pipe *pipe,
1330    struct label *pipelabel)
1331{
1332	struct mac_biba *subj, *obj;
1333
1334	if (!mac_biba_enabled)
1335		return (0);
1336
1337	subj = SLOT(&cred->cr_label);
1338	obj = SLOT((pipelabel));
1339
1340	if (!mac_biba_dominate_single(subj, obj))
1341		return (EACCES);
1342
1343	return (0);
1344}
1345
1346static int
1347mac_biba_check_proc_debug(struct ucred *cred, struct proc *proc)
1348{
1349	struct mac_biba *subj, *obj;
1350
1351	if (!mac_biba_enabled)
1352		return (0);
1353
1354	subj = SLOT(&cred->cr_label);
1355	obj = SLOT(&proc->p_ucred->cr_label);
1356
1357	/* XXX: range checks */
1358	if (!mac_biba_dominate_single(obj, subj))
1359		return (ESRCH);
1360	if (!mac_biba_dominate_single(subj, obj))
1361		return (EACCES);
1362
1363	return (0);
1364}
1365
1366static int
1367mac_biba_check_proc_sched(struct ucred *cred, struct proc *proc)
1368{
1369	struct mac_biba *subj, *obj;
1370
1371	if (!mac_biba_enabled)
1372		return (0);
1373
1374	subj = SLOT(&cred->cr_label);
1375	obj = SLOT(&proc->p_ucred->cr_label);
1376
1377	/* XXX: range checks */
1378	if (!mac_biba_dominate_single(obj, subj))
1379		return (ESRCH);
1380	if (!mac_biba_dominate_single(subj, obj))
1381		return (EACCES);
1382
1383	return (0);
1384}
1385
1386static int
1387mac_biba_check_proc_signal(struct ucred *cred, struct proc *proc, int signum)
1388{
1389	struct mac_biba *subj, *obj;
1390
1391	if (!mac_biba_enabled)
1392		return (0);
1393
1394	subj = SLOT(&cred->cr_label);
1395	obj = SLOT(&proc->p_ucred->cr_label);
1396
1397	/* XXX: range checks */
1398	if (!mac_biba_dominate_single(obj, subj))
1399		return (ESRCH);
1400	if (!mac_biba_dominate_single(subj, obj))
1401		return (EACCES);
1402
1403	return (0);
1404}
1405
1406static int
1407mac_biba_check_socket_deliver(struct socket *so, struct label *socketlabel,
1408    struct mbuf *m, struct label *mbuflabel)
1409{
1410	struct mac_biba *p, *s;
1411
1412	if (!mac_biba_enabled)
1413		return (0);
1414
1415	p = SLOT(mbuflabel);
1416	s = SLOT(socketlabel);
1417
1418	return (mac_biba_equal_single(p, s) ? 0 : EACCES);
1419}
1420
1421static int
1422mac_biba_check_socket_relabel(struct ucred *cred, struct socket *socket,
1423    struct label *socketlabel, struct label *newlabel)
1424{
1425	struct mac_biba *subj, *obj, *new;
1426	int error;
1427
1428	new = SLOT(newlabel);
1429	subj = SLOT(&cred->cr_label);
1430	obj = SLOT(socketlabel);
1431
1432	/*
1433	 * If there is a Biba label update for the socket, it may be
1434	 * an update of single.
1435	 */
1436	error = biba_atmostflags(new, MAC_BIBA_FLAG_SINGLE);
1437	if (error)
1438		return (error);
1439
1440	/*
1441	 * To relabel a socket, the old socket single must be in the subject
1442	 * range.
1443	 */
1444	if (!mac_biba_single_in_range(obj, subj))
1445		return (EPERM);
1446
1447	/*
1448	 * If the Biba label is to be changed, authorize as appropriate.
1449	 */
1450	if (new->mb_flags & MAC_BIBA_FLAG_SINGLE) {
1451		/*
1452		 * To relabel a socket, the new socket single must be in
1453		 * the subject range.
1454		 */
1455		if (!mac_biba_single_in_range(new, subj))
1456			return (EPERM);
1457
1458		/*
1459		 * To change the Biba label on the socket to contain EQUAL,
1460		 * the subject must have appropriate privilege.
1461		 */
1462		if (mac_biba_contains_equal(new)) {
1463			error = mac_biba_subject_equal_ok(subj);
1464			if (error)
1465				return (error);
1466		}
1467	}
1468
1469	return (0);
1470}
1471
1472static int
1473mac_biba_check_socket_visible(struct ucred *cred, struct socket *socket,
1474    struct label *socketlabel)
1475{
1476	struct mac_biba *subj, *obj;
1477
1478	subj = SLOT(&cred->cr_label);
1479	obj = SLOT(socketlabel);
1480
1481	if (!mac_biba_dominate_single(obj, subj))
1482		return (ENOENT);
1483
1484	return (0);
1485}
1486
1487static int
1488mac_biba_check_vnode_chdir(struct ucred *cred, struct vnode *dvp,
1489    struct label *dlabel)
1490{
1491	struct mac_biba *subj, *obj;
1492
1493	if (!mac_biba_enabled)
1494		return (0);
1495
1496	subj = SLOT(&cred->cr_label);
1497	obj = SLOT(dlabel);
1498
1499	if (!mac_biba_dominate_single(obj, subj))
1500		return (EACCES);
1501
1502	return (0);
1503}
1504
1505static int
1506mac_biba_check_vnode_chroot(struct ucred *cred, struct vnode *dvp,
1507    struct label *dlabel)
1508{
1509	struct mac_biba *subj, *obj;
1510
1511	if (!mac_biba_enabled)
1512		return (0);
1513
1514	subj = SLOT(&cred->cr_label);
1515	obj = SLOT(dlabel);
1516
1517	if (!mac_biba_dominate_single(obj, subj))
1518		return (EACCES);
1519
1520	return (0);
1521}
1522
1523static int
1524mac_biba_check_vnode_create(struct ucred *cred, struct vnode *dvp,
1525    struct label *dlabel, struct componentname *cnp, struct vattr *vap)
1526{
1527	struct mac_biba *subj, *obj;
1528
1529	if (!mac_biba_enabled)
1530		return (0);
1531
1532	subj = SLOT(&cred->cr_label);
1533	obj = SLOT(dlabel);
1534
1535	if (!mac_biba_dominate_single(subj, obj))
1536		return (EACCES);
1537
1538	return (0);
1539}
1540
1541static int
1542mac_biba_check_vnode_delete(struct ucred *cred, struct vnode *dvp,
1543    struct label *dlabel, struct vnode *vp, struct label *label,
1544    struct componentname *cnp)
1545{
1546	struct mac_biba *subj, *obj;
1547
1548	if (!mac_biba_enabled)
1549		return (0);
1550
1551	subj = SLOT(&cred->cr_label);
1552	obj = SLOT(dlabel);
1553
1554	if (!mac_biba_dominate_single(subj, obj))
1555		return (EACCES);
1556
1557	obj = SLOT(label);
1558
1559	if (!mac_biba_dominate_single(subj, obj))
1560		return (EACCES);
1561
1562	return (0);
1563}
1564
1565static int
1566mac_biba_check_vnode_deleteacl(struct ucred *cred, struct vnode *vp,
1567    struct label *label, acl_type_t type)
1568{
1569	struct mac_biba *subj, *obj;
1570
1571	if (!mac_biba_enabled)
1572		return (0);
1573
1574	subj = SLOT(&cred->cr_label);
1575	obj = SLOT(label);
1576
1577	if (!mac_biba_dominate_single(subj, obj))
1578		return (EACCES);
1579
1580	return (0);
1581}
1582
1583static int
1584mac_biba_check_vnode_exec(struct ucred *cred, struct vnode *vp,
1585    struct label *label)
1586{
1587	struct mac_biba *subj, *obj;
1588
1589	if (!mac_biba_enabled)
1590		return (0);
1591
1592	subj = SLOT(&cred->cr_label);
1593	obj = SLOT(label);
1594
1595	if (!mac_biba_dominate_single(obj, subj))
1596		return (EACCES);
1597
1598	return (0);
1599}
1600
1601static int
1602mac_biba_check_vnode_getacl(struct ucred *cred, struct vnode *vp,
1603    struct label *label, acl_type_t type)
1604{
1605	struct mac_biba *subj, *obj;
1606
1607	if (!mac_biba_enabled)
1608		return (0);
1609
1610	subj = SLOT(&cred->cr_label);
1611	obj = SLOT(label);
1612
1613	if (!mac_biba_dominate_single(obj, subj))
1614		return (EACCES);
1615
1616	return (0);
1617}
1618
1619static int
1620mac_biba_check_vnode_getextattr(struct ucred *cred, struct vnode *vp,
1621    struct label *label, int attrnamespace, const char *name, struct uio *uio)
1622{
1623	struct mac_biba *subj, *obj;
1624
1625	if (!mac_biba_enabled)
1626		return (0);
1627
1628	subj = SLOT(&cred->cr_label);
1629	obj = SLOT(label);
1630
1631	if (!mac_biba_dominate_single(obj, subj))
1632		return (EACCES);
1633
1634	return (0);
1635}
1636
1637static int
1638mac_biba_check_vnode_link(struct ucred *cred, struct vnode *dvp,
1639    struct label *dlabel, struct vnode *vp, struct label *label,
1640    struct componentname *cnp)
1641{
1642	struct mac_biba *subj, *obj;
1643
1644	if (!mac_biba_enabled)
1645		return (0);
1646
1647	subj = SLOT(&cred->cr_label);
1648	obj = SLOT(dlabel);
1649
1650	if (!mac_biba_dominate_single(subj, obj))
1651		return (EACCES);
1652
1653	obj = SLOT(label);
1654
1655	if (!mac_biba_dominate_single(subj, obj))
1656		return (EACCES);
1657
1658	return (0);
1659}
1660
1661static int
1662mac_biba_check_vnode_lookup(struct ucred *cred, struct vnode *dvp,
1663    struct label *dlabel, struct componentname *cnp)
1664{
1665	struct mac_biba *subj, *obj;
1666
1667	if (!mac_biba_enabled)
1668		return (0);
1669
1670	subj = SLOT(&cred->cr_label);
1671	obj = SLOT(dlabel);
1672
1673	if (!mac_biba_dominate_single(obj, subj))
1674		return (EACCES);
1675
1676	return (0);
1677}
1678
1679static int
1680mac_biba_check_vnode_mmap(struct ucred *cred, struct vnode *vp,
1681    struct label *label, int prot)
1682{
1683	struct mac_biba *subj, *obj;
1684
1685	/*
1686	 * Rely on the use of open()-time protections to handle
1687	 * non-revocation cases.
1688	 */
1689	if (!mac_biba_enabled || !revocation_enabled)
1690		return (0);
1691
1692	subj = SLOT(&cred->cr_label);
1693	obj = SLOT(label);
1694
1695	if (prot & (VM_PROT_READ | VM_PROT_EXECUTE)) {
1696		if (!mac_biba_dominate_single(obj, subj))
1697			return (EACCES);
1698	}
1699	if (prot & VM_PROT_WRITE) {
1700		if (!mac_biba_dominate_single(subj, obj))
1701			return (EACCES);
1702	}
1703
1704	return (0);
1705}
1706
1707static int
1708mac_biba_check_vnode_open(struct ucred *cred, struct vnode *vp,
1709    struct label *vnodelabel, mode_t acc_mode)
1710{
1711	struct mac_biba *subj, *obj;
1712
1713	if (!mac_biba_enabled)
1714		return (0);
1715
1716	subj = SLOT(&cred->cr_label);
1717	obj = SLOT(vnodelabel);
1718
1719	/* XXX privilege override for admin? */
1720	if (acc_mode & (VREAD | VEXEC | VSTAT)) {
1721		if (!mac_biba_dominate_single(obj, subj))
1722			return (EACCES);
1723	}
1724	if (acc_mode & (VWRITE | VAPPEND | VADMIN)) {
1725		if (!mac_biba_dominate_single(subj, obj))
1726			return (EACCES);
1727	}
1728
1729	return (0);
1730}
1731
1732static int
1733mac_biba_check_vnode_poll(struct ucred *active_cred, struct ucred *file_cred,
1734    struct vnode *vp, struct label *label)
1735{
1736	struct mac_biba *subj, *obj;
1737
1738	if (!mac_biba_enabled || !revocation_enabled)
1739		return (0);
1740
1741	subj = SLOT(&active_cred->cr_label);
1742	obj = SLOT(label);
1743
1744	if (!mac_biba_dominate_single(obj, subj))
1745		return (EACCES);
1746
1747	return (0);
1748}
1749
1750static int
1751mac_biba_check_vnode_read(struct ucred *active_cred, struct ucred *file_cred,
1752    struct vnode *vp, struct label *label)
1753{
1754	struct mac_biba *subj, *obj;
1755
1756	if (!mac_biba_enabled || !revocation_enabled)
1757		return (0);
1758
1759	subj = SLOT(&active_cred->cr_label);
1760	obj = SLOT(label);
1761
1762	if (!mac_biba_dominate_single(obj, subj))
1763		return (EACCES);
1764
1765	return (0);
1766}
1767
1768static int
1769mac_biba_check_vnode_readdir(struct ucred *cred, struct vnode *dvp,
1770    struct label *dlabel)
1771{
1772	struct mac_biba *subj, *obj;
1773
1774	if (!mac_biba_enabled)
1775		return (0);
1776
1777	subj = SLOT(&cred->cr_label);
1778	obj = SLOT(dlabel);
1779
1780	if (!mac_biba_dominate_single(obj, subj))
1781		return (EACCES);
1782
1783	return (0);
1784}
1785
1786static int
1787mac_biba_check_vnode_readlink(struct ucred *cred, struct vnode *vp,
1788    struct label *label)
1789{
1790	struct mac_biba *subj, *obj;
1791
1792	if (!mac_biba_enabled)
1793		return (0);
1794
1795	subj = SLOT(&cred->cr_label);
1796	obj = SLOT(label);
1797
1798	if (!mac_biba_dominate_single(obj, subj))
1799		return (EACCES);
1800
1801	return (0);
1802}
1803
1804static int
1805mac_biba_check_vnode_relabel(struct ucred *cred, struct vnode *vp,
1806    struct label *vnodelabel, struct label *newlabel)
1807{
1808	struct mac_biba *old, *new, *subj;
1809	int error;
1810
1811	old = SLOT(vnodelabel);
1812	new = SLOT(newlabel);
1813	subj = SLOT(&cred->cr_label);
1814
1815	/*
1816	 * If there is a Biba label update for the vnode, it must be a
1817	 * single label.
1818	 */
1819	error = biba_atmostflags(new, MAC_BIBA_FLAG_SINGLE);
1820	if (error)
1821		return (error);
1822
1823	/*
1824	 * To perform a relabel of the vnode (Biba label or not), Biba must
1825	 * authorize the relabel.
1826	 */
1827	if (!mac_biba_single_in_range(old, subj))
1828		return (EPERM);
1829
1830	/*
1831	 * If the Biba label is to be changed, authorize as appropriate.
1832	 */
1833	if (new->mb_flags & MAC_BIBA_FLAG_SINGLE) {
1834		/*
1835		 * To change the Biba label on a vnode, the new vnode label
1836		 * must be in the subject range.
1837		 */
1838		if (!mac_biba_single_in_range(new, subj))
1839			return (EPERM);
1840
1841		/*
1842		 * To change the Biba label on the vnode to be EQUAL,
1843		 * the subject must have appropriate privilege.
1844		 */
1845		if (mac_biba_contains_equal(new)) {
1846			error = mac_biba_subject_equal_ok(subj);
1847			if (error)
1848				return (error);
1849		}
1850	}
1851
1852	return (0);
1853}
1854
1855static int
1856mac_biba_check_vnode_rename_from(struct ucred *cred, struct vnode *dvp,
1857    struct label *dlabel, struct vnode *vp, struct label *label,
1858    struct componentname *cnp)
1859{
1860	struct mac_biba *subj, *obj;
1861
1862	if (!mac_biba_enabled)
1863		return (0);
1864
1865	subj = SLOT(&cred->cr_label);
1866	obj = SLOT(dlabel);
1867
1868	if (!mac_biba_dominate_single(subj, obj))
1869		return (EACCES);
1870
1871	obj = SLOT(label);
1872
1873	if (!mac_biba_dominate_single(subj, obj))
1874		return (EACCES);
1875
1876	return (0);
1877}
1878
1879static int
1880mac_biba_check_vnode_rename_to(struct ucred *cred, struct vnode *dvp,
1881    struct label *dlabel, struct vnode *vp, struct label *label, int samedir,
1882    struct componentname *cnp)
1883{
1884	struct mac_biba *subj, *obj;
1885
1886	if (!mac_biba_enabled)
1887		return (0);
1888
1889	subj = SLOT(&cred->cr_label);
1890	obj = SLOT(dlabel);
1891
1892	if (!mac_biba_dominate_single(subj, obj))
1893		return (EACCES);
1894
1895	if (vp != NULL) {
1896		obj = SLOT(label);
1897
1898		if (!mac_biba_dominate_single(subj, obj))
1899			return (EACCES);
1900	}
1901
1902	return (0);
1903}
1904
1905static int
1906mac_biba_check_vnode_revoke(struct ucred *cred, struct vnode *vp,
1907    struct label *label)
1908{
1909	struct mac_biba *subj, *obj;
1910
1911	if (!mac_biba_enabled)
1912		return (0);
1913
1914	subj = SLOT(&cred->cr_label);
1915	obj = SLOT(label);
1916
1917	if (!mac_biba_dominate_single(subj, obj))
1918		return (EACCES);
1919
1920	return (0);
1921}
1922
1923static int
1924mac_biba_check_vnode_setacl(struct ucred *cred, struct vnode *vp,
1925    struct label *label, acl_type_t type, struct acl *acl)
1926{
1927	struct mac_biba *subj, *obj;
1928
1929	if (!mac_biba_enabled)
1930		return (0);
1931
1932	subj = SLOT(&cred->cr_label);
1933	obj = SLOT(label);
1934
1935	if (!mac_biba_dominate_single(subj, obj))
1936		return (EACCES);
1937
1938	return (0);
1939}
1940
1941static int
1942mac_biba_check_vnode_setextattr(struct ucred *cred, struct vnode *vp,
1943    struct label *vnodelabel, int attrnamespace, const char *name,
1944    struct uio *uio)
1945{
1946	struct mac_biba *subj, *obj;
1947
1948	if (!mac_biba_enabled)
1949		return (0);
1950
1951	subj = SLOT(&cred->cr_label);
1952	obj = SLOT(vnodelabel);
1953
1954	if (!mac_biba_dominate_single(subj, obj))
1955		return (EACCES);
1956
1957	/* XXX: protect the MAC EA in a special way? */
1958
1959	return (0);
1960}
1961
1962static int
1963mac_biba_check_vnode_setflags(struct ucred *cred, struct vnode *vp,
1964    struct label *vnodelabel, u_long flags)
1965{
1966	struct mac_biba *subj, *obj;
1967
1968	if (!mac_biba_enabled)
1969		return (0);
1970
1971	subj = SLOT(&cred->cr_label);
1972	obj = SLOT(vnodelabel);
1973
1974	if (!mac_biba_dominate_single(subj, obj))
1975		return (EACCES);
1976
1977	return (0);
1978}
1979
1980static int
1981mac_biba_check_vnode_setmode(struct ucred *cred, struct vnode *vp,
1982    struct label *vnodelabel, mode_t mode)
1983{
1984	struct mac_biba *subj, *obj;
1985
1986	if (!mac_biba_enabled)
1987		return (0);
1988
1989	subj = SLOT(&cred->cr_label);
1990	obj = SLOT(vnodelabel);
1991
1992	if (!mac_biba_dominate_single(subj, obj))
1993		return (EACCES);
1994
1995	return (0);
1996}
1997
1998static int
1999mac_biba_check_vnode_setowner(struct ucred *cred, struct vnode *vp,
2000    struct label *vnodelabel, uid_t uid, gid_t gid)
2001{
2002	struct mac_biba *subj, *obj;
2003
2004	if (!mac_biba_enabled)
2005		return (0);
2006
2007	subj = SLOT(&cred->cr_label);
2008	obj = SLOT(vnodelabel);
2009
2010	if (!mac_biba_dominate_single(subj, obj))
2011		return (EACCES);
2012
2013	return (0);
2014}
2015
2016static int
2017mac_biba_check_vnode_setutimes(struct ucred *cred, struct vnode *vp,
2018    struct label *vnodelabel, struct timespec atime, struct timespec mtime)
2019{
2020	struct mac_biba *subj, *obj;
2021
2022	if (!mac_biba_enabled)
2023		return (0);
2024
2025	subj = SLOT(&cred->cr_label);
2026	obj = SLOT(vnodelabel);
2027
2028	if (!mac_biba_dominate_single(subj, obj))
2029		return (EACCES);
2030
2031	return (0);
2032}
2033
2034static int
2035mac_biba_check_vnode_stat(struct ucred *active_cred, struct ucred *file_cred,
2036    struct vnode *vp, struct label *vnodelabel)
2037{
2038	struct mac_biba *subj, *obj;
2039
2040	if (!mac_biba_enabled)
2041		return (0);
2042
2043	subj = SLOT(&active_cred->cr_label);
2044	obj = SLOT(vnodelabel);
2045
2046	if (!mac_biba_dominate_single(obj, subj))
2047		return (EACCES);
2048
2049	return (0);
2050}
2051
2052static int
2053mac_biba_check_vnode_write(struct ucred *active_cred,
2054    struct ucred *file_cred, struct vnode *vp, struct label *label)
2055{
2056	struct mac_biba *subj, *obj;
2057
2058	if (!mac_biba_enabled || !revocation_enabled)
2059		return (0);
2060
2061	subj = SLOT(&active_cred->cr_label);
2062	obj = SLOT(label);
2063
2064	if (!mac_biba_dominate_single(subj, obj))
2065		return (EACCES);
2066
2067	return (0);
2068}
2069
2070static struct mac_policy_op_entry mac_biba_ops[] =
2071{
2072	{ MAC_DESTROY,
2073	    (macop_t)mac_biba_destroy },
2074	{ MAC_INIT,
2075	    (macop_t)mac_biba_init },
2076	{ MAC_INIT_BPFDESC_LABEL,
2077	    (macop_t)mac_biba_init_label },
2078	{ MAC_INIT_CRED_LABEL,
2079	    (macop_t)mac_biba_init_label },
2080	{ MAC_INIT_DEVFSDIRENT_LABEL,
2081	    (macop_t)mac_biba_init_label },
2082	{ MAC_INIT_IFNET_LABEL,
2083	    (macop_t)mac_biba_init_label },
2084	{ MAC_INIT_IPQ_LABEL,
2085	    (macop_t)mac_biba_init_label },
2086	{ MAC_INIT_MBUF_LABEL,
2087	    (macop_t)mac_biba_init_label_waitcheck },
2088	{ MAC_INIT_MOUNT_LABEL,
2089	    (macop_t)mac_biba_init_label },
2090	{ MAC_INIT_MOUNT_FS_LABEL,
2091	    (macop_t)mac_biba_init_label },
2092	{ MAC_INIT_PIPE_LABEL,
2093	    (macop_t)mac_biba_init_label },
2094	{ MAC_INIT_SOCKET_LABEL,
2095	    (macop_t)mac_biba_init_label_waitcheck },
2096	{ MAC_INIT_SOCKET_PEER_LABEL,
2097	    (macop_t)mac_biba_init_label_waitcheck },
2098	{ MAC_INIT_TEMP_LABEL,
2099	    (macop_t)mac_biba_init_label },
2100	{ MAC_INIT_VNODE_LABEL,
2101	    (macop_t)mac_biba_init_label },
2102	{ MAC_DESTROY_BPFDESC_LABEL,
2103	    (macop_t)mac_biba_destroy_label },
2104	{ MAC_DESTROY_CRED_LABEL,
2105	    (macop_t)mac_biba_destroy_label },
2106	{ MAC_DESTROY_DEVFSDIRENT_LABEL,
2107	    (macop_t)mac_biba_destroy_label },
2108	{ MAC_DESTROY_IFNET_LABEL,
2109	    (macop_t)mac_biba_destroy_label },
2110	{ MAC_DESTROY_IPQ_LABEL,
2111	    (macop_t)mac_biba_destroy_label },
2112	{ MAC_DESTROY_MBUF_LABEL,
2113	    (macop_t)mac_biba_destroy_label },
2114	{ MAC_DESTROY_MOUNT_LABEL,
2115	    (macop_t)mac_biba_destroy_label },
2116	{ MAC_DESTROY_MOUNT_FS_LABEL,
2117	    (macop_t)mac_biba_destroy_label },
2118	{ MAC_DESTROY_PIPE_LABEL,
2119	    (macop_t)mac_biba_destroy_label },
2120	{ MAC_DESTROY_SOCKET_LABEL,
2121	    (macop_t)mac_biba_destroy_label },
2122	{ MAC_DESTROY_SOCKET_PEER_LABEL,
2123	    (macop_t)mac_biba_destroy_label },
2124	{ MAC_DESTROY_TEMP_LABEL,
2125	    (macop_t)mac_biba_destroy_label },
2126	{ MAC_DESTROY_VNODE_LABEL,
2127	    (macop_t)mac_biba_destroy_label },
2128	{ MAC_EXTERNALIZE,
2129	    (macop_t)mac_biba_externalize },
2130	{ MAC_INTERNALIZE,
2131	    (macop_t)mac_biba_internalize },
2132	{ MAC_CREATE_DEVFS_DEVICE,
2133	    (macop_t)mac_biba_create_devfs_device },
2134	{ MAC_CREATE_DEVFS_DIRECTORY,
2135	    (macop_t)mac_biba_create_devfs_directory },
2136	{ MAC_CREATE_DEVFS_SYMLINK,
2137	    (macop_t)mac_biba_create_devfs_symlink },
2138	{ MAC_CREATE_DEVFS_VNODE,
2139	    (macop_t)mac_biba_create_devfs_vnode },
2140	{ MAC_CREATE_VNODE,
2141	    (macop_t)mac_biba_create_vnode },
2142	{ MAC_CREATE_MOUNT,
2143	    (macop_t)mac_biba_create_mount },
2144	{ MAC_CREATE_ROOT_MOUNT,
2145	    (macop_t)mac_biba_create_root_mount },
2146	{ MAC_RELABEL_VNODE,
2147	    (macop_t)mac_biba_relabel_vnode },
2148	{ MAC_UPDATE_DEVFSDIRENT,
2149	    (macop_t)mac_biba_update_devfsdirent },
2150	{ MAC_UPDATE_PROCFSVNODE,
2151	    (macop_t)mac_biba_update_procfsvnode },
2152	{ MAC_UPDATE_VNODE_FROM_EXTERNALIZED,
2153	    (macop_t)mac_biba_update_vnode_from_externalized },
2154	{ MAC_UPDATE_VNODE_FROM_MOUNT,
2155	    (macop_t)mac_biba_update_vnode_from_mount },
2156	{ MAC_CREATE_MBUF_FROM_SOCKET,
2157	    (macop_t)mac_biba_create_mbuf_from_socket },
2158	{ MAC_CREATE_PIPE,
2159	    (macop_t)mac_biba_create_pipe },
2160	{ MAC_CREATE_SOCKET,
2161	    (macop_t)mac_biba_create_socket },
2162	{ MAC_CREATE_SOCKET_FROM_SOCKET,
2163	    (macop_t)mac_biba_create_socket_from_socket },
2164	{ MAC_RELABEL_PIPE,
2165	    (macop_t)mac_biba_relabel_pipe },
2166	{ MAC_RELABEL_SOCKET,
2167	    (macop_t)mac_biba_relabel_socket },
2168	{ MAC_SET_SOCKET_PEER_FROM_MBUF,
2169	    (macop_t)mac_biba_set_socket_peer_from_mbuf },
2170	{ MAC_SET_SOCKET_PEER_FROM_SOCKET,
2171	    (macop_t)mac_biba_set_socket_peer_from_socket },
2172	{ MAC_CREATE_BPFDESC,
2173	    (macop_t)mac_biba_create_bpfdesc },
2174	{ MAC_CREATE_DATAGRAM_FROM_IPQ,
2175	    (macop_t)mac_biba_create_datagram_from_ipq },
2176	{ MAC_CREATE_FRAGMENT,
2177	    (macop_t)mac_biba_create_fragment },
2178	{ MAC_CREATE_IFNET,
2179	    (macop_t)mac_biba_create_ifnet },
2180	{ MAC_CREATE_IPQ,
2181	    (macop_t)mac_biba_create_ipq },
2182	{ MAC_CREATE_MBUF_FROM_MBUF,
2183	    (macop_t)mac_biba_create_mbuf_from_mbuf },
2184	{ MAC_CREATE_MBUF_LINKLAYER,
2185	    (macop_t)mac_biba_create_mbuf_linklayer },
2186	{ MAC_CREATE_MBUF_FROM_BPFDESC,
2187	    (macop_t)mac_biba_create_mbuf_from_bpfdesc },
2188	{ MAC_CREATE_MBUF_FROM_IFNET,
2189	    (macop_t)mac_biba_create_mbuf_from_ifnet },
2190	{ MAC_CREATE_MBUF_MULTICAST_ENCAP,
2191	    (macop_t)mac_biba_create_mbuf_multicast_encap },
2192	{ MAC_CREATE_MBUF_NETLAYER,
2193	    (macop_t)mac_biba_create_mbuf_netlayer },
2194	{ MAC_FRAGMENT_MATCH,
2195	    (macop_t)mac_biba_fragment_match },
2196	{ MAC_RELABEL_IFNET,
2197	    (macop_t)mac_biba_relabel_ifnet },
2198	{ MAC_UPDATE_IPQ,
2199	    (macop_t)mac_biba_update_ipq },
2200	{ MAC_CREATE_CRED,
2201	    (macop_t)mac_biba_create_cred },
2202	{ MAC_EXECVE_TRANSITION,
2203	    (macop_t)mac_biba_execve_transition },
2204	{ MAC_EXECVE_WILL_TRANSITION,
2205	    (macop_t)mac_biba_execve_will_transition },
2206	{ MAC_CREATE_PROC0,
2207	    (macop_t)mac_biba_create_proc0 },
2208	{ MAC_CREATE_PROC1,
2209	    (macop_t)mac_biba_create_proc1 },
2210	{ MAC_RELABEL_CRED,
2211	    (macop_t)mac_biba_relabel_cred },
2212	{ MAC_CHECK_BPFDESC_RECEIVE,
2213	    (macop_t)mac_biba_check_bpfdesc_receive },
2214	{ MAC_CHECK_CRED_RELABEL,
2215	    (macop_t)mac_biba_check_cred_relabel },
2216	{ MAC_CHECK_CRED_VISIBLE,
2217	    (macop_t)mac_biba_check_cred_visible },
2218	{ MAC_CHECK_IFNET_RELABEL,
2219	    (macop_t)mac_biba_check_ifnet_relabel },
2220	{ MAC_CHECK_IFNET_TRANSMIT,
2221	    (macop_t)mac_biba_check_ifnet_transmit },
2222	{ MAC_CHECK_MOUNT_STAT,
2223	    (macop_t)mac_biba_check_mount_stat },
2224	{ MAC_CHECK_PIPE_IOCTL,
2225	    (macop_t)mac_biba_check_pipe_ioctl },
2226	{ MAC_CHECK_PIPE_POLL,
2227	    (macop_t)mac_biba_check_pipe_poll },
2228	{ MAC_CHECK_PIPE_READ,
2229	    (macop_t)mac_biba_check_pipe_read },
2230	{ MAC_CHECK_PIPE_RELABEL,
2231	    (macop_t)mac_biba_check_pipe_relabel },
2232	{ MAC_CHECK_PIPE_STAT,
2233	    (macop_t)mac_biba_check_pipe_stat },
2234	{ MAC_CHECK_PIPE_WRITE,
2235	    (macop_t)mac_biba_check_pipe_write },
2236	{ MAC_CHECK_PROC_DEBUG,
2237	    (macop_t)mac_biba_check_proc_debug },
2238	{ MAC_CHECK_PROC_SCHED,
2239	    (macop_t)mac_biba_check_proc_sched },
2240	{ MAC_CHECK_PROC_SIGNAL,
2241	    (macop_t)mac_biba_check_proc_signal },
2242	{ MAC_CHECK_SOCKET_DELIVER,
2243	    (macop_t)mac_biba_check_socket_deliver },
2244	{ MAC_CHECK_SOCKET_RELABEL,
2245	    (macop_t)mac_biba_check_socket_relabel },
2246	{ MAC_CHECK_SOCKET_VISIBLE,
2247	    (macop_t)mac_biba_check_socket_visible },
2248	{ MAC_CHECK_VNODE_ACCESS,
2249	    (macop_t)mac_biba_check_vnode_open },
2250	{ MAC_CHECK_VNODE_CHDIR,
2251	    (macop_t)mac_biba_check_vnode_chdir },
2252	{ MAC_CHECK_VNODE_CHROOT,
2253	    (macop_t)mac_biba_check_vnode_chroot },
2254	{ MAC_CHECK_VNODE_CREATE,
2255	    (macop_t)mac_biba_check_vnode_create },
2256	{ MAC_CHECK_VNODE_DELETE,
2257	    (macop_t)mac_biba_check_vnode_delete },
2258	{ MAC_CHECK_VNODE_DELETEACL,
2259	    (macop_t)mac_biba_check_vnode_deleteacl },
2260	{ MAC_CHECK_VNODE_EXEC,
2261	    (macop_t)mac_biba_check_vnode_exec },
2262	{ MAC_CHECK_VNODE_GETACL,
2263	    (macop_t)mac_biba_check_vnode_getacl },
2264	{ MAC_CHECK_VNODE_GETEXTATTR,
2265	    (macop_t)mac_biba_check_vnode_getextattr },
2266	{ MAC_CHECK_VNODE_LINK,
2267	    (macop_t)mac_biba_check_vnode_link },
2268	{ MAC_CHECK_VNODE_LOOKUP,
2269	    (macop_t)mac_biba_check_vnode_lookup },
2270	{ MAC_CHECK_VNODE_MMAP,
2271	    (macop_t)mac_biba_check_vnode_mmap },
2272	{ MAC_CHECK_VNODE_MPROTECT,
2273	    (macop_t)mac_biba_check_vnode_mmap },
2274	{ MAC_CHECK_VNODE_OPEN,
2275	    (macop_t)mac_biba_check_vnode_open },
2276	{ MAC_CHECK_VNODE_POLL,
2277	    (macop_t)mac_biba_check_vnode_poll },
2278	{ MAC_CHECK_VNODE_READ,
2279	    (macop_t)mac_biba_check_vnode_read },
2280	{ MAC_CHECK_VNODE_READDIR,
2281	    (macop_t)mac_biba_check_vnode_readdir },
2282	{ MAC_CHECK_VNODE_READLINK,
2283	    (macop_t)mac_biba_check_vnode_readlink },
2284	{ MAC_CHECK_VNODE_RELABEL,
2285	    (macop_t)mac_biba_check_vnode_relabel },
2286	{ MAC_CHECK_VNODE_RENAME_FROM,
2287	    (macop_t)mac_biba_check_vnode_rename_from },
2288	{ MAC_CHECK_VNODE_RENAME_TO,
2289	    (macop_t)mac_biba_check_vnode_rename_to },
2290	{ MAC_CHECK_VNODE_REVOKE,
2291	    (macop_t)mac_biba_check_vnode_revoke },
2292	{ MAC_CHECK_VNODE_SETACL,
2293	    (macop_t)mac_biba_check_vnode_setacl },
2294	{ MAC_CHECK_VNODE_SETEXTATTR,
2295	    (macop_t)mac_biba_check_vnode_setextattr },
2296	{ MAC_CHECK_VNODE_SETFLAGS,
2297	    (macop_t)mac_biba_check_vnode_setflags },
2298	{ MAC_CHECK_VNODE_SETMODE,
2299	    (macop_t)mac_biba_check_vnode_setmode },
2300	{ MAC_CHECK_VNODE_SETOWNER,
2301	    (macop_t)mac_biba_check_vnode_setowner },
2302	{ MAC_CHECK_VNODE_SETUTIMES,
2303	    (macop_t)mac_biba_check_vnode_setutimes },
2304	{ MAC_CHECK_VNODE_STAT,
2305	    (macop_t)mac_biba_check_vnode_stat },
2306	{ MAC_CHECK_VNODE_WRITE,
2307	    (macop_t)mac_biba_check_vnode_write },
2308	{ MAC_OP_LAST, NULL }
2309};
2310
2311MAC_POLICY_SET(mac_biba_ops, trustedbsd_mac_biba, "TrustedBSD MAC/Biba",
2312    MPC_LOADTIME_FLAG_NOTLATE, &mac_biba_slot);
2313