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