2 * Copyright (c) 1999-2002, 2007 Robert N. M. Watson
3 * Copyright (c) 2001-2005 McAfee, Inc.
4 * Copyright (c) 2006 SPARTA, Inc.
7 * This software was developed by Robert Watson for the TrustedBSD Project.
9 * This software was developed for the FreeBSD Project in part by McAfee
10 * Research, the Security Research Division of McAfee, Inc. under
11 * DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA
12 * CHATS research program.
14 * This software was enhanced by SPARTA ISSO under SPAWAR contract
15 * N66001-04-C-6019 ("SEFOS").
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
26 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 * Developed by the TrustedBSD Project.
44 * Biba fixed label mandatory integrity policy.
47 #include <sys/param.h>
49 #include <sys/extattr.h>
50 #include <sys/kernel.h>
52 #include <sys/malloc.h>
54 #include <sys/mount.h>
58 #include <sys/systm.h>
59 #include <sys/sysproto.h>
60 #include <sys/sysent.h>
61 #include <sys/systm.h>
62 #include <sys/vnode.h>
64 #include <sys/socket.h>
65 #include <sys/socketvar.h>
68 #include <sys/sysctl.h>
73 #include <fs/devfs/devfs.h>
75 #include <net/bpfdesc.h>
77 #include <net/if_types.h>
78 #include <net/if_var.h>
80 #include <netinet/in.h>
81 #include <netinet/in_pcb.h>
82 #include <netinet/ip_var.h>
87 #include <security/mac/mac_policy.h>
88 #include <security/mac_biba/mac_biba.h>
90 SYSCTL_DECL(_security_mac);
92 SYSCTL_NODE(_security_mac, OID_AUTO, biba, CTLFLAG_RW, 0,
93 "TrustedBSD mac_biba policy controls");
95 static int biba_label_size = sizeof(struct mac_biba);
96 SYSCTL_INT(_security_mac_biba, OID_AUTO, label_size, CTLFLAG_RD,
97 &biba_label_size, 0, "Size of struct mac_biba");
99 static int biba_enabled = 1;
100 SYSCTL_INT(_security_mac_biba, OID_AUTO, enabled, CTLFLAG_RW, &biba_enabled,
101 0, "Enforce MAC/Biba policy");
102 TUNABLE_INT("security.mac.biba.enabled", &biba_enabled);
104 static int destroyed_not_inited;
105 SYSCTL_INT(_security_mac_biba, OID_AUTO, destroyed_not_inited, CTLFLAG_RD,
106 &destroyed_not_inited, 0, "Count of labels destroyed but not inited");
108 static int trust_all_interfaces = 0;
109 SYSCTL_INT(_security_mac_biba, OID_AUTO, trust_all_interfaces, CTLFLAG_RD,
110 &trust_all_interfaces, 0, "Consider all interfaces 'trusted' by MAC/Biba");
111 TUNABLE_INT("security.mac.biba.trust_all_interfaces", &trust_all_interfaces);
113 static char trusted_interfaces[128];
114 SYSCTL_STRING(_security_mac_biba, OID_AUTO, trusted_interfaces, CTLFLAG_RD,
115 trusted_interfaces, 0, "Interfaces considered 'trusted' by MAC/Biba");
116 TUNABLE_STR("security.mac.biba.trusted_interfaces", trusted_interfaces,
117 sizeof(trusted_interfaces));
119 static int max_compartments = MAC_BIBA_MAX_COMPARTMENTS;
120 SYSCTL_INT(_security_mac_biba, OID_AUTO, max_compartments, CTLFLAG_RD,
121 &max_compartments, 0, "Maximum supported compartments");
123 static int ptys_equal = 0;
124 SYSCTL_INT(_security_mac_biba, OID_AUTO, ptys_equal, CTLFLAG_RW, &ptys_equal,
125 0, "Label pty devices as biba/equal on create");
126 TUNABLE_INT("security.mac.biba.ptys_equal", &ptys_equal);
128 static int interfaces_equal;
129 SYSCTL_INT(_security_mac_biba, OID_AUTO, interfaces_equal, CTLFLAG_RW,
130 &interfaces_equal, 0, "Label network interfaces as biba/equal on create");
131 TUNABLE_INT("security.mac.biba.interfaces_equal", &interfaces_equal);
133 static int revocation_enabled = 0;
134 SYSCTL_INT(_security_mac_biba, OID_AUTO, revocation_enabled, CTLFLAG_RW,
135 &revocation_enabled, 0, "Revoke access to objects on relabel");
136 TUNABLE_INT("security.mac.biba.revocation_enabled", &revocation_enabled);
138 static int biba_slot;
139 #define SLOT(l) ((struct mac_biba *)mac_label_get((l), biba_slot))
140 #define SLOT_SET(l, val) mac_label_set((l), biba_slot, (uintptr_t)(val))
142 static uma_zone_t zone_biba;
145 biba_bit_set_empty(u_char *set) {
148 for (i = 0; i < MAC_BIBA_MAX_COMPARTMENTS >> 3; i++)
154 static struct mac_biba *
158 return (uma_zalloc(zone_biba, flag | M_ZERO));
162 biba_free(struct mac_biba *mb)
166 uma_zfree(zone_biba, mb);
168 atomic_add_int(&destroyed_not_inited, 1);
172 biba_atmostflags(struct mac_biba *mb, int flags)
175 if ((mb->mb_flags & flags) != mb->mb_flags)
181 biba_dominate_element(struct mac_biba_element *a, struct mac_biba_element *b)
185 switch (a->mbe_type) {
186 case MAC_BIBA_TYPE_EQUAL:
187 case MAC_BIBA_TYPE_HIGH:
190 case MAC_BIBA_TYPE_LOW:
191 switch (b->mbe_type) {
192 case MAC_BIBA_TYPE_GRADE:
193 case MAC_BIBA_TYPE_HIGH:
196 case MAC_BIBA_TYPE_EQUAL:
197 case MAC_BIBA_TYPE_LOW:
201 panic("biba_dominate_element: b->mbe_type invalid");
204 case MAC_BIBA_TYPE_GRADE:
205 switch (b->mbe_type) {
206 case MAC_BIBA_TYPE_EQUAL:
207 case MAC_BIBA_TYPE_LOW:
210 case MAC_BIBA_TYPE_HIGH:
213 case MAC_BIBA_TYPE_GRADE:
214 for (bit = 1; bit <= MAC_BIBA_MAX_COMPARTMENTS; bit++)
215 if (!MAC_BIBA_BIT_TEST(bit,
216 a->mbe_compartments) &&
217 MAC_BIBA_BIT_TEST(bit, b->mbe_compartments))
219 return (a->mbe_grade >= b->mbe_grade);
222 panic("biba_dominate_element: b->mbe_type invalid");
226 panic("biba_dominate_element: a->mbe_type invalid");
233 biba_subject_dominate_high(struct mac_biba *mb)
235 struct mac_biba_element *element;
237 KASSERT((mb->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) != 0,
238 ("biba_effective_in_range: mb not effective"));
239 element = &mb->mb_effective;
241 return (element->mbe_type == MAC_BIBA_TYPE_EQUAL ||
242 element->mbe_type == MAC_BIBA_TYPE_HIGH);
246 biba_range_in_range(struct mac_biba *rangea, struct mac_biba *rangeb)
249 return (biba_dominate_element(&rangeb->mb_rangehigh,
250 &rangea->mb_rangehigh) &&
251 biba_dominate_element(&rangea->mb_rangelow,
252 &rangeb->mb_rangelow));
256 biba_effective_in_range(struct mac_biba *effective, struct mac_biba *range)
259 KASSERT((effective->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) != 0,
260 ("biba_effective_in_range: a not effective"));
261 KASSERT((range->mb_flags & MAC_BIBA_FLAG_RANGE) != 0,
262 ("biba_effective_in_range: b not range"));
264 return (biba_dominate_element(&range->mb_rangehigh,
265 &effective->mb_effective) &&
266 biba_dominate_element(&effective->mb_effective,
267 &range->mb_rangelow));
273 biba_dominate_effective(struct mac_biba *a, struct mac_biba *b)
275 KASSERT((a->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) != 0,
276 ("biba_dominate_effective: a not effective"));
277 KASSERT((b->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) != 0,
278 ("biba_dominate_effective: b not effective"));
280 return (biba_dominate_element(&a->mb_effective, &b->mb_effective));
284 biba_equal_element(struct mac_biba_element *a, struct mac_biba_element *b)
287 if (a->mbe_type == MAC_BIBA_TYPE_EQUAL ||
288 b->mbe_type == MAC_BIBA_TYPE_EQUAL)
291 return (a->mbe_type == b->mbe_type && a->mbe_grade == b->mbe_grade);
295 biba_equal_effective(struct mac_biba *a, struct mac_biba *b)
298 KASSERT((a->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) != 0,
299 ("biba_equal_effective: a not effective"));
300 KASSERT((b->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) != 0,
301 ("biba_equal_effective: b not effective"));
303 return (biba_equal_element(&a->mb_effective, &b->mb_effective));
307 biba_contains_equal(struct mac_biba *mb)
310 if (mb->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) {
311 if (mb->mb_effective.mbe_type == MAC_BIBA_TYPE_EQUAL)
315 if (mb->mb_flags & MAC_BIBA_FLAG_RANGE) {
316 if (mb->mb_rangelow.mbe_type == MAC_BIBA_TYPE_EQUAL)
318 if (mb->mb_rangehigh.mbe_type == MAC_BIBA_TYPE_EQUAL)
326 biba_subject_privileged(struct mac_biba *mb)
329 KASSERT((mb->mb_flags & MAC_BIBA_FLAGS_BOTH) == MAC_BIBA_FLAGS_BOTH,
330 ("biba_subject_privileged: subject doesn't have both labels"));
332 /* If the effective is EQUAL, it's ok. */
333 if (mb->mb_effective.mbe_type == MAC_BIBA_TYPE_EQUAL)
336 /* If either range endpoint is EQUAL, it's ok. */
337 if (mb->mb_rangelow.mbe_type == MAC_BIBA_TYPE_EQUAL ||
338 mb->mb_rangehigh.mbe_type == MAC_BIBA_TYPE_EQUAL)
341 /* If the range is low-high, it's ok. */
342 if (mb->mb_rangelow.mbe_type == MAC_BIBA_TYPE_LOW &&
343 mb->mb_rangehigh.mbe_type == MAC_BIBA_TYPE_HIGH)
351 biba_high_effective(struct mac_biba *mb)
354 KASSERT((mb->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) != 0,
355 ("biba_equal_effective: mb not effective"));
357 return (mb->mb_effective.mbe_type == MAC_BIBA_TYPE_HIGH);
361 biba_valid(struct mac_biba *mb)
364 if (mb->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) {
365 switch (mb->mb_effective.mbe_type) {
366 case MAC_BIBA_TYPE_GRADE:
369 case MAC_BIBA_TYPE_EQUAL:
370 case MAC_BIBA_TYPE_HIGH:
371 case MAC_BIBA_TYPE_LOW:
372 if (mb->mb_effective.mbe_grade != 0 ||
373 !MAC_BIBA_BIT_SET_EMPTY(
374 mb->mb_effective.mbe_compartments))
382 if (mb->mb_effective.mbe_type != MAC_BIBA_TYPE_UNDEF)
386 if (mb->mb_flags & MAC_BIBA_FLAG_RANGE) {
387 switch (mb->mb_rangelow.mbe_type) {
388 case MAC_BIBA_TYPE_GRADE:
391 case MAC_BIBA_TYPE_EQUAL:
392 case MAC_BIBA_TYPE_HIGH:
393 case MAC_BIBA_TYPE_LOW:
394 if (mb->mb_rangelow.mbe_grade != 0 ||
395 !MAC_BIBA_BIT_SET_EMPTY(
396 mb->mb_rangelow.mbe_compartments))
404 switch (mb->mb_rangehigh.mbe_type) {
405 case MAC_BIBA_TYPE_GRADE:
408 case MAC_BIBA_TYPE_EQUAL:
409 case MAC_BIBA_TYPE_HIGH:
410 case MAC_BIBA_TYPE_LOW:
411 if (mb->mb_rangehigh.mbe_grade != 0 ||
412 !MAC_BIBA_BIT_SET_EMPTY(
413 mb->mb_rangehigh.mbe_compartments))
420 if (!biba_dominate_element(&mb->mb_rangehigh,
424 if (mb->mb_rangelow.mbe_type != MAC_BIBA_TYPE_UNDEF ||
425 mb->mb_rangehigh.mbe_type != MAC_BIBA_TYPE_UNDEF)
433 biba_set_range(struct mac_biba *mb, u_short typelow, u_short gradelow,
434 u_char *compartmentslow, u_short typehigh, u_short gradehigh,
435 u_char *compartmentshigh)
438 mb->mb_rangelow.mbe_type = typelow;
439 mb->mb_rangelow.mbe_grade = gradelow;
440 if (compartmentslow != NULL)
441 memcpy(mb->mb_rangelow.mbe_compartments, compartmentslow,
442 sizeof(mb->mb_rangelow.mbe_compartments));
443 mb->mb_rangehigh.mbe_type = typehigh;
444 mb->mb_rangehigh.mbe_grade = gradehigh;
445 if (compartmentshigh != NULL)
446 memcpy(mb->mb_rangehigh.mbe_compartments, compartmentshigh,
447 sizeof(mb->mb_rangehigh.mbe_compartments));
448 mb->mb_flags |= MAC_BIBA_FLAG_RANGE;
452 biba_set_effective(struct mac_biba *mb, u_short type, u_short grade,
453 u_char *compartments)
456 mb->mb_effective.mbe_type = type;
457 mb->mb_effective.mbe_grade = grade;
458 if (compartments != NULL)
459 memcpy(mb->mb_effective.mbe_compartments, compartments,
460 sizeof(mb->mb_effective.mbe_compartments));
461 mb->mb_flags |= MAC_BIBA_FLAG_EFFECTIVE;
465 biba_copy_range(struct mac_biba *labelfrom, struct mac_biba *labelto)
468 KASSERT((labelfrom->mb_flags & MAC_BIBA_FLAG_RANGE) != 0,
469 ("biba_copy_range: labelfrom not range"));
471 labelto->mb_rangelow = labelfrom->mb_rangelow;
472 labelto->mb_rangehigh = labelfrom->mb_rangehigh;
473 labelto->mb_flags |= MAC_BIBA_FLAG_RANGE;
477 biba_copy_effective(struct mac_biba *labelfrom, struct mac_biba *labelto)
480 KASSERT((labelfrom->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) != 0,
481 ("biba_copy_effective: labelfrom not effective"));
483 labelto->mb_effective = labelfrom->mb_effective;
484 labelto->mb_flags |= MAC_BIBA_FLAG_EFFECTIVE;
488 biba_copy(struct mac_biba *source, struct mac_biba *dest)
491 if (source->mb_flags & MAC_BIBA_FLAG_EFFECTIVE)
492 biba_copy_effective(source, dest);
493 if (source->mb_flags & MAC_BIBA_FLAG_RANGE)
494 biba_copy_range(source, dest);
498 * Policy module operations.
501 biba_init(struct mac_policy_conf *conf)
504 zone_biba = uma_zcreate("mac_biba", sizeof(struct mac_biba), NULL,
505 NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
512 biba_init_label(struct label *label)
515 SLOT_SET(label, biba_alloc(M_WAITOK));
519 biba_init_label_waitcheck(struct label *label, int flag)
522 SLOT_SET(label, biba_alloc(flag));
523 if (SLOT(label) == NULL)
530 biba_destroy_label(struct label *label)
533 biba_free(SLOT(label));
534 SLOT_SET(label, NULL);
538 * biba_element_to_string() accepts an sbuf and Biba element. It converts
539 * the Biba element to a string and stores the result in the sbuf; if there
540 * isn't space in the sbuf, -1 is returned.
543 biba_element_to_string(struct sbuf *sb, struct mac_biba_element *element)
547 switch (element->mbe_type) {
548 case MAC_BIBA_TYPE_HIGH:
549 return (sbuf_printf(sb, "high"));
551 case MAC_BIBA_TYPE_LOW:
552 return (sbuf_printf(sb, "low"));
554 case MAC_BIBA_TYPE_EQUAL:
555 return (sbuf_printf(sb, "equal"));
557 case MAC_BIBA_TYPE_GRADE:
558 if (sbuf_printf(sb, "%d", element->mbe_grade) == -1)
562 for (i = 1; i <= MAC_BIBA_MAX_COMPARTMENTS; i++) {
563 if (MAC_BIBA_BIT_TEST(i, element->mbe_compartments)) {
565 if (sbuf_putc(sb, ':') == -1)
567 if (sbuf_printf(sb, "%d", i) == -1)
571 if (sbuf_printf(sb, "+%d", i) == -1)
579 panic("biba_element_to_string: invalid type (%d)",
585 * biba_to_string() converts a Biba label to a string, and places the results
586 * in the passed sbuf. It returns 0 on success, or EINVAL if there isn't
587 * room in the sbuf. Note: the sbuf will be modified even in a failure case,
588 * so the caller may need to revert the sbuf by restoring the offset if
592 biba_to_string(struct sbuf *sb, struct mac_biba *mb)
595 if (mb->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) {
596 if (biba_element_to_string(sb, &mb->mb_effective) == -1)
600 if (mb->mb_flags & MAC_BIBA_FLAG_RANGE) {
601 if (sbuf_putc(sb, '(') == -1)
604 if (biba_element_to_string(sb, &mb->mb_rangelow) == -1)
607 if (sbuf_putc(sb, '-') == -1)
610 if (biba_element_to_string(sb, &mb->mb_rangehigh) == -1)
613 if (sbuf_putc(sb, ')') == -1)
621 biba_externalize_label(struct label *label, char *element_name,
622 struct sbuf *sb, int *claimed)
626 if (strcmp(MAC_BIBA_LABEL_NAME, element_name) != 0)
632 return (biba_to_string(sb, mb));
636 biba_parse_element(struct mac_biba_element *element, char *string)
638 char *compartment, *end, *grade;
641 if (strcmp(string, "high") == 0 || strcmp(string, "hi") == 0) {
642 element->mbe_type = MAC_BIBA_TYPE_HIGH;
643 element->mbe_grade = MAC_BIBA_TYPE_UNDEF;
644 } else if (strcmp(string, "low") == 0 || strcmp(string, "lo") == 0) {
645 element->mbe_type = MAC_BIBA_TYPE_LOW;
646 element->mbe_grade = MAC_BIBA_TYPE_UNDEF;
647 } else if (strcmp(string, "equal") == 0 ||
648 strcmp(string, "eq") == 0) {
649 element->mbe_type = MAC_BIBA_TYPE_EQUAL;
650 element->mbe_grade = MAC_BIBA_TYPE_UNDEF;
652 element->mbe_type = MAC_BIBA_TYPE_GRADE;
655 * Numeric grade piece of the element.
657 grade = strsep(&string, ":");
658 value = strtol(grade, &end, 10);
659 if (end == grade || *end != '\0')
661 if (value < 0 || value > 65535)
663 element->mbe_grade = value;
666 * Optional compartment piece of the element. If none are
667 * included, we assume that the label has no compartments.
674 while ((compartment = strsep(&string, "+")) != NULL) {
675 value = strtol(compartment, &end, 10);
676 if (compartment == end || *end != '\0')
678 if (value < 1 || value > MAC_BIBA_MAX_COMPARTMENTS)
680 MAC_BIBA_BIT_SET(value, element->mbe_compartments);
688 * Note: destructively consumes the string, make a local copy before calling
689 * if that's a problem.
692 biba_parse(struct mac_biba *mb, char *string)
694 char *rangehigh, *rangelow, *effective;
697 effective = strsep(&string, "(");
698 if (*effective == '\0')
701 if (string != NULL) {
702 rangelow = strsep(&string, "-");
705 rangehigh = strsep(&string, ")");
715 KASSERT((rangelow != NULL && rangehigh != NULL) ||
716 (rangelow == NULL && rangehigh == NULL),
717 ("biba_parse: range mismatch"));
719 bzero(mb, sizeof(*mb));
720 if (effective != NULL) {
721 error = biba_parse_element(&mb->mb_effective, effective);
724 mb->mb_flags |= MAC_BIBA_FLAG_EFFECTIVE;
727 if (rangelow != NULL) {
728 error = biba_parse_element(&mb->mb_rangelow, rangelow);
731 error = biba_parse_element(&mb->mb_rangehigh, rangehigh);
734 mb->mb_flags |= MAC_BIBA_FLAG_RANGE;
737 error = biba_valid(mb);
745 biba_internalize_label(struct label *label, char *element_name,
746 char *element_data, int *claimed)
748 struct mac_biba *mb, mb_temp;
751 if (strcmp(MAC_BIBA_LABEL_NAME, element_name) != 0)
756 error = biba_parse(&mb_temp, element_data);
767 biba_copy_label(struct label *src, struct label *dest)
770 *SLOT(dest) = *SLOT(src);
774 * Object-specific entry point implementations are sorted alphabetically by
775 * object type name and then by operation.
778 biba_bpfdesc_check_receive(struct bpf_d *d, struct label *dlabel,
779 struct ifnet *ifp, struct label *ifplabel)
781 struct mac_biba *a, *b;
789 if (biba_equal_effective(a, b))
795 biba_bpfdesc_create(struct ucred *cred, struct bpf_d *d,
796 struct label *dlabel)
798 struct mac_biba *source, *dest;
800 source = SLOT(cred->cr_label);
803 biba_copy_effective(source, dest);
807 biba_bpfdesc_create_mbuf(struct bpf_d *d, struct label *dlabel,
808 struct mbuf *m, struct label *mlabel)
810 struct mac_biba *source, *dest;
812 source = SLOT(dlabel);
815 biba_copy_effective(source, dest);
819 biba_cred_check_relabel(struct ucred *cred, struct label *newlabel)
821 struct mac_biba *subj, *new;
824 subj = SLOT(cred->cr_label);
825 new = SLOT(newlabel);
828 * If there is a Biba label update for the credential, it may
829 * be an update of the effective, range, or both.
831 error = biba_atmostflags(new, MAC_BIBA_FLAGS_BOTH);
836 * If the Biba label is to be changed, authorize as appropriate.
838 if (new->mb_flags & MAC_BIBA_FLAGS_BOTH) {
840 * If the change request modifies both the Biba label
841 * effective and range, check that the new effective will be
844 if ((new->mb_flags & MAC_BIBA_FLAGS_BOTH) ==
845 MAC_BIBA_FLAGS_BOTH &&
846 !biba_effective_in_range(new, new))
850 * To change the Biba effective label on a credential, the
851 * new effective label must be in the current range.
853 if (new->mb_flags & MAC_BIBA_FLAG_EFFECTIVE &&
854 !biba_effective_in_range(new, subj))
858 * To change the Biba range on a credential, the new range
859 * label must be in the current range.
861 if (new->mb_flags & MAC_BIBA_FLAG_RANGE &&
862 !biba_range_in_range(new, subj))
866 * To have EQUAL in any component of the new credential Biba
867 * label, the subject must already have EQUAL in their label.
869 if (biba_contains_equal(new)) {
870 error = biba_subject_privileged(subj);
880 biba_cred_check_visible(struct ucred *u1, struct ucred *u2)
882 struct mac_biba *subj, *obj;
887 subj = SLOT(u1->cr_label);
888 obj = SLOT(u2->cr_label);
891 if (!biba_dominate_effective(obj, subj))
898 biba_cred_relabel(struct ucred *cred, struct label *newlabel)
900 struct mac_biba *source, *dest;
902 source = SLOT(newlabel);
903 dest = SLOT(cred->cr_label);
905 biba_copy(source, dest);
909 biba_devfs_create_device(struct ucred *cred, struct mount *mp,
910 struct cdev *dev, struct devfs_dirent *de, struct label *delabel)
916 if (strcmp(dev->si_name, "null") == 0 ||
917 strcmp(dev->si_name, "zero") == 0 ||
918 strcmp(dev->si_name, "random") == 0 ||
919 strncmp(dev->si_name, "fd/", strlen("fd/")) == 0)
920 biba_type = MAC_BIBA_TYPE_EQUAL;
921 else if (ptys_equal &&
922 (strncmp(dev->si_name, "ttyp", strlen("ttyp")) == 0 ||
923 strncmp(dev->si_name, "ptyp", strlen("ptyp")) == 0))
924 biba_type = MAC_BIBA_TYPE_EQUAL;
926 biba_type = MAC_BIBA_TYPE_HIGH;
927 biba_set_effective(mb, biba_type, 0, NULL);
931 biba_devfs_create_directory(struct mount *mp, char *dirname, int dirnamelen,
932 struct devfs_dirent *de, struct label *delabel)
938 biba_set_effective(mb, MAC_BIBA_TYPE_HIGH, 0, NULL);
942 biba_devfs_create_symlink(struct ucred *cred, struct mount *mp,
943 struct devfs_dirent *dd, struct label *ddlabel, struct devfs_dirent *de,
944 struct label *delabel)
946 struct mac_biba *source, *dest;
948 source = SLOT(cred->cr_label);
949 dest = SLOT(delabel);
951 biba_copy_effective(source, dest);
955 biba_devfs_update(struct mount *mp, struct devfs_dirent *de,
956 struct label *delabel, struct vnode *vp, struct label *vplabel)
958 struct mac_biba *source, *dest;
960 source = SLOT(vplabel);
961 dest = SLOT(delabel);
963 biba_copy(source, dest);
967 biba_devfs_vnode_associate(struct mount *mp, struct label *mntlabel,
968 struct devfs_dirent *de, struct label *delabel, struct vnode *vp,
969 struct label *vplabel)
971 struct mac_biba *source, *dest;
973 source = SLOT(delabel);
974 dest = SLOT(vplabel);
976 biba_copy_effective(source, dest);
980 biba_ifnet_check_relabel(struct ucred *cred, struct ifnet *ifp,
981 struct label *ifplabel, struct label *newlabel)
983 struct mac_biba *subj, *new;
986 subj = SLOT(cred->cr_label);
987 new = SLOT(newlabel);
990 * If there is a Biba label update for the interface, it may be an
991 * update of the effective, range, or both.
993 error = biba_atmostflags(new, MAC_BIBA_FLAGS_BOTH);
998 * Relabling network interfaces requires Biba privilege.
1000 error = biba_subject_privileged(subj);
1008 biba_ifnet_check_transmit(struct ifnet *ifp, struct label *ifplabel,
1009 struct mbuf *m, struct label *mlabel)
1011 struct mac_biba *p, *i;
1019 return (biba_effective_in_range(p, i) ? 0 : EACCES);
1023 biba_ifnet_create(struct ifnet *ifp, struct label *ifplabel)
1025 char tifname[IFNAMSIZ], *p, *q;
1026 char tiflist[sizeof(trusted_interfaces)];
1027 struct mac_biba *dest;
1030 dest = SLOT(ifplabel);
1032 if (ifp->if_type == IFT_LOOP || interfaces_equal != 0) {
1033 type = MAC_BIBA_TYPE_EQUAL;
1037 if (trust_all_interfaces) {
1038 type = MAC_BIBA_TYPE_HIGH;
1042 type = MAC_BIBA_TYPE_LOW;
1044 if (trusted_interfaces[0] == '\0' ||
1045 !strvalid(trusted_interfaces, sizeof(trusted_interfaces)))
1048 bzero(tiflist, sizeof(tiflist));
1049 for (p = trusted_interfaces, q = tiflist; *p != '\0'; p++, q++)
1050 if(*p != ' ' && *p != '\t')
1053 for (p = q = tiflist;; p++) {
1054 if (*p == ',' || *p == '\0') {
1056 if (len < IFNAMSIZ) {
1057 bzero(tifname, sizeof(tifname));
1058 bcopy(q, tifname, len);
1059 if (strcmp(tifname, ifp->if_xname) == 0) {
1060 type = MAC_BIBA_TYPE_HIGH;
1065 printf("mac_biba warning: interface name "
1066 "\"%s\" is too long (must be < %d)\n",
1075 biba_set_effective(dest, type, 0, NULL);
1076 biba_set_range(dest, type, 0, NULL, type, 0, NULL);
1080 biba_ifnet_create_mbuf(struct ifnet *ifp, struct label *ifplabel,
1081 struct mbuf *m, struct label *mlabel)
1083 struct mac_biba *source, *dest;
1085 source = SLOT(ifplabel);
1086 dest = SLOT(mlabel);
1088 biba_copy_effective(source, dest);
1092 biba_ifnet_relabel(struct ucred *cred, struct ifnet *ifp,
1093 struct label *ifplabel, struct label *newlabel)
1095 struct mac_biba *source, *dest;
1097 source = SLOT(newlabel);
1098 dest = SLOT(ifplabel);
1100 biba_copy(source, dest);
1104 biba_inpcb_check_deliver(struct inpcb *inp, struct label *inplabel,
1105 struct mbuf *m, struct label *mlabel)
1107 struct mac_biba *p, *i;
1115 return (biba_equal_effective(p, i) ? 0 : EACCES);
1119 biba_inpcb_check_visible(struct ucred *cred, struct inpcb *inp,
1120 struct label *inplabel)
1122 struct mac_biba *subj, *obj;
1127 subj = SLOT(cred->cr_label);
1128 obj = SLOT(inplabel);
1130 if (!biba_dominate_effective(obj, subj))
1137 biba_inpcb_create(struct socket *so, struct label *solabel,
1138 struct inpcb *inp, struct label *inplabel)
1140 struct mac_biba *source, *dest;
1142 source = SLOT(solabel);
1143 dest = SLOT(inplabel);
1145 biba_copy_effective(source, dest);
1149 biba_inpcb_create_mbuf(struct inpcb *inp, struct label *inplabel,
1150 struct mbuf *m, struct label *mlabel)
1152 struct mac_biba *source, *dest;
1154 source = SLOT(inplabel);
1155 dest = SLOT(mlabel);
1157 biba_copy_effective(source, dest);
1161 biba_inpcb_sosetlabel(struct socket *so, struct label *solabel,
1162 struct inpcb *inp, struct label *inplabel)
1164 struct mac_biba *source, *dest;
1166 source = SLOT(solabel);
1167 dest = SLOT(inplabel);
1169 biba_copy(source, dest);
1173 biba_ipq_create(struct mbuf *m, struct label *mlabel, struct ipq *q,
1174 struct label *qlabel)
1176 struct mac_biba *source, *dest;
1178 source = SLOT(mlabel);
1179 dest = SLOT(qlabel);
1181 biba_copy_effective(source, dest);
1185 biba_ipq_match(struct mbuf *m, struct label *mlabel, struct ipq *q,
1186 struct label *qlabel)
1188 struct mac_biba *a, *b;
1193 return (biba_equal_effective(a, b));
1197 biba_ipq_reassemble(struct ipq *q, struct label *qlabel, struct mbuf *m,
1198 struct label *mlabel)
1200 struct mac_biba *source, *dest;
1202 source = SLOT(qlabel);
1203 dest = SLOT(mlabel);
1205 /* Just use the head, since we require them all to match. */
1206 biba_copy_effective(source, dest);
1210 biba_ipq_update(struct mbuf *m, struct label *mlabel, struct ipq *q,
1211 struct label *qlabel)
1214 /* NOOP: we only accept matching labels, so no need to update */
1218 biba_kld_check_load(struct ucred *cred, struct vnode *vp,
1219 struct label *vplabel)
1221 struct mac_biba *subj, *obj;
1227 subj = SLOT(cred->cr_label);
1229 error = biba_subject_privileged(subj);
1233 obj = SLOT(vplabel);
1234 if (!biba_high_effective(obj))
1241 biba_mount_check_stat(struct ucred *cred, struct mount *mp,
1242 struct label *mplabel)
1244 struct mac_biba *subj, *obj;
1249 subj = SLOT(cred->cr_label);
1250 obj = SLOT(mplabel);
1252 if (!biba_dominate_effective(obj, subj))
1259 biba_mount_create(struct ucred *cred, struct mount *mp,
1260 struct label *mplabel)
1262 struct mac_biba *source, *dest;
1264 source = SLOT(cred->cr_label);
1265 dest = SLOT(mplabel);
1267 biba_copy_effective(source, dest);
1271 biba_netatalk_aarp_send(struct ifnet *ifp, struct label *ifplabel,
1272 struct mbuf *m, struct label *mlabel)
1274 struct mac_biba *dest;
1276 dest = SLOT(mlabel);
1278 biba_set_effective(dest, MAC_BIBA_TYPE_EQUAL, 0, NULL);
1282 biba_netinet_arp_send(struct ifnet *ifp, struct label *ifplabel,
1283 struct mbuf *m, struct label *mlabel)
1285 struct mac_biba *dest;
1287 dest = SLOT(mlabel);
1289 biba_set_effective(dest, MAC_BIBA_TYPE_EQUAL, 0, NULL);
1293 biba_netinet_firewall_reply(struct mbuf *mrecv, struct label *mrecvlabel,
1294 struct mbuf *msend, struct label *msendlabel)
1296 struct mac_biba *source, *dest;
1298 source = SLOT(mrecvlabel);
1299 dest = SLOT(msendlabel);
1301 biba_copy_effective(source, dest);
1305 biba_netinet_firewall_send(struct mbuf *m, struct label *mlabel)
1307 struct mac_biba *dest;
1309 dest = SLOT(mlabel);
1311 /* XXX: where is the label for the firewall really coming from? */
1312 biba_set_effective(dest, MAC_BIBA_TYPE_EQUAL, 0, NULL);
1316 biba_netinet_fragment(struct mbuf *m, struct label *mlabel,
1317 struct mbuf *frag, struct label *fraglabel)
1319 struct mac_biba *source, *dest;
1321 source = SLOT(mlabel);
1322 dest = SLOT(fraglabel);
1324 biba_copy_effective(source, dest);
1328 biba_netinet_icmp_reply(struct mbuf *mrecv, struct label *mrecvlabel,
1329 struct mbuf *msend, struct label *msendlabel)
1331 struct mac_biba *source, *dest;
1333 source = SLOT(mrecvlabel);
1334 dest = SLOT(msendlabel);
1336 biba_copy_effective(source, dest);
1340 biba_netinet_igmp_send(struct ifnet *ifp, struct label *ifplabel,
1341 struct mbuf *m, struct label *mlabel)
1343 struct mac_biba *dest;
1345 dest = SLOT(mlabel);
1347 biba_set_effective(dest, MAC_BIBA_TYPE_EQUAL, 0, NULL);
1351 biba_netinet6_nd6_send(struct ifnet *ifp, struct label *ifplabel,
1352 struct mbuf *m, struct label *mlabel)
1354 struct mac_biba *dest;
1356 dest = SLOT(mlabel);
1358 biba_set_effective(dest, MAC_BIBA_TYPE_EQUAL, 0, NULL);
1362 biba_pipe_check_ioctl(struct ucred *cred, struct pipepair *pp,
1363 struct label *pplabel, unsigned long cmd, void /* caddr_t */ *data)
1369 /* XXX: This will be implemented soon... */
1375 biba_pipe_check_poll(struct ucred *cred, struct pipepair *pp,
1376 struct label *pplabel)
1378 struct mac_biba *subj, *obj;
1383 subj = SLOT(cred->cr_label);
1384 obj = SLOT(pplabel);
1386 if (!biba_dominate_effective(obj, subj))
1393 biba_pipe_check_read(struct ucred *cred, struct pipepair *pp,
1394 struct label *pplabel)
1396 struct mac_biba *subj, *obj;
1401 subj = SLOT(cred->cr_label);
1402 obj = SLOT(pplabel);
1404 if (!biba_dominate_effective(obj, subj))
1411 biba_pipe_check_relabel(struct ucred *cred, struct pipepair *pp,
1412 struct label *pplabel, struct label *newlabel)
1414 struct mac_biba *subj, *obj, *new;
1417 new = SLOT(newlabel);
1418 subj = SLOT(cred->cr_label);
1419 obj = SLOT(pplabel);
1422 * If there is a Biba label update for a pipe, it must be a effective
1425 error = biba_atmostflags(new, MAC_BIBA_FLAG_EFFECTIVE);
1430 * To perform a relabel of a pipe (Biba label or not), Biba must
1431 * authorize the relabel.
1433 if (!biba_effective_in_range(obj, subj))
1437 * If the Biba label is to be changed, authorize as appropriate.
1439 if (new->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) {
1441 * To change the Biba label on a pipe, the new pipe label
1442 * must be in the subject range.
1444 if (!biba_effective_in_range(new, subj))
1448 * To change the Biba label on a pipe to be EQUAL, the
1449 * subject must have appropriate privilege.
1451 if (biba_contains_equal(new)) {
1452 error = biba_subject_privileged(subj);
1462 biba_pipe_check_stat(struct ucred *cred, struct pipepair *pp,
1463 struct label *pplabel)
1465 struct mac_biba *subj, *obj;
1470 subj = SLOT(cred->cr_label);
1471 obj = SLOT(pplabel);
1473 if (!biba_dominate_effective(obj, subj))
1480 biba_pipe_check_write(struct ucred *cred, struct pipepair *pp,
1481 struct label *pplabel)
1483 struct mac_biba *subj, *obj;
1488 subj = SLOT(cred->cr_label);
1489 obj = SLOT(pplabel);
1491 if (!biba_dominate_effective(subj, obj))
1498 biba_pipe_create(struct ucred *cred, struct pipepair *pp,
1499 struct label *pplabel)
1501 struct mac_biba *source, *dest;
1503 source = SLOT(cred->cr_label);
1504 dest = SLOT(pplabel);
1506 biba_copy_effective(source, dest);
1510 biba_pipe_relabel(struct ucred *cred, struct pipepair *pp,
1511 struct label *pplabel, struct label *newlabel)
1513 struct mac_biba *source, *dest;
1515 source = SLOT(newlabel);
1516 dest = SLOT(pplabel);
1518 biba_copy(source, dest);
1522 biba_posixsem_check_openunlink(struct ucred *cred, struct ksem *ks,
1523 struct label *kslabel)
1525 struct mac_biba *subj, *obj;
1530 subj = SLOT(cred->cr_label);
1531 obj = SLOT(kslabel);
1533 if (!biba_dominate_effective(subj, obj))
1540 biba_posixsem_check_write(struct ucred *active_cred, struct ucred *file_cred,
1541 struct ksem *ks, struct label *kslabel)
1543 struct mac_biba *subj, *obj;
1548 subj = SLOT(active_cred->cr_label);
1549 obj = SLOT(kslabel);
1551 if (!biba_dominate_effective(subj, obj))
1558 biba_posixsem_check_rdonly(struct ucred *active_cred, struct ucred *file_cred,
1559 struct ksem *ks, struct label *kslabel)
1561 struct mac_biba *subj, *obj;
1566 subj = SLOT(active_cred->cr_label);
1567 obj = SLOT(kslabel);
1569 if (!biba_dominate_effective(obj, subj))
1576 biba_posixsem_create(struct ucred *cred, struct ksem *ks,
1577 struct label *kslabel)
1579 struct mac_biba *source, *dest;
1581 source = SLOT(cred->cr_label);
1582 dest = SLOT(kslabel);
1584 biba_copy_effective(source, dest);
1588 * Some system privileges are allowed regardless of integrity grade; others
1589 * are allowed only when running with privilege with respect to the Biba
1590 * policy as they might otherwise allow bypassing of the integrity policy.
1593 biba_priv_check(struct ucred *cred, int priv)
1595 struct mac_biba *subj;
1602 * Exempt only specific privileges from the Biba integrity policy.
1609 * Allow processes to manipulate basic process audit properties, and
1610 * to submit audit records.
1612 case PRIV_AUDIT_GETAUDIT:
1613 case PRIV_AUDIT_SETAUDIT:
1614 case PRIV_AUDIT_SUBMIT:
1617 * Allow processes to manipulate their regular UNIX credentials.
1619 case PRIV_CRED_SETUID:
1620 case PRIV_CRED_SETEUID:
1621 case PRIV_CRED_SETGID:
1622 case PRIV_CRED_SETEGID:
1623 case PRIV_CRED_SETGROUPS:
1624 case PRIV_CRED_SETREUID:
1625 case PRIV_CRED_SETREGID:
1626 case PRIV_CRED_SETRESUID:
1627 case PRIV_CRED_SETRESGID:
1630 * Allow processes to perform system monitoring.
1632 case PRIV_SEEOTHERGIDS:
1633 case PRIV_SEEOTHERUIDS:
1637 * Allow access to general process debugging facilities. We
1638 * separately control debugging based on MAC label.
1640 case PRIV_DEBUG_DIFFCRED:
1641 case PRIV_DEBUG_SUGID:
1642 case PRIV_DEBUG_UNPRIV:
1645 * Allow manipulating jails.
1647 case PRIV_JAIL_ATTACH:
1650 * Allow privilege with respect to the Partition policy, but not the
1653 case PRIV_MAC_PARTITION:
1656 * Allow privilege with respect to process resource limits and login
1659 case PRIV_PROC_LIMIT:
1660 case PRIV_PROC_SETLOGIN:
1661 case PRIV_PROC_SETRLIMIT:
1664 * Allow System V and POSIX IPC privileges.
1667 case PRIV_IPC_WRITE:
1668 case PRIV_IPC_ADMIN:
1669 case PRIV_IPC_MSGSIZE:
1673 * Allow certain scheduler manipulations -- possibly this should be
1674 * controlled by more fine-grained policy, as potentially low
1675 * integrity processes can deny CPU to higher integrity ones.
1677 case PRIV_SCHED_DIFFCRED:
1678 case PRIV_SCHED_SETPRIORITY:
1679 case PRIV_SCHED_RTPRIO:
1680 case PRIV_SCHED_SETPOLICY:
1681 case PRIV_SCHED_SET:
1682 case PRIV_SCHED_SETPARAM:
1685 * More IPC privileges.
1687 case PRIV_SEM_WRITE:
1690 * Allow signaling privileges subject to integrity policy.
1692 case PRIV_SIGNAL_DIFFCRED:
1693 case PRIV_SIGNAL_SUGID:
1696 * Allow access to only limited sysctls from lower integrity levels;
1697 * piggy-back on the Jail definition.
1699 case PRIV_SYSCTL_WRITEJAIL:
1702 * Allow TTY-based privileges, subject to general device access using
1703 * labels on TTY device nodes, but not console privilege.
1705 case PRIV_TTY_DRAINWAIT:
1706 case PRIV_TTY_DTRWAIT:
1707 case PRIV_TTY_EXCLUSIVE:
1708 case PRIV_TTY_PRISON:
1713 * Grant most VFS privileges, as almost all are in practice bounded
1714 * by more specific checks using labels.
1717 case PRIV_VFS_WRITE:
1718 case PRIV_VFS_ADMIN:
1720 case PRIV_VFS_LOOKUP:
1721 case PRIV_VFS_CHFLAGS_DEV:
1722 case PRIV_VFS_CHOWN:
1723 case PRIV_VFS_CHROOT:
1724 case PRIV_VFS_RETAINSUGID:
1725 case PRIV_VFS_EXCEEDQUOTA:
1726 case PRIV_VFS_FCHROOT:
1727 case PRIV_VFS_FHOPEN:
1728 case PRIV_VFS_FHSTATFS:
1729 case PRIV_VFS_GENERATION:
1730 case PRIV_VFS_GETFH:
1731 case PRIV_VFS_GETQUOTA:
1733 case PRIV_VFS_MOUNT:
1734 case PRIV_VFS_MOUNT_OWNER:
1735 case PRIV_VFS_MOUNT_PERM:
1736 case PRIV_VFS_MOUNT_SUIDDIR:
1737 case PRIV_VFS_MOUNT_NONUSER:
1738 case PRIV_VFS_SETGID:
1739 case PRIV_VFS_STICKYFILE:
1740 case PRIV_VFS_SYSFLAGS:
1741 case PRIV_VFS_UNMOUNT:
1744 * Allow VM privileges; it would be nice if these were subject to
1747 case PRIV_VM_MADV_PROTECT:
1749 case PRIV_VM_MUNLOCK:
1752 * Allow some but not all network privileges. In general, dont allow
1753 * reconfiguring the network stack, just normal use.
1755 case PRIV_NETATALK_RESERVEDPORT:
1756 case PRIV_NETINET_RESERVEDPORT:
1757 case PRIV_NETINET_RAW:
1758 case PRIV_NETINET_REUSEPORT:
1759 case PRIV_NETIPX_RESERVEDPORT:
1760 case PRIV_NETIPX_RAW:
1764 * All remaining system privileges are allow only if the process
1765 * holds privilege with respect to the Biba policy.
1768 subj = SLOT(cred->cr_label);
1769 error = biba_subject_privileged(subj);
1777 biba_proc_associate_nfsd(struct ucred *cred)
1779 struct mac_biba *label;
1781 label = SLOT(cred->cr_label);
1782 biba_set_effective(label, MAC_BIBA_TYPE_LOW, 0, NULL);
1783 biba_set_range(label, MAC_BIBA_TYPE_LOW, 0, NULL, MAC_BIBA_TYPE_HIGH,
1788 biba_proc_check_debug(struct ucred *cred, struct proc *p)
1790 struct mac_biba *subj, *obj;
1795 subj = SLOT(cred->cr_label);
1796 obj = SLOT(p->p_ucred->cr_label);
1798 /* XXX: range checks */
1799 if (!biba_dominate_effective(obj, subj))
1801 if (!biba_dominate_effective(subj, obj))
1808 biba_proc_check_sched(struct ucred *cred, struct proc *p)
1810 struct mac_biba *subj, *obj;
1815 subj = SLOT(cred->cr_label);
1816 obj = SLOT(p->p_ucred->cr_label);
1818 /* XXX: range checks */
1819 if (!biba_dominate_effective(obj, subj))
1821 if (!biba_dominate_effective(subj, obj))
1828 biba_proc_check_signal(struct ucred *cred, struct proc *p, int signum)
1830 struct mac_biba *subj, *obj;
1835 subj = SLOT(cred->cr_label);
1836 obj = SLOT(p->p_ucred->cr_label);
1838 /* XXX: range checks */
1839 if (!biba_dominate_effective(obj, subj))
1841 if (!biba_dominate_effective(subj, obj))
1848 biba_socket_check_deliver(struct socket *so, struct label *solabel,
1849 struct mbuf *m, struct label *mlabel)
1851 struct mac_biba *p, *s;
1859 return (biba_equal_effective(p, s) ? 0 : EACCES);
1863 biba_proc_create_init(struct ucred *cred)
1865 struct mac_biba *dest;
1867 dest = SLOT(cred->cr_label);
1869 biba_set_effective(dest, MAC_BIBA_TYPE_HIGH, 0, NULL);
1870 biba_set_range(dest, MAC_BIBA_TYPE_LOW, 0, NULL, MAC_BIBA_TYPE_HIGH,
1875 biba_proc_create_swapper(struct ucred *cred)
1877 struct mac_biba *dest;
1879 dest = SLOT(cred->cr_label);
1881 biba_set_effective(dest, MAC_BIBA_TYPE_EQUAL, 0, NULL);
1882 biba_set_range(dest, MAC_BIBA_TYPE_LOW, 0, NULL, MAC_BIBA_TYPE_HIGH,
1887 biba_socket_check_relabel(struct ucred *cred, struct socket *so,
1888 struct label *solabel, struct label *newlabel)
1890 struct mac_biba *subj, *obj, *new;
1893 new = SLOT(newlabel);
1894 subj = SLOT(cred->cr_label);
1895 obj = SLOT(solabel);
1898 * If there is a Biba label update for the socket, it may be an
1899 * update of effective.
1901 error = biba_atmostflags(new, MAC_BIBA_FLAG_EFFECTIVE);
1906 * To relabel a socket, the old socket effective must be in the
1909 if (!biba_effective_in_range(obj, subj))
1913 * If the Biba label is to be changed, authorize as appropriate.
1915 if (new->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) {
1917 * To relabel a socket, the new socket effective must be in
1918 * the subject range.
1920 if (!biba_effective_in_range(new, subj))
1924 * To change the Biba label on the socket to contain EQUAL,
1925 * the subject must have appropriate privilege.
1927 if (biba_contains_equal(new)) {
1928 error = biba_subject_privileged(subj);
1938 biba_socket_check_visible(struct ucred *cred, struct socket *so,
1939 struct label *solabel)
1941 struct mac_biba *subj, *obj;
1946 subj = SLOT(cred->cr_label);
1947 obj = SLOT(solabel);
1949 if (!biba_dominate_effective(obj, subj))
1956 biba_socket_create(struct ucred *cred, struct socket *so,
1957 struct label *solabel)
1959 struct mac_biba *source, *dest;
1961 source = SLOT(cred->cr_label);
1962 dest = SLOT(solabel);
1964 biba_copy_effective(source, dest);
1968 biba_socket_create_mbuf(struct socket *so, struct label *solabel,
1969 struct mbuf *m, struct label *mlabel)
1971 struct mac_biba *source, *dest;
1973 source = SLOT(solabel);
1974 dest = SLOT(mlabel);
1976 biba_copy_effective(source, dest);
1980 biba_socket_newconn(struct socket *oldso, struct label *oldsolabel,
1981 struct socket *newso, struct label *newsolabel)
1983 struct mac_biba *source, *dest;
1985 source = SLOT(oldsolabel);
1986 dest = SLOT(newsolabel);
1988 biba_copy_effective(source, dest);
1992 biba_socket_relabel(struct ucred *cred, struct socket *so,
1993 struct label *solabel, struct label *newlabel)
1995 struct mac_biba *source, *dest;
1997 source = SLOT(newlabel);
1998 dest = SLOT(solabel);
2000 biba_copy(source, dest);
2004 biba_socketpeer_set_from_mbuf(struct mbuf *m, struct label *mlabel,
2005 struct socket *so, struct label *sopeerlabel)
2007 struct mac_biba *source, *dest;
2009 source = SLOT(mlabel);
2010 dest = SLOT(sopeerlabel);
2012 biba_copy_effective(source, dest);
2016 biba_socketpeer_set_from_socket(struct socket *oldso,
2017 struct label *oldsolabel, struct socket *newso,
2018 struct label *newsopeerlabel)
2020 struct mac_biba *source, *dest;
2022 source = SLOT(oldsolabel);
2023 dest = SLOT(newsopeerlabel);
2025 biba_copy_effective(source, dest);
2029 biba_syncache_create(struct label *label, struct inpcb *inp)
2031 struct mac_biba *source, *dest;
2033 source = SLOT(inp->inp_label);
2035 biba_copy_effective(source, dest);
2039 biba_syncache_create_mbuf(struct label *sc_label, struct mbuf *m,
2040 struct label *mlabel)
2042 struct mac_biba *source, *dest;
2044 source = SLOT(sc_label);
2045 dest = SLOT(mlabel);
2046 biba_copy_effective(source, dest);
2050 biba_system_check_acct(struct ucred *cred, struct vnode *vp,
2051 struct label *vplabel)
2053 struct mac_biba *subj, *obj;
2059 subj = SLOT(cred->cr_label);
2061 error = biba_subject_privileged(subj);
2065 if (vplabel == NULL)
2068 obj = SLOT(vplabel);
2069 if (!biba_high_effective(obj))
2076 biba_system_check_auditctl(struct ucred *cred, struct vnode *vp,
2077 struct label *vplabel)
2079 struct mac_biba *subj, *obj;
2085 subj = SLOT(cred->cr_label);
2087 error = biba_subject_privileged(subj);
2091 if (vplabel == NULL)
2094 obj = SLOT(vplabel);
2095 if (!biba_high_effective(obj))
2102 biba_system_check_auditon(struct ucred *cred, int cmd)
2104 struct mac_biba *subj;
2110 subj = SLOT(cred->cr_label);
2112 error = biba_subject_privileged(subj);
2120 biba_system_check_swapoff(struct ucred *cred, struct vnode *vp,
2121 struct label *label)
2123 struct mac_biba *subj;
2129 subj = SLOT(cred->cr_label);
2131 error = biba_subject_privileged(subj);
2139 biba_system_check_swapon(struct ucred *cred, struct vnode *vp,
2140 struct label *vplabel)
2142 struct mac_biba *subj, *obj;
2148 subj = SLOT(cred->cr_label);
2149 obj = SLOT(vplabel);
2151 error = biba_subject_privileged(subj);
2155 if (!biba_high_effective(obj))
2162 biba_system_check_sysctl(struct ucred *cred, struct sysctl_oid *oidp,
2163 void *arg1, int arg2, struct sysctl_req *req)
2165 struct mac_biba *subj;
2171 subj = SLOT(cred->cr_label);
2174 * Treat sysctl variables without CTLFLAG_ANYBODY flag as biba/high,
2175 * but also require privilege to change them.
2177 if (req->newptr != NULL && (oidp->oid_kind & CTLFLAG_ANYBODY) == 0) {
2178 if (!biba_subject_dominate_high(subj))
2181 error = biba_subject_privileged(subj);
2190 biba_sysvmsg_cleanup(struct label *msglabel)
2193 bzero(SLOT(msglabel), sizeof(struct mac_biba));
2197 biba_sysvmsg_create(struct ucred *cred, struct msqid_kernel *msqkptr,
2198 struct label *msqlabel, struct msg *msgptr, struct label *msglabel)
2200 struct mac_biba *source, *dest;
2202 /* Ignore the msgq label */
2203 source = SLOT(cred->cr_label);
2204 dest = SLOT(msglabel);
2206 biba_copy_effective(source, dest);
2210 biba_sysvmsq_check_msgrcv(struct ucred *cred, struct msg *msgptr,
2211 struct label *msglabel)
2213 struct mac_biba *subj, *obj;
2218 subj = SLOT(cred->cr_label);
2219 obj = SLOT(msglabel);
2221 if (!biba_dominate_effective(obj, subj))
2228 biba_sysvmsq_check_msgrmid(struct ucred *cred, struct msg *msgptr,
2229 struct label *msglabel)
2231 struct mac_biba *subj, *obj;
2236 subj = SLOT(cred->cr_label);
2237 obj = SLOT(msglabel);
2239 if (!biba_dominate_effective(subj, obj))
2246 biba_sysvmsq_check_msqget(struct ucred *cred, struct msqid_kernel *msqkptr,
2247 struct label *msqklabel)
2249 struct mac_biba *subj, *obj;
2254 subj = SLOT(cred->cr_label);
2255 obj = SLOT(msqklabel);
2257 if (!biba_dominate_effective(obj, subj))
2264 biba_sysvmsq_check_msqsnd(struct ucred *cred, struct msqid_kernel *msqkptr,
2265 struct label *msqklabel)
2267 struct mac_biba *subj, *obj;
2272 subj = SLOT(cred->cr_label);
2273 obj = SLOT(msqklabel);
2275 if (!biba_dominate_effective(subj, obj))
2282 biba_sysvmsq_check_msqrcv(struct ucred *cred, struct msqid_kernel *msqkptr,
2283 struct label *msqklabel)
2285 struct mac_biba *subj, *obj;
2290 subj = SLOT(cred->cr_label);
2291 obj = SLOT(msqklabel);
2293 if (!biba_dominate_effective(obj, subj))
2300 biba_sysvmsq_check_msqctl(struct ucred *cred, struct msqid_kernel *msqkptr,
2301 struct label *msqklabel, int cmd)
2303 struct mac_biba *subj, *obj;
2308 subj = SLOT(cred->cr_label);
2309 obj = SLOT(msqklabel);
2314 if (!biba_dominate_effective(subj, obj))
2319 if (!biba_dominate_effective(obj, subj))
2331 biba_sysvmsq_cleanup(struct label *msqlabel)
2334 bzero(SLOT(msqlabel), sizeof(struct mac_biba));
2338 biba_sysvmsq_create(struct ucred *cred, struct msqid_kernel *msqkptr,
2339 struct label *msqlabel)
2341 struct mac_biba *source, *dest;
2343 source = SLOT(cred->cr_label);
2344 dest = SLOT(msqlabel);
2346 biba_copy_effective(source, dest);
2350 biba_sysvsem_check_semctl(struct ucred *cred, struct semid_kernel *semakptr,
2351 struct label *semaklabel, int cmd)
2353 struct mac_biba *subj, *obj;
2358 subj = SLOT(cred->cr_label);
2359 obj = SLOT(semaklabel);
2366 if (!biba_dominate_effective(subj, obj))
2376 if (!biba_dominate_effective(obj, subj))
2388 biba_sysvsem_check_semget(struct ucred *cred, struct semid_kernel *semakptr,
2389 struct label *semaklabel)
2391 struct mac_biba *subj, *obj;
2396 subj = SLOT(cred->cr_label);
2397 obj = SLOT(semaklabel);
2399 if (!biba_dominate_effective(obj, subj))
2406 biba_sysvsem_check_semop(struct ucred *cred, struct semid_kernel *semakptr,
2407 struct label *semaklabel, size_t accesstype)
2409 struct mac_biba *subj, *obj;
2414 subj = SLOT(cred->cr_label);
2415 obj = SLOT(semaklabel);
2417 if (accesstype & SEM_R)
2418 if (!biba_dominate_effective(obj, subj))
2421 if (accesstype & SEM_A)
2422 if (!biba_dominate_effective(subj, obj))
2429 biba_sysvsem_cleanup(struct label *semalabel)
2432 bzero(SLOT(semalabel), sizeof(struct mac_biba));
2436 biba_sysvsem_create(struct ucred *cred, struct semid_kernel *semakptr,
2437 struct label *semalabel)
2439 struct mac_biba *source, *dest;
2441 source = SLOT(cred->cr_label);
2442 dest = SLOT(semalabel);
2444 biba_copy_effective(source, dest);
2448 biba_sysvshm_check_shmat(struct ucred *cred, struct shmid_kernel *shmsegptr,
2449 struct label *shmseglabel, int shmflg)
2451 struct mac_biba *subj, *obj;
2456 subj = SLOT(cred->cr_label);
2457 obj = SLOT(shmseglabel);
2459 if (!biba_dominate_effective(obj, subj))
2461 if ((shmflg & SHM_RDONLY) == 0) {
2462 if (!biba_dominate_effective(subj, obj))
2470 biba_sysvshm_check_shmctl(struct ucred *cred, struct shmid_kernel *shmsegptr,
2471 struct label *shmseglabel, int cmd)
2473 struct mac_biba *subj, *obj;
2478 subj = SLOT(cred->cr_label);
2479 obj = SLOT(shmseglabel);
2484 if (!biba_dominate_effective(subj, obj))
2490 if (!biba_dominate_effective(obj, subj))
2502 biba_sysvshm_check_shmget(struct ucred *cred, struct shmid_kernel *shmsegptr,
2503 struct label *shmseglabel, int shmflg)
2505 struct mac_biba *subj, *obj;
2510 subj = SLOT(cred->cr_label);
2511 obj = SLOT(shmseglabel);
2513 if (!biba_dominate_effective(obj, subj))
2520 biba_sysvshm_cleanup(struct label *shmlabel)
2523 bzero(SLOT(shmlabel), sizeof(struct mac_biba));
2527 biba_sysvshm_create(struct ucred *cred, struct shmid_kernel *shmsegptr,
2528 struct label *shmlabel)
2530 struct mac_biba *source, *dest;
2532 source = SLOT(cred->cr_label);
2533 dest = SLOT(shmlabel);
2535 biba_copy_effective(source, dest);
2539 biba_vnode_associate_extattr(struct mount *mp, struct label *mplabel,
2540 struct vnode *vp, struct label *vplabel)
2542 struct mac_biba mb_temp, *source, *dest;
2545 source = SLOT(mplabel);
2546 dest = SLOT(vplabel);
2548 buflen = sizeof(mb_temp);
2549 bzero(&mb_temp, buflen);
2551 error = vn_extattr_get(vp, IO_NODELOCKED, MAC_BIBA_EXTATTR_NAMESPACE,
2552 MAC_BIBA_EXTATTR_NAME, &buflen, (char *) &mb_temp, curthread);
2553 if (error == ENOATTR || error == EOPNOTSUPP) {
2554 /* Fall back to the mntlabel. */
2555 biba_copy_effective(source, dest);
2560 if (buflen != sizeof(mb_temp)) {
2561 printf("biba_vnode_associate_extattr: bad size %d\n",
2565 if (biba_valid(&mb_temp) != 0) {
2566 printf("biba_vnode_associate_extattr: invalid\n");
2569 if ((mb_temp.mb_flags & MAC_BIBA_FLAGS_BOTH) !=
2570 MAC_BIBA_FLAG_EFFECTIVE) {
2571 printf("biba_vnode_associate_extattr: not effective\n");
2575 biba_copy_effective(&mb_temp, dest);
2580 biba_vnode_associate_singlelabel(struct mount *mp, struct label *mplabel,
2581 struct vnode *vp, struct label *vplabel)
2583 struct mac_biba *source, *dest;
2585 source = SLOT(mplabel);
2586 dest = SLOT(vplabel);
2588 biba_copy_effective(source, dest);
2592 biba_vnode_check_chdir(struct ucred *cred, struct vnode *dvp,
2593 struct label *dvplabel)
2595 struct mac_biba *subj, *obj;
2600 subj = SLOT(cred->cr_label);
2601 obj = SLOT(dvplabel);
2603 if (!biba_dominate_effective(obj, subj))
2610 biba_vnode_check_chroot(struct ucred *cred, struct vnode *dvp,
2611 struct label *dvplabel)
2613 struct mac_biba *subj, *obj;
2618 subj = SLOT(cred->cr_label);
2619 obj = SLOT(dvplabel);
2621 if (!biba_dominate_effective(obj, subj))
2628 biba_vnode_check_create(struct ucred *cred, struct vnode *dvp,
2629 struct label *dvplabel, struct componentname *cnp, struct vattr *vap)
2631 struct mac_biba *subj, *obj;
2636 subj = SLOT(cred->cr_label);
2637 obj = SLOT(dvplabel);
2639 if (!biba_dominate_effective(subj, obj))
2646 biba_vnode_check_deleteacl(struct ucred *cred, struct vnode *vp,
2647 struct label *vplabel, acl_type_t type)
2649 struct mac_biba *subj, *obj;
2654 subj = SLOT(cred->cr_label);
2655 obj = SLOT(vplabel);
2657 if (!biba_dominate_effective(subj, obj))
2664 biba_vnode_check_deleteextattr(struct ucred *cred, struct vnode *vp,
2665 struct label *vplabel, int attrnamespace, const char *name)
2667 struct mac_biba *subj, *obj;
2672 subj = SLOT(cred->cr_label);
2673 obj = SLOT(vplabel);
2675 if (!biba_dominate_effective(subj, obj))
2682 biba_vnode_check_exec(struct ucred *cred, struct vnode *vp,
2683 struct label *vplabel, struct image_params *imgp,
2684 struct label *execlabel)
2686 struct mac_biba *subj, *obj, *exec;
2689 if (execlabel != NULL) {
2691 * We currently don't permit labels to be changed at
2692 * exec-time as part of Biba, so disallow non-NULL Biba label
2693 * elements in the execlabel.
2695 exec = SLOT(execlabel);
2696 error = biba_atmostflags(exec, 0);
2704 subj = SLOT(cred->cr_label);
2705 obj = SLOT(vplabel);
2707 if (!biba_dominate_effective(obj, subj))
2714 biba_vnode_check_getacl(struct ucred *cred, struct vnode *vp,
2715 struct label *vplabel, acl_type_t type)
2717 struct mac_biba *subj, *obj;
2722 subj = SLOT(cred->cr_label);
2723 obj = SLOT(vplabel);
2725 if (!biba_dominate_effective(obj, subj))
2732 biba_vnode_check_getextattr(struct ucred *cred, struct vnode *vp,
2733 struct label *vplabel, int attrnamespace, const char *name,
2736 struct mac_biba *subj, *obj;
2741 subj = SLOT(cred->cr_label);
2742 obj = SLOT(vplabel);
2744 if (!biba_dominate_effective(obj, subj))
2751 biba_vnode_check_link(struct ucred *cred, struct vnode *dvp,
2752 struct label *dvplabel, struct vnode *vp, struct label *vplabel,
2753 struct componentname *cnp)
2755 struct mac_biba *subj, *obj;
2760 subj = SLOT(cred->cr_label);
2761 obj = SLOT(dvplabel);
2763 if (!biba_dominate_effective(subj, obj))
2766 obj = SLOT(vplabel);
2768 if (!biba_dominate_effective(subj, obj))
2775 biba_vnode_check_listextattr(struct ucred *cred, struct vnode *vp,
2776 struct label *vplabel, int attrnamespace)
2778 struct mac_biba *subj, *obj;
2783 subj = SLOT(cred->cr_label);
2784 obj = SLOT(vplabel);
2786 if (!biba_dominate_effective(obj, subj))
2793 biba_vnode_check_lookup(struct ucred *cred, struct vnode *dvp,
2794 struct label *dvplabel, struct componentname *cnp)
2796 struct mac_biba *subj, *obj;
2801 subj = SLOT(cred->cr_label);
2802 obj = SLOT(dvplabel);
2804 if (!biba_dominate_effective(obj, subj))
2811 biba_vnode_check_mmap(struct ucred *cred, struct vnode *vp,
2812 struct label *vplabel, int prot, int flags)
2814 struct mac_biba *subj, *obj;
2817 * Rely on the use of open()-time protections to handle
2818 * non-revocation cases.
2820 if (!biba_enabled || !revocation_enabled)
2823 subj = SLOT(cred->cr_label);
2824 obj = SLOT(vplabel);
2826 if (prot & (VM_PROT_READ | VM_PROT_EXECUTE)) {
2827 if (!biba_dominate_effective(obj, subj))
2830 if (((prot & VM_PROT_WRITE) != 0) && ((flags & MAP_SHARED) != 0)) {
2831 if (!biba_dominate_effective(subj, obj))
2839 biba_vnode_check_open(struct ucred *cred, struct vnode *vp,
2840 struct label *vplabel, int acc_mode)
2842 struct mac_biba *subj, *obj;
2847 subj = SLOT(cred->cr_label);
2848 obj = SLOT(vplabel);
2850 /* XXX privilege override for admin? */
2851 if (acc_mode & (VREAD | VEXEC | VSTAT)) {
2852 if (!biba_dominate_effective(obj, subj))
2855 if (acc_mode & (VWRITE | VAPPEND | VADMIN)) {
2856 if (!biba_dominate_effective(subj, obj))
2864 biba_vnode_check_poll(struct ucred *active_cred, struct ucred *file_cred,
2865 struct vnode *vp, struct label *vplabel)
2867 struct mac_biba *subj, *obj;
2869 if (!biba_enabled || !revocation_enabled)
2872 subj = SLOT(active_cred->cr_label);
2873 obj = SLOT(vplabel);
2875 if (!biba_dominate_effective(obj, subj))
2882 biba_vnode_check_read(struct ucred *active_cred, struct ucred *file_cred,
2883 struct vnode *vp, struct label *vplabel)
2885 struct mac_biba *subj, *obj;
2887 if (!biba_enabled || !revocation_enabled)
2890 subj = SLOT(active_cred->cr_label);
2891 obj = SLOT(vplabel);
2893 if (!biba_dominate_effective(obj, subj))
2900 biba_vnode_check_readdir(struct ucred *cred, struct vnode *dvp,
2901 struct label *dvplabel)
2903 struct mac_biba *subj, *obj;
2908 subj = SLOT(cred->cr_label);
2909 obj = SLOT(dvplabel);
2911 if (!biba_dominate_effective(obj, subj))
2918 biba_vnode_check_readlink(struct ucred *cred, struct vnode *vp,
2919 struct label *vplabel)
2921 struct mac_biba *subj, *obj;
2926 subj = SLOT(cred->cr_label);
2927 obj = SLOT(vplabel);
2929 if (!biba_dominate_effective(obj, subj))
2936 biba_vnode_check_relabel(struct ucred *cred, struct vnode *vp,
2937 struct label *vplabel, struct label *newlabel)
2939 struct mac_biba *old, *new, *subj;
2942 old = SLOT(vplabel);
2943 new = SLOT(newlabel);
2944 subj = SLOT(cred->cr_label);
2947 * If there is a Biba label update for the vnode, it must be a
2950 error = biba_atmostflags(new, MAC_BIBA_FLAG_EFFECTIVE);
2955 * To perform a relabel of the vnode (Biba label or not), Biba must
2956 * authorize the relabel.
2958 if (!biba_effective_in_range(old, subj))
2962 * If the Biba label is to be changed, authorize as appropriate.
2964 if (new->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) {
2966 * To change the Biba label on a vnode, the new vnode label
2967 * must be in the subject range.
2969 if (!biba_effective_in_range(new, subj))
2973 * To change the Biba label on the vnode to be EQUAL, the
2974 * subject must have appropriate privilege.
2976 if (biba_contains_equal(new)) {
2977 error = biba_subject_privileged(subj);
2987 biba_vnode_check_rename_from(struct ucred *cred, struct vnode *dvp,
2988 struct label *dvplabel, struct vnode *vp, struct label *vplabel,
2989 struct componentname *cnp)
2991 struct mac_biba *subj, *obj;
2996 subj = SLOT(cred->cr_label);
2997 obj = SLOT(dvplabel);
2999 if (!biba_dominate_effective(subj, obj))
3002 obj = SLOT(vplabel);
3004 if (!biba_dominate_effective(subj, obj))
3011 biba_vnode_check_rename_to(struct ucred *cred, struct vnode *dvp,
3012 struct label *dvplabel, struct vnode *vp, struct label *vplabel,
3013 int samedir, struct componentname *cnp)
3015 struct mac_biba *subj, *obj;
3020 subj = SLOT(cred->cr_label);
3021 obj = SLOT(dvplabel);
3023 if (!biba_dominate_effective(subj, obj))
3027 obj = SLOT(vplabel);
3029 if (!biba_dominate_effective(subj, obj))
3037 biba_vnode_check_revoke(struct ucred *cred, struct vnode *vp,
3038 struct label *vplabel)
3040 struct mac_biba *subj, *obj;
3045 subj = SLOT(cred->cr_label);
3046 obj = SLOT(vplabel);
3048 if (!biba_dominate_effective(subj, obj))
3055 biba_vnode_check_setacl(struct ucred *cred, struct vnode *vp,
3056 struct label *vplabel, acl_type_t type, struct acl *acl)
3058 struct mac_biba *subj, *obj;
3063 subj = SLOT(cred->cr_label);
3064 obj = SLOT(vplabel);
3066 if (!biba_dominate_effective(subj, obj))
3073 biba_vnode_check_setextattr(struct ucred *cred, struct vnode *vp,
3074 struct label *vplabel, int attrnamespace, const char *name,
3077 struct mac_biba *subj, *obj;
3082 subj = SLOT(cred->cr_label);
3083 obj = SLOT(vplabel);
3085 if (!biba_dominate_effective(subj, obj))
3088 /* XXX: protect the MAC EA in a special way? */
3094 biba_vnode_check_setflags(struct ucred *cred, struct vnode *vp,
3095 struct label *vplabel, u_long flags)
3097 struct mac_biba *subj, *obj;
3102 subj = SLOT(cred->cr_label);
3103 obj = SLOT(vplabel);
3105 if (!biba_dominate_effective(subj, obj))
3112 biba_vnode_check_setmode(struct ucred *cred, struct vnode *vp,
3113 struct label *vplabel, mode_t mode)
3115 struct mac_biba *subj, *obj;
3120 subj = SLOT(cred->cr_label);
3121 obj = SLOT(vplabel);
3123 if (!biba_dominate_effective(subj, obj))
3130 biba_vnode_check_setowner(struct ucred *cred, struct vnode *vp,
3131 struct label *vplabel, uid_t uid, gid_t gid)
3133 struct mac_biba *subj, *obj;
3138 subj = SLOT(cred->cr_label);
3139 obj = SLOT(vplabel);
3141 if (!biba_dominate_effective(subj, obj))
3148 biba_vnode_check_setutimes(struct ucred *cred, struct vnode *vp,
3149 struct label *vplabel, struct timespec atime, struct timespec mtime)
3151 struct mac_biba *subj, *obj;
3156 subj = SLOT(cred->cr_label);
3157 obj = SLOT(vplabel);
3159 if (!biba_dominate_effective(subj, obj))
3166 biba_vnode_check_stat(struct ucred *active_cred, struct ucred *file_cred,
3167 struct vnode *vp, struct label *vplabel)
3169 struct mac_biba *subj, *obj;
3174 subj = SLOT(active_cred->cr_label);
3175 obj = SLOT(vplabel);
3177 if (!biba_dominate_effective(obj, subj))
3184 biba_vnode_check_unlink(struct ucred *cred, struct vnode *dvp,
3185 struct label *dvplabel, struct vnode *vp, struct label *vplabel,
3186 struct componentname *cnp)
3188 struct mac_biba *subj, *obj;
3193 subj = SLOT(cred->cr_label);
3194 obj = SLOT(dvplabel);
3196 if (!biba_dominate_effective(subj, obj))
3199 obj = SLOT(vplabel);
3201 if (!biba_dominate_effective(subj, obj))
3208 biba_vnode_check_write(struct ucred *active_cred,
3209 struct ucred *file_cred, struct vnode *vp, struct label *vplabel)
3211 struct mac_biba *subj, *obj;
3213 if (!biba_enabled || !revocation_enabled)
3216 subj = SLOT(active_cred->cr_label);
3217 obj = SLOT(vplabel);
3219 if (!biba_dominate_effective(subj, obj))
3226 biba_vnode_create_extattr(struct ucred *cred, struct mount *mp,
3227 struct label *mplabel, struct vnode *dvp, struct label *dvplabel,
3228 struct vnode *vp, struct label *vplabel, struct componentname *cnp)
3230 struct mac_biba *source, *dest, mb_temp;
3234 buflen = sizeof(mb_temp);
3235 bzero(&mb_temp, buflen);
3237 source = SLOT(cred->cr_label);
3238 dest = SLOT(vplabel);
3239 biba_copy_effective(source, &mb_temp);
3241 error = vn_extattr_set(vp, IO_NODELOCKED, MAC_BIBA_EXTATTR_NAMESPACE,
3242 MAC_BIBA_EXTATTR_NAME, buflen, (char *) &mb_temp, curthread);
3244 biba_copy_effective(source, dest);
3249 biba_vnode_relabel(struct ucred *cred, struct vnode *vp,
3250 struct label *vplabel, struct label *newlabel)
3252 struct mac_biba *source, *dest;
3254 source = SLOT(newlabel);
3255 dest = SLOT(vplabel);
3257 biba_copy(source, dest);
3261 biba_vnode_setlabel_extattr(struct ucred *cred, struct vnode *vp,
3262 struct label *vplabel, struct label *intlabel)
3264 struct mac_biba *source, mb_temp;
3268 buflen = sizeof(mb_temp);
3269 bzero(&mb_temp, buflen);
3271 source = SLOT(intlabel);
3272 if ((source->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) == 0)
3275 biba_copy_effective(source, &mb_temp);
3277 error = vn_extattr_set(vp, IO_NODELOCKED, MAC_BIBA_EXTATTR_NAMESPACE,
3278 MAC_BIBA_EXTATTR_NAME, buflen, (char *) &mb_temp, curthread);
3282 static struct mac_policy_ops mac_biba_ops =
3284 .mpo_init = biba_init,
3286 .mpo_bpfdesc_check_receive = biba_bpfdesc_check_receive,
3287 .mpo_bpfdesc_create = biba_bpfdesc_create,
3288 .mpo_bpfdesc_create_mbuf = biba_bpfdesc_create_mbuf,
3289 .mpo_bpfdesc_destroy_label = biba_destroy_label,
3290 .mpo_bpfdesc_init_label = biba_init_label,
3292 .mpo_cred_check_relabel = biba_cred_check_relabel,
3293 .mpo_cred_check_visible = biba_cred_check_visible,
3294 .mpo_cred_copy_label = biba_copy_label,
3295 .mpo_cred_destroy_label = biba_destroy_label,
3296 .mpo_cred_externalize_label = biba_externalize_label,
3297 .mpo_cred_init_label = biba_init_label,
3298 .mpo_cred_internalize_label = biba_internalize_label,
3299 .mpo_cred_relabel = biba_cred_relabel,
3301 .mpo_devfs_create_device = biba_devfs_create_device,
3302 .mpo_devfs_create_directory = biba_devfs_create_directory,
3303 .mpo_devfs_create_symlink = biba_devfs_create_symlink,
3304 .mpo_devfs_destroy_label = biba_destroy_label,
3305 .mpo_devfs_init_label = biba_init_label,
3306 .mpo_devfs_update = biba_devfs_update,
3307 .mpo_devfs_vnode_associate = biba_devfs_vnode_associate,
3309 .mpo_ifnet_check_relabel = biba_ifnet_check_relabel,
3310 .mpo_ifnet_check_transmit = biba_ifnet_check_transmit,
3311 .mpo_ifnet_copy_label = biba_copy_label,
3312 .mpo_ifnet_create = biba_ifnet_create,
3313 .mpo_ifnet_create_mbuf = biba_ifnet_create_mbuf,
3314 .mpo_ifnet_destroy_label = biba_destroy_label,
3315 .mpo_ifnet_externalize_label = biba_externalize_label,
3316 .mpo_ifnet_init_label = biba_init_label,
3317 .mpo_ifnet_internalize_label = biba_internalize_label,
3318 .mpo_ifnet_relabel = biba_ifnet_relabel,
3320 .mpo_inpcb_check_deliver = biba_inpcb_check_deliver,
3321 .mpo_inpcb_check_visible = biba_inpcb_check_visible,
3322 .mpo_inpcb_create = biba_inpcb_create,
3323 .mpo_inpcb_create_mbuf = biba_inpcb_create_mbuf,
3324 .mpo_inpcb_destroy_label = biba_destroy_label,
3325 .mpo_inpcb_init_label = biba_init_label_waitcheck,
3326 .mpo_inpcb_sosetlabel = biba_inpcb_sosetlabel,
3328 .mpo_ipq_create = biba_ipq_create,
3329 .mpo_ipq_destroy_label = biba_destroy_label,
3330 .mpo_ipq_init_label = biba_init_label_waitcheck,
3331 .mpo_ipq_match = biba_ipq_match,
3332 .mpo_ipq_reassemble = biba_ipq_reassemble,
3333 .mpo_ipq_update = biba_ipq_update,
3335 .mpo_kld_check_load = biba_kld_check_load,
3337 .mpo_mbuf_copy_label = biba_copy_label,
3338 .mpo_mbuf_destroy_label = biba_destroy_label,
3339 .mpo_mbuf_init_label = biba_init_label_waitcheck,
3341 .mpo_mount_check_stat = biba_mount_check_stat,
3342 .mpo_mount_create = biba_mount_create,
3343 .mpo_mount_destroy_label = biba_destroy_label,
3344 .mpo_mount_init_label = biba_init_label,
3346 .mpo_netatalk_aarp_send = biba_netatalk_aarp_send,
3348 .mpo_netinet_arp_send = biba_netinet_arp_send,
3349 .mpo_netinet_firewall_reply = biba_netinet_firewall_reply,
3350 .mpo_netinet_firewall_send = biba_netinet_firewall_send,
3351 .mpo_netinet_fragment = biba_netinet_fragment,
3352 .mpo_netinet_icmp_reply = biba_netinet_icmp_reply,
3353 .mpo_netinet_igmp_send = biba_netinet_igmp_send,
3355 .mpo_netinet6_nd6_send = biba_netinet6_nd6_send,
3357 .mpo_pipe_check_ioctl = biba_pipe_check_ioctl,
3358 .mpo_pipe_check_poll = biba_pipe_check_poll,
3359 .mpo_pipe_check_read = biba_pipe_check_read,
3360 .mpo_pipe_check_relabel = biba_pipe_check_relabel,
3361 .mpo_pipe_check_stat = biba_pipe_check_stat,
3362 .mpo_pipe_check_write = biba_pipe_check_write,
3363 .mpo_pipe_copy_label = biba_copy_label,
3364 .mpo_pipe_create = biba_pipe_create,
3365 .mpo_pipe_destroy_label = biba_destroy_label,
3366 .mpo_pipe_externalize_label = biba_externalize_label,
3367 .mpo_pipe_init_label = biba_init_label,
3368 .mpo_pipe_internalize_label = biba_internalize_label,
3369 .mpo_pipe_relabel = biba_pipe_relabel,
3371 .mpo_posixsem_check_getvalue = biba_posixsem_check_rdonly,
3372 .mpo_posixsem_check_open = biba_posixsem_check_openunlink,
3373 .mpo_posixsem_check_post = biba_posixsem_check_write,
3374 .mpo_posixsem_check_stat = biba_posixsem_check_rdonly,
3375 .mpo_posixsem_check_unlink = biba_posixsem_check_openunlink,
3376 .mpo_posixsem_check_wait = biba_posixsem_check_write,
3377 .mpo_posixsem_create = biba_posixsem_create,
3378 .mpo_posixsem_destroy_label = biba_destroy_label,
3379 .mpo_posixsem_init_label = biba_init_label,
3381 .mpo_priv_check = biba_priv_check,
3383 .mpo_proc_associate_nfsd = biba_proc_associate_nfsd,
3384 .mpo_proc_check_debug = biba_proc_check_debug,
3385 .mpo_proc_check_sched = biba_proc_check_sched,
3386 .mpo_proc_check_signal = biba_proc_check_signal,
3387 .mpo_proc_create_init = biba_proc_create_init,
3388 .mpo_proc_create_swapper = biba_proc_create_swapper,
3390 .mpo_socket_check_deliver = biba_socket_check_deliver,
3391 .mpo_socket_check_relabel = biba_socket_check_relabel,
3392 .mpo_socket_check_visible = biba_socket_check_visible,
3393 .mpo_socket_copy_label = biba_copy_label,
3394 .mpo_socket_create = biba_socket_create,
3395 .mpo_socket_create_mbuf = biba_socket_create_mbuf,
3396 .mpo_socket_destroy_label = biba_destroy_label,
3397 .mpo_socket_externalize_label = biba_externalize_label,
3398 .mpo_socket_init_label = biba_init_label_waitcheck,
3399 .mpo_socket_internalize_label = biba_internalize_label,
3400 .mpo_socket_newconn = biba_socket_newconn,
3401 .mpo_socket_relabel = biba_socket_relabel,
3403 .mpo_socketpeer_destroy_label = biba_destroy_label,
3404 .mpo_socketpeer_externalize_label = biba_externalize_label,
3405 .mpo_socketpeer_init_label = biba_init_label_waitcheck,
3406 .mpo_socketpeer_set_from_mbuf = biba_socketpeer_set_from_mbuf,
3407 .mpo_socketpeer_set_from_socket = biba_socketpeer_set_from_socket,
3409 .mpo_syncache_create = biba_syncache_create,
3410 .mpo_syncache_create_mbuf = biba_syncache_create_mbuf,
3411 .mpo_syncache_destroy_label = biba_destroy_label,
3412 .mpo_syncache_init_label = biba_init_label_waitcheck,
3414 .mpo_system_check_acct = biba_system_check_acct,
3415 .mpo_system_check_auditctl = biba_system_check_auditctl,
3416 .mpo_system_check_auditon = biba_system_check_auditon,
3417 .mpo_system_check_swapoff = biba_system_check_swapoff,
3418 .mpo_system_check_swapon = biba_system_check_swapon,
3419 .mpo_system_check_sysctl = biba_system_check_sysctl,
3421 .mpo_sysvmsg_cleanup = biba_sysvmsg_cleanup,
3422 .mpo_sysvmsg_create = biba_sysvmsg_create,
3423 .mpo_sysvmsg_destroy_label = biba_destroy_label,
3424 .mpo_sysvmsg_init_label = biba_init_label,
3426 .mpo_sysvmsq_check_msgrcv = biba_sysvmsq_check_msgrcv,
3427 .mpo_sysvmsq_check_msgrmid = biba_sysvmsq_check_msgrmid,
3428 .mpo_sysvmsq_check_msqget = biba_sysvmsq_check_msqget,
3429 .mpo_sysvmsq_check_msqsnd = biba_sysvmsq_check_msqsnd,
3430 .mpo_sysvmsq_check_msqrcv = biba_sysvmsq_check_msqrcv,
3431 .mpo_sysvmsq_check_msqctl = biba_sysvmsq_check_msqctl,
3432 .mpo_sysvmsq_cleanup = biba_sysvmsq_cleanup,
3433 .mpo_sysvmsq_create = biba_sysvmsq_create,
3434 .mpo_sysvmsq_destroy_label = biba_destroy_label,
3435 .mpo_sysvmsq_init_label = biba_init_label,
3437 .mpo_sysvsem_check_semctl = biba_sysvsem_check_semctl,
3438 .mpo_sysvsem_check_semget = biba_sysvsem_check_semget,
3439 .mpo_sysvsem_check_semop = biba_sysvsem_check_semop,
3440 .mpo_sysvsem_cleanup = biba_sysvsem_cleanup,
3441 .mpo_sysvsem_create = biba_sysvsem_create,
3442 .mpo_sysvsem_destroy_label = biba_destroy_label,
3443 .mpo_sysvsem_init_label = biba_init_label,
3445 .mpo_sysvshm_check_shmat = biba_sysvshm_check_shmat,
3446 .mpo_sysvshm_check_shmctl = biba_sysvshm_check_shmctl,
3447 .mpo_sysvshm_check_shmget = biba_sysvshm_check_shmget,
3448 .mpo_sysvshm_cleanup = biba_sysvshm_cleanup,
3449 .mpo_sysvshm_create = biba_sysvshm_create,
3450 .mpo_sysvshm_destroy_label = biba_destroy_label,
3451 .mpo_sysvshm_init_label = biba_init_label,
3453 .mpo_vnode_associate_extattr = biba_vnode_associate_extattr,
3454 .mpo_vnode_associate_singlelabel = biba_vnode_associate_singlelabel,
3455 .mpo_vnode_check_access = biba_vnode_check_open,
3456 .mpo_vnode_check_chdir = biba_vnode_check_chdir,
3457 .mpo_vnode_check_chroot = biba_vnode_check_chroot,
3458 .mpo_vnode_check_create = biba_vnode_check_create,
3459 .mpo_vnode_check_deleteacl = biba_vnode_check_deleteacl,
3460 .mpo_vnode_check_deleteextattr = biba_vnode_check_deleteextattr,
3461 .mpo_vnode_check_exec = biba_vnode_check_exec,
3462 .mpo_vnode_check_getacl = biba_vnode_check_getacl,
3463 .mpo_vnode_check_getextattr = biba_vnode_check_getextattr,
3464 .mpo_vnode_check_link = biba_vnode_check_link,
3465 .mpo_vnode_check_listextattr = biba_vnode_check_listextattr,
3466 .mpo_vnode_check_lookup = biba_vnode_check_lookup,
3467 .mpo_vnode_check_mmap = biba_vnode_check_mmap,
3468 .mpo_vnode_check_open = biba_vnode_check_open,
3469 .mpo_vnode_check_poll = biba_vnode_check_poll,
3470 .mpo_vnode_check_read = biba_vnode_check_read,
3471 .mpo_vnode_check_readdir = biba_vnode_check_readdir,
3472 .mpo_vnode_check_readlink = biba_vnode_check_readlink,
3473 .mpo_vnode_check_relabel = biba_vnode_check_relabel,
3474 .mpo_vnode_check_rename_from = biba_vnode_check_rename_from,
3475 .mpo_vnode_check_rename_to = biba_vnode_check_rename_to,
3476 .mpo_vnode_check_revoke = biba_vnode_check_revoke,
3477 .mpo_vnode_check_setacl = biba_vnode_check_setacl,
3478 .mpo_vnode_check_setextattr = biba_vnode_check_setextattr,
3479 .mpo_vnode_check_setflags = biba_vnode_check_setflags,
3480 .mpo_vnode_check_setmode = biba_vnode_check_setmode,
3481 .mpo_vnode_check_setowner = biba_vnode_check_setowner,
3482 .mpo_vnode_check_setutimes = biba_vnode_check_setutimes,
3483 .mpo_vnode_check_stat = biba_vnode_check_stat,
3484 .mpo_vnode_check_unlink = biba_vnode_check_unlink,
3485 .mpo_vnode_check_write = biba_vnode_check_write,
3486 .mpo_vnode_create_extattr = biba_vnode_create_extattr,
3487 .mpo_vnode_copy_label = biba_copy_label,
3488 .mpo_vnode_destroy_label = biba_destroy_label,
3489 .mpo_vnode_externalize_label = biba_externalize_label,
3490 .mpo_vnode_init_label = biba_init_label,
3491 .mpo_vnode_internalize_label = biba_internalize_label,
3492 .mpo_vnode_relabel = biba_vnode_relabel,
3493 .mpo_vnode_setlabel_extattr = biba_vnode_setlabel_extattr,
3496 #define BIBA_OBJECTS (MPC_OBJECT_CRED | \
3497 /* MPC_OBJECT_PROC | */ \
3498 MPC_OBJECT_VNODE | \
3499 MPC_OBJECT_INPCB | \
3500 MPC_OBJECT_SOCKET | \
3501 MPC_OBJECT_DEVFS | \
3504 MPC_OBJECT_IFNET | \
3505 MPC_OBJECT_BPFDESC | \
3507 MPC_OBJECT_MOUNT | \
3508 MPC_OBJECT_POSIXSEM | \
3509 /* MPC_OBJECT_POSIXSHM | */ \
3510 MPC_OBJECT_SYSVMSG | \
3511 MPC_OBJECT_SYSVMSQ | \
3512 MPC_OBJECT_SYSVSEM | \
3513 MPC_OBJECT_SYSVSHM | \
3514 MPC_OBJECT_SYNCACHE)
3516 MAC_POLICY_SET(&mac_biba_ops, mac_biba, "TrustedBSD MAC/Biba",
3517 MPC_LOADTIME_FLAG_NOTLATE, &biba_slot, BIBA_OBJECTS);