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