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