2 * Copyright (c) 1999-2002, 2007-2011 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 * This software was developed at the University of Cambridge Computer
18 * Laboratory with support from a grant from Google, Inc.
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
23 * 1. Redistributions of source code must retain the above copyright
24 * notice, this list of conditions and the following disclaimer.
25 * 2. Redistributions in binary form must reproduce the above copyright
26 * notice, this list of conditions and the following disclaimer in the
27 * documentation and/or other materials provided with the distribution.
29 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45 * Developed by the TrustedBSD Project.
47 * Biba fixed label mandatory integrity policy.
50 #include <sys/param.h>
52 #include <sys/extattr.h>
53 #include <sys/kernel.h>
55 #include <sys/malloc.h>
57 #include <sys/mount.h>
61 #include <sys/systm.h>
62 #include <sys/sysproto.h>
63 #include <sys/sysent.h>
64 #include <sys/systm.h>
65 #include <sys/vnode.h>
67 #include <sys/socket.h>
68 #include <sys/socketvar.h>
71 #include <sys/sysctl.h>
76 #include <fs/devfs/devfs.h>
78 #include <net/bpfdesc.h>
80 #include <net/if_types.h>
81 #include <net/if_var.h>
83 #include <netinet/in.h>
84 #include <netinet/in_pcb.h>
85 #include <netinet/ip_var.h>
90 #include <security/mac/mac_policy.h>
91 #include <security/mac_biba/mac_biba.h>
93 SYSCTL_DECL(_security_mac);
95 SYSCTL_NODE(_security_mac, OID_AUTO, biba, CTLFLAG_RW, 0,
96 "TrustedBSD mac_biba policy controls");
98 static int biba_label_size = sizeof(struct mac_biba);
99 SYSCTL_INT(_security_mac_biba, OID_AUTO, label_size, CTLFLAG_RD,
100 &biba_label_size, 0, "Size of struct mac_biba");
102 static int biba_enabled = 1;
103 SYSCTL_INT(_security_mac_biba, OID_AUTO, enabled, CTLFLAG_RW, &biba_enabled,
104 0, "Enforce MAC/Biba policy");
105 TUNABLE_INT("security.mac.biba.enabled", &biba_enabled);
107 static int destroyed_not_inited;
108 SYSCTL_INT(_security_mac_biba, OID_AUTO, destroyed_not_inited, CTLFLAG_RD,
109 &destroyed_not_inited, 0, "Count of labels destroyed but not inited");
111 static int trust_all_interfaces = 0;
112 SYSCTL_INT(_security_mac_biba, OID_AUTO, trust_all_interfaces, CTLFLAG_RD,
113 &trust_all_interfaces, 0, "Consider all interfaces 'trusted' by MAC/Biba");
114 TUNABLE_INT("security.mac.biba.trust_all_interfaces", &trust_all_interfaces);
116 static char trusted_interfaces[128];
117 SYSCTL_STRING(_security_mac_biba, OID_AUTO, trusted_interfaces, CTLFLAG_RD,
118 trusted_interfaces, 0, "Interfaces considered 'trusted' by MAC/Biba");
119 TUNABLE_STR("security.mac.biba.trusted_interfaces", trusted_interfaces,
120 sizeof(trusted_interfaces));
122 static int max_compartments = MAC_BIBA_MAX_COMPARTMENTS;
123 SYSCTL_INT(_security_mac_biba, OID_AUTO, max_compartments, CTLFLAG_RD,
124 &max_compartments, 0, "Maximum supported compartments");
126 static int ptys_equal = 0;
127 SYSCTL_INT(_security_mac_biba, OID_AUTO, ptys_equal, CTLFLAG_RW, &ptys_equal,
128 0, "Label pty devices as biba/equal on create");
129 TUNABLE_INT("security.mac.biba.ptys_equal", &ptys_equal);
131 static int interfaces_equal = 1;
132 SYSCTL_INT(_security_mac_biba, OID_AUTO, interfaces_equal, CTLFLAG_RW,
133 &interfaces_equal, 0, "Label network interfaces as biba/equal on create");
134 TUNABLE_INT("security.mac.biba.interfaces_equal", &interfaces_equal);
136 static int revocation_enabled = 0;
137 SYSCTL_INT(_security_mac_biba, OID_AUTO, revocation_enabled, CTLFLAG_RW,
138 &revocation_enabled, 0, "Revoke access to objects on relabel");
139 TUNABLE_INT("security.mac.biba.revocation_enabled", &revocation_enabled);
141 static int biba_slot;
142 #define SLOT(l) ((struct mac_biba *)mac_label_get((l), biba_slot))
143 #define SLOT_SET(l, val) mac_label_set((l), biba_slot, (uintptr_t)(val))
145 static uma_zone_t zone_biba;
148 biba_bit_set_empty(u_char *set) {
151 for (i = 0; i < MAC_BIBA_MAX_COMPARTMENTS >> 3; i++)
157 static struct mac_biba *
161 return (uma_zalloc(zone_biba, flag | M_ZERO));
165 biba_free(struct mac_biba *mb)
169 uma_zfree(zone_biba, mb);
171 atomic_add_int(&destroyed_not_inited, 1);
175 biba_atmostflags(struct mac_biba *mb, int flags)
178 if ((mb->mb_flags & flags) != mb->mb_flags)
184 biba_dominate_element(struct mac_biba_element *a, struct mac_biba_element *b)
188 switch (a->mbe_type) {
189 case MAC_BIBA_TYPE_EQUAL:
190 case MAC_BIBA_TYPE_HIGH:
193 case MAC_BIBA_TYPE_LOW:
194 switch (b->mbe_type) {
195 case MAC_BIBA_TYPE_GRADE:
196 case MAC_BIBA_TYPE_HIGH:
199 case MAC_BIBA_TYPE_EQUAL:
200 case MAC_BIBA_TYPE_LOW:
204 panic("biba_dominate_element: b->mbe_type invalid");
207 case MAC_BIBA_TYPE_GRADE:
208 switch (b->mbe_type) {
209 case MAC_BIBA_TYPE_EQUAL:
210 case MAC_BIBA_TYPE_LOW:
213 case MAC_BIBA_TYPE_HIGH:
216 case MAC_BIBA_TYPE_GRADE:
217 for (bit = 1; bit <= MAC_BIBA_MAX_COMPARTMENTS; bit++)
218 if (!MAC_BIBA_BIT_TEST(bit,
219 a->mbe_compartments) &&
220 MAC_BIBA_BIT_TEST(bit, b->mbe_compartments))
222 return (a->mbe_grade >= b->mbe_grade);
225 panic("biba_dominate_element: b->mbe_type invalid");
229 panic("biba_dominate_element: a->mbe_type invalid");
236 biba_subject_dominate_high(struct mac_biba *mb)
238 struct mac_biba_element *element;
240 KASSERT((mb->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) != 0,
241 ("biba_effective_in_range: mb not effective"));
242 element = &mb->mb_effective;
244 return (element->mbe_type == MAC_BIBA_TYPE_EQUAL ||
245 element->mbe_type == MAC_BIBA_TYPE_HIGH);
249 biba_range_in_range(struct mac_biba *rangea, struct mac_biba *rangeb)
252 return (biba_dominate_element(&rangeb->mb_rangehigh,
253 &rangea->mb_rangehigh) &&
254 biba_dominate_element(&rangea->mb_rangelow,
255 &rangeb->mb_rangelow));
259 biba_effective_in_range(struct mac_biba *effective, struct mac_biba *range)
262 KASSERT((effective->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) != 0,
263 ("biba_effective_in_range: a not effective"));
264 KASSERT((range->mb_flags & MAC_BIBA_FLAG_RANGE) != 0,
265 ("biba_effective_in_range: b not range"));
267 return (biba_dominate_element(&range->mb_rangehigh,
268 &effective->mb_effective) &&
269 biba_dominate_element(&effective->mb_effective,
270 &range->mb_rangelow));
276 biba_dominate_effective(struct mac_biba *a, struct mac_biba *b)
278 KASSERT((a->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) != 0,
279 ("biba_dominate_effective: a not effective"));
280 KASSERT((b->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) != 0,
281 ("biba_dominate_effective: b not effective"));
283 return (biba_dominate_element(&a->mb_effective, &b->mb_effective));
287 biba_equal_element(struct mac_biba_element *a, struct mac_biba_element *b)
290 if (a->mbe_type == MAC_BIBA_TYPE_EQUAL ||
291 b->mbe_type == MAC_BIBA_TYPE_EQUAL)
294 return (a->mbe_type == b->mbe_type && a->mbe_grade == b->mbe_grade);
298 biba_equal_effective(struct mac_biba *a, struct mac_biba *b)
301 KASSERT((a->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) != 0,
302 ("biba_equal_effective: a not effective"));
303 KASSERT((b->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) != 0,
304 ("biba_equal_effective: b not effective"));
306 return (biba_equal_element(&a->mb_effective, &b->mb_effective));
310 biba_contains_equal(struct mac_biba *mb)
313 if (mb->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) {
314 if (mb->mb_effective.mbe_type == MAC_BIBA_TYPE_EQUAL)
318 if (mb->mb_flags & MAC_BIBA_FLAG_RANGE) {
319 if (mb->mb_rangelow.mbe_type == MAC_BIBA_TYPE_EQUAL)
321 if (mb->mb_rangehigh.mbe_type == MAC_BIBA_TYPE_EQUAL)
329 biba_subject_privileged(struct mac_biba *mb)
332 KASSERT((mb->mb_flags & MAC_BIBA_FLAGS_BOTH) == MAC_BIBA_FLAGS_BOTH,
333 ("biba_subject_privileged: subject doesn't have both labels"));
335 /* If the effective is EQUAL, it's ok. */
336 if (mb->mb_effective.mbe_type == MAC_BIBA_TYPE_EQUAL)
339 /* If either range endpoint is EQUAL, it's ok. */
340 if (mb->mb_rangelow.mbe_type == MAC_BIBA_TYPE_EQUAL ||
341 mb->mb_rangehigh.mbe_type == MAC_BIBA_TYPE_EQUAL)
344 /* If the range is low-high, it's ok. */
345 if (mb->mb_rangelow.mbe_type == MAC_BIBA_TYPE_LOW &&
346 mb->mb_rangehigh.mbe_type == MAC_BIBA_TYPE_HIGH)
354 biba_high_effective(struct mac_biba *mb)
357 KASSERT((mb->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) != 0,
358 ("biba_equal_effective: mb not effective"));
360 return (mb->mb_effective.mbe_type == MAC_BIBA_TYPE_HIGH);
364 biba_valid(struct mac_biba *mb)
367 if (mb->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) {
368 switch (mb->mb_effective.mbe_type) {
369 case MAC_BIBA_TYPE_GRADE:
372 case MAC_BIBA_TYPE_EQUAL:
373 case MAC_BIBA_TYPE_HIGH:
374 case MAC_BIBA_TYPE_LOW:
375 if (mb->mb_effective.mbe_grade != 0 ||
376 !MAC_BIBA_BIT_SET_EMPTY(
377 mb->mb_effective.mbe_compartments))
385 if (mb->mb_effective.mbe_type != MAC_BIBA_TYPE_UNDEF)
389 if (mb->mb_flags & MAC_BIBA_FLAG_RANGE) {
390 switch (mb->mb_rangelow.mbe_type) {
391 case MAC_BIBA_TYPE_GRADE:
394 case MAC_BIBA_TYPE_EQUAL:
395 case MAC_BIBA_TYPE_HIGH:
396 case MAC_BIBA_TYPE_LOW:
397 if (mb->mb_rangelow.mbe_grade != 0 ||
398 !MAC_BIBA_BIT_SET_EMPTY(
399 mb->mb_rangelow.mbe_compartments))
407 switch (mb->mb_rangehigh.mbe_type) {
408 case MAC_BIBA_TYPE_GRADE:
411 case MAC_BIBA_TYPE_EQUAL:
412 case MAC_BIBA_TYPE_HIGH:
413 case MAC_BIBA_TYPE_LOW:
414 if (mb->mb_rangehigh.mbe_grade != 0 ||
415 !MAC_BIBA_BIT_SET_EMPTY(
416 mb->mb_rangehigh.mbe_compartments))
423 if (!biba_dominate_element(&mb->mb_rangehigh,
427 if (mb->mb_rangelow.mbe_type != MAC_BIBA_TYPE_UNDEF ||
428 mb->mb_rangehigh.mbe_type != MAC_BIBA_TYPE_UNDEF)
436 biba_set_range(struct mac_biba *mb, u_short typelow, u_short gradelow,
437 u_char *compartmentslow, u_short typehigh, u_short gradehigh,
438 u_char *compartmentshigh)
441 mb->mb_rangelow.mbe_type = typelow;
442 mb->mb_rangelow.mbe_grade = gradelow;
443 if (compartmentslow != NULL)
444 memcpy(mb->mb_rangelow.mbe_compartments, compartmentslow,
445 sizeof(mb->mb_rangelow.mbe_compartments));
446 mb->mb_rangehigh.mbe_type = typehigh;
447 mb->mb_rangehigh.mbe_grade = gradehigh;
448 if (compartmentshigh != NULL)
449 memcpy(mb->mb_rangehigh.mbe_compartments, compartmentshigh,
450 sizeof(mb->mb_rangehigh.mbe_compartments));
451 mb->mb_flags |= MAC_BIBA_FLAG_RANGE;
455 biba_set_effective(struct mac_biba *mb, u_short type, u_short grade,
456 u_char *compartments)
459 mb->mb_effective.mbe_type = type;
460 mb->mb_effective.mbe_grade = grade;
461 if (compartments != NULL)
462 memcpy(mb->mb_effective.mbe_compartments, compartments,
463 sizeof(mb->mb_effective.mbe_compartments));
464 mb->mb_flags |= MAC_BIBA_FLAG_EFFECTIVE;
468 biba_copy_range(struct mac_biba *labelfrom, struct mac_biba *labelto)
471 KASSERT((labelfrom->mb_flags & MAC_BIBA_FLAG_RANGE) != 0,
472 ("biba_copy_range: labelfrom not range"));
474 labelto->mb_rangelow = labelfrom->mb_rangelow;
475 labelto->mb_rangehigh = labelfrom->mb_rangehigh;
476 labelto->mb_flags |= MAC_BIBA_FLAG_RANGE;
480 biba_copy_effective(struct mac_biba *labelfrom, struct mac_biba *labelto)
483 KASSERT((labelfrom->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) != 0,
484 ("biba_copy_effective: labelfrom not effective"));
486 labelto->mb_effective = labelfrom->mb_effective;
487 labelto->mb_flags |= MAC_BIBA_FLAG_EFFECTIVE;
491 biba_copy(struct mac_biba *source, struct mac_biba *dest)
494 if (source->mb_flags & MAC_BIBA_FLAG_EFFECTIVE)
495 biba_copy_effective(source, dest);
496 if (source->mb_flags & MAC_BIBA_FLAG_RANGE)
497 biba_copy_range(source, dest);
501 * Policy module operations.
504 biba_init(struct mac_policy_conf *conf)
507 zone_biba = uma_zcreate("mac_biba", sizeof(struct mac_biba), NULL,
508 NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
515 biba_init_label(struct label *label)
518 SLOT_SET(label, biba_alloc(M_WAITOK));
522 biba_init_label_waitcheck(struct label *label, int flag)
525 SLOT_SET(label, biba_alloc(flag));
526 if (SLOT(label) == NULL)
533 biba_destroy_label(struct label *label)
536 biba_free(SLOT(label));
537 SLOT_SET(label, NULL);
541 * biba_element_to_string() accepts an sbuf and Biba element. It converts
542 * the Biba element to a string and stores the result in the sbuf; if there
543 * isn't space in the sbuf, -1 is returned.
546 biba_element_to_string(struct sbuf *sb, struct mac_biba_element *element)
550 switch (element->mbe_type) {
551 case MAC_BIBA_TYPE_HIGH:
552 return (sbuf_printf(sb, "high"));
554 case MAC_BIBA_TYPE_LOW:
555 return (sbuf_printf(sb, "low"));
557 case MAC_BIBA_TYPE_EQUAL:
558 return (sbuf_printf(sb, "equal"));
560 case MAC_BIBA_TYPE_GRADE:
561 if (sbuf_printf(sb, "%d", element->mbe_grade) == -1)
565 for (i = 1; i <= MAC_BIBA_MAX_COMPARTMENTS; i++) {
566 if (MAC_BIBA_BIT_TEST(i, element->mbe_compartments)) {
568 if (sbuf_putc(sb, ':') == -1)
570 if (sbuf_printf(sb, "%d", i) == -1)
574 if (sbuf_printf(sb, "+%d", i) == -1)
582 panic("biba_element_to_string: invalid type (%d)",
588 * biba_to_string() converts a Biba label to a string, and places the results
589 * in the passed sbuf. It returns 0 on success, or EINVAL if there isn't
590 * room in the sbuf. Note: the sbuf will be modified even in a failure case,
591 * so the caller may need to revert the sbuf by restoring the offset if
595 biba_to_string(struct sbuf *sb, struct mac_biba *mb)
598 if (mb->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) {
599 if (biba_element_to_string(sb, &mb->mb_effective) == -1)
603 if (mb->mb_flags & MAC_BIBA_FLAG_RANGE) {
604 if (sbuf_putc(sb, '(') == -1)
607 if (biba_element_to_string(sb, &mb->mb_rangelow) == -1)
610 if (sbuf_putc(sb, '-') == -1)
613 if (biba_element_to_string(sb, &mb->mb_rangehigh) == -1)
616 if (sbuf_putc(sb, ')') == -1)
624 biba_externalize_label(struct label *label, char *element_name,
625 struct sbuf *sb, int *claimed)
629 if (strcmp(MAC_BIBA_LABEL_NAME, element_name) != 0)
635 return (biba_to_string(sb, mb));
639 biba_parse_element(struct mac_biba_element *element, char *string)
641 char *compartment, *end, *grade;
644 if (strcmp(string, "high") == 0 || strcmp(string, "hi") == 0) {
645 element->mbe_type = MAC_BIBA_TYPE_HIGH;
646 element->mbe_grade = MAC_BIBA_TYPE_UNDEF;
647 } else if (strcmp(string, "low") == 0 || strcmp(string, "lo") == 0) {
648 element->mbe_type = MAC_BIBA_TYPE_LOW;
649 element->mbe_grade = MAC_BIBA_TYPE_UNDEF;
650 } else if (strcmp(string, "equal") == 0 ||
651 strcmp(string, "eq") == 0) {
652 element->mbe_type = MAC_BIBA_TYPE_EQUAL;
653 element->mbe_grade = MAC_BIBA_TYPE_UNDEF;
655 element->mbe_type = MAC_BIBA_TYPE_GRADE;
658 * Numeric grade piece of the element.
660 grade = strsep(&string, ":");
661 value = strtol(grade, &end, 10);
662 if (end == grade || *end != '\0')
664 if (value < 0 || value > 65535)
666 element->mbe_grade = value;
669 * Optional compartment piece of the element. If none are
670 * included, we assume that the label has no compartments.
677 while ((compartment = strsep(&string, "+")) != NULL) {
678 value = strtol(compartment, &end, 10);
679 if (compartment == end || *end != '\0')
681 if (value < 1 || value > MAC_BIBA_MAX_COMPARTMENTS)
683 MAC_BIBA_BIT_SET(value, element->mbe_compartments);
691 * Note: destructively consumes the string, make a local copy before calling
692 * if that's a problem.
695 biba_parse(struct mac_biba *mb, char *string)
697 char *rangehigh, *rangelow, *effective;
700 effective = strsep(&string, "(");
701 if (*effective == '\0')
704 if (string != NULL) {
705 rangelow = strsep(&string, "-");
708 rangehigh = strsep(&string, ")");
718 KASSERT((rangelow != NULL && rangehigh != NULL) ||
719 (rangelow == NULL && rangehigh == NULL),
720 ("biba_parse: range mismatch"));
722 bzero(mb, sizeof(*mb));
723 if (effective != NULL) {
724 error = biba_parse_element(&mb->mb_effective, effective);
727 mb->mb_flags |= MAC_BIBA_FLAG_EFFECTIVE;
730 if (rangelow != NULL) {
731 error = biba_parse_element(&mb->mb_rangelow, rangelow);
734 error = biba_parse_element(&mb->mb_rangehigh, rangehigh);
737 mb->mb_flags |= MAC_BIBA_FLAG_RANGE;
740 error = biba_valid(mb);
748 biba_internalize_label(struct label *label, char *element_name,
749 char *element_data, int *claimed)
751 struct mac_biba *mb, mb_temp;
754 if (strcmp(MAC_BIBA_LABEL_NAME, element_name) != 0)
759 error = biba_parse(&mb_temp, element_data);
770 biba_copy_label(struct label *src, struct label *dest)
773 *SLOT(dest) = *SLOT(src);
777 * Object-specific entry point implementations are sorted alphabetically by
778 * object type name and then by operation.
781 biba_bpfdesc_check_receive(struct bpf_d *d, struct label *dlabel,
782 struct ifnet *ifp, struct label *ifplabel)
784 struct mac_biba *a, *b;
792 if (biba_equal_effective(a, b))
798 biba_bpfdesc_create(struct ucred *cred, struct bpf_d *d,
799 struct label *dlabel)
801 struct mac_biba *source, *dest;
803 source = SLOT(cred->cr_label);
806 biba_copy_effective(source, dest);
810 biba_bpfdesc_create_mbuf(struct bpf_d *d, struct label *dlabel,
811 struct mbuf *m, struct label *mlabel)
813 struct mac_biba *source, *dest;
815 source = SLOT(dlabel);
818 biba_copy_effective(source, dest);
822 biba_cred_associate_nfsd(struct ucred *cred)
824 struct mac_biba *label;
826 label = SLOT(cred->cr_label);
827 biba_set_effective(label, MAC_BIBA_TYPE_LOW, 0, NULL);
828 biba_set_range(label, MAC_BIBA_TYPE_LOW, 0, NULL, MAC_BIBA_TYPE_HIGH,
833 biba_cred_check_relabel(struct ucred *cred, struct label *newlabel)
835 struct mac_biba *subj, *new;
838 subj = SLOT(cred->cr_label);
839 new = SLOT(newlabel);
842 * If there is a Biba label update for the credential, it may
843 * be an update of the effective, range, or both.
845 error = biba_atmostflags(new, MAC_BIBA_FLAGS_BOTH);
850 * If the Biba label is to be changed, authorize as appropriate.
852 if (new->mb_flags & MAC_BIBA_FLAGS_BOTH) {
854 * If the change request modifies both the Biba label
855 * effective and range, check that the new effective will be
858 if ((new->mb_flags & MAC_BIBA_FLAGS_BOTH) ==
859 MAC_BIBA_FLAGS_BOTH &&
860 !biba_effective_in_range(new, new))
864 * To change the Biba effective label on a credential, the
865 * new effective label must be in the current range.
867 if (new->mb_flags & MAC_BIBA_FLAG_EFFECTIVE &&
868 !biba_effective_in_range(new, subj))
872 * To change the Biba range on a credential, the new range
873 * label must be in the current range.
875 if (new->mb_flags & MAC_BIBA_FLAG_RANGE &&
876 !biba_range_in_range(new, subj))
880 * To have EQUAL in any component of the new credential Biba
881 * label, the subject must already have EQUAL in their label.
883 if (biba_contains_equal(new)) {
884 error = biba_subject_privileged(subj);
894 biba_cred_check_visible(struct ucred *u1, struct ucred *u2)
896 struct mac_biba *subj, *obj;
901 subj = SLOT(u1->cr_label);
902 obj = SLOT(u2->cr_label);
905 if (!biba_dominate_effective(obj, subj))
912 biba_cred_create_init(struct ucred *cred)
914 struct mac_biba *dest;
916 dest = SLOT(cred->cr_label);
918 biba_set_effective(dest, MAC_BIBA_TYPE_HIGH, 0, NULL);
919 biba_set_range(dest, MAC_BIBA_TYPE_LOW, 0, NULL, MAC_BIBA_TYPE_HIGH,
924 biba_cred_create_swapper(struct ucred *cred)
926 struct mac_biba *dest;
928 dest = SLOT(cred->cr_label);
930 biba_set_effective(dest, MAC_BIBA_TYPE_EQUAL, 0, NULL);
931 biba_set_range(dest, MAC_BIBA_TYPE_LOW, 0, NULL, MAC_BIBA_TYPE_HIGH,
936 biba_cred_relabel(struct ucred *cred, struct label *newlabel)
938 struct mac_biba *source, *dest;
940 source = SLOT(newlabel);
941 dest = SLOT(cred->cr_label);
943 biba_copy(source, dest);
947 biba_devfs_create_device(struct ucred *cred, struct mount *mp,
948 struct cdev *dev, struct devfs_dirent *de, struct label *delabel)
954 if (strcmp(dev->si_name, "null") == 0 ||
955 strcmp(dev->si_name, "zero") == 0 ||
956 strcmp(dev->si_name, "random") == 0 ||
957 strncmp(dev->si_name, "fd/", strlen("fd/")) == 0)
958 biba_type = MAC_BIBA_TYPE_EQUAL;
959 else if (ptys_equal &&
960 (strncmp(dev->si_name, "ttyp", strlen("ttyp")) == 0 ||
961 strncmp(dev->si_name, "pts/", strlen("pts/")) == 0 ||
962 strncmp(dev->si_name, "ptyp", strlen("ptyp")) == 0))
963 biba_type = MAC_BIBA_TYPE_EQUAL;
965 biba_type = MAC_BIBA_TYPE_HIGH;
966 biba_set_effective(mb, biba_type, 0, NULL);
970 biba_devfs_create_directory(struct mount *mp, char *dirname, int dirnamelen,
971 struct devfs_dirent *de, struct label *delabel)
977 biba_set_effective(mb, MAC_BIBA_TYPE_HIGH, 0, NULL);
981 biba_devfs_create_symlink(struct ucred *cred, struct mount *mp,
982 struct devfs_dirent *dd, struct label *ddlabel, struct devfs_dirent *de,
983 struct label *delabel)
985 struct mac_biba *source, *dest;
987 source = SLOT(cred->cr_label);
988 dest = SLOT(delabel);
990 biba_copy_effective(source, dest);
994 biba_devfs_update(struct mount *mp, struct devfs_dirent *de,
995 struct label *delabel, struct vnode *vp, struct label *vplabel)
997 struct mac_biba *source, *dest;
999 source = SLOT(vplabel);
1000 dest = SLOT(delabel);
1002 biba_copy(source, dest);
1006 biba_devfs_vnode_associate(struct mount *mp, struct label *mntlabel,
1007 struct devfs_dirent *de, struct label *delabel, struct vnode *vp,
1008 struct label *vplabel)
1010 struct mac_biba *source, *dest;
1012 source = SLOT(delabel);
1013 dest = SLOT(vplabel);
1015 biba_copy_effective(source, dest);
1019 biba_ifnet_check_relabel(struct ucred *cred, struct ifnet *ifp,
1020 struct label *ifplabel, struct label *newlabel)
1022 struct mac_biba *subj, *new;
1025 subj = SLOT(cred->cr_label);
1026 new = SLOT(newlabel);
1029 * If there is a Biba label update for the interface, it may be an
1030 * update of the effective, range, or both.
1032 error = biba_atmostflags(new, MAC_BIBA_FLAGS_BOTH);
1037 * Relabling network interfaces requires Biba privilege.
1039 error = biba_subject_privileged(subj);
1047 biba_ifnet_check_transmit(struct ifnet *ifp, struct label *ifplabel,
1048 struct mbuf *m, struct label *mlabel)
1050 struct mac_biba *p, *i;
1058 return (biba_effective_in_range(p, i) ? 0 : EACCES);
1062 biba_ifnet_create(struct ifnet *ifp, struct label *ifplabel)
1064 char tifname[IFNAMSIZ], *p, *q;
1065 char tiflist[sizeof(trusted_interfaces)];
1066 struct mac_biba *dest;
1069 dest = SLOT(ifplabel);
1071 if (ifp->if_type == IFT_LOOP || interfaces_equal != 0) {
1072 type = MAC_BIBA_TYPE_EQUAL;
1076 if (trust_all_interfaces) {
1077 type = MAC_BIBA_TYPE_HIGH;
1081 type = MAC_BIBA_TYPE_LOW;
1083 if (trusted_interfaces[0] == '\0' ||
1084 !strvalid(trusted_interfaces, sizeof(trusted_interfaces)))
1087 bzero(tiflist, sizeof(tiflist));
1088 for (p = trusted_interfaces, q = tiflist; *p != '\0'; p++, q++)
1089 if(*p != ' ' && *p != '\t')
1092 for (p = q = tiflist;; p++) {
1093 if (*p == ',' || *p == '\0') {
1095 if (len < IFNAMSIZ) {
1096 bzero(tifname, sizeof(tifname));
1097 bcopy(q, tifname, len);
1098 if (strcmp(tifname, ifp->if_xname) == 0) {
1099 type = MAC_BIBA_TYPE_HIGH;
1104 printf("mac_biba warning: interface name "
1105 "\"%s\" is too long (must be < %d)\n",
1114 biba_set_effective(dest, type, 0, NULL);
1115 biba_set_range(dest, type, 0, NULL, type, 0, NULL);
1119 biba_ifnet_create_mbuf(struct ifnet *ifp, struct label *ifplabel,
1120 struct mbuf *m, struct label *mlabel)
1122 struct mac_biba *source, *dest;
1124 source = SLOT(ifplabel);
1125 dest = SLOT(mlabel);
1127 biba_copy_effective(source, dest);
1131 biba_ifnet_relabel(struct ucred *cred, struct ifnet *ifp,
1132 struct label *ifplabel, struct label *newlabel)
1134 struct mac_biba *source, *dest;
1136 source = SLOT(newlabel);
1137 dest = SLOT(ifplabel);
1139 biba_copy(source, dest);
1143 biba_inpcb_check_deliver(struct inpcb *inp, struct label *inplabel,
1144 struct mbuf *m, struct label *mlabel)
1146 struct mac_biba *p, *i;
1154 return (biba_equal_effective(p, i) ? 0 : EACCES);
1158 biba_inpcb_check_visible(struct ucred *cred, struct inpcb *inp,
1159 struct label *inplabel)
1161 struct mac_biba *subj, *obj;
1166 subj = SLOT(cred->cr_label);
1167 obj = SLOT(inplabel);
1169 if (!biba_dominate_effective(obj, subj))
1176 biba_inpcb_create(struct socket *so, struct label *solabel,
1177 struct inpcb *inp, struct label *inplabel)
1179 struct mac_biba *source, *dest;
1181 source = SLOT(solabel);
1182 dest = SLOT(inplabel);
1185 biba_copy_effective(source, dest);
1190 biba_inpcb_create_mbuf(struct inpcb *inp, struct label *inplabel,
1191 struct mbuf *m, struct label *mlabel)
1193 struct mac_biba *source, *dest;
1195 source = SLOT(inplabel);
1196 dest = SLOT(mlabel);
1198 biba_copy_effective(source, dest);
1202 biba_inpcb_sosetlabel(struct socket *so, struct label *solabel,
1203 struct inpcb *inp, struct label *inplabel)
1205 struct mac_biba *source, *dest;
1207 SOCK_LOCK_ASSERT(so);
1209 source = SLOT(solabel);
1210 dest = SLOT(inplabel);
1212 biba_copy(source, dest);
1216 biba_ip6q_create(struct mbuf *m, struct label *mlabel, struct ip6q *q6,
1217 struct label *q6label)
1219 struct mac_biba *source, *dest;
1221 source = SLOT(mlabel);
1222 dest = SLOT(q6label);
1224 biba_copy_effective(source, dest);
1228 biba_ip6q_match(struct mbuf *m, struct label *mlabel, struct ip6q *q6,
1229 struct label *q6label)
1231 struct mac_biba *a, *b;
1236 return (biba_equal_effective(a, b));
1240 biba_ip6q_reassemble(struct ip6q *q6, struct label *q6label, struct mbuf *m,
1241 struct label *mlabel)
1243 struct mac_biba *source, *dest;
1245 source = SLOT(q6label);
1246 dest = SLOT(mlabel);
1248 /* Just use the head, since we require them all to match. */
1249 biba_copy_effective(source, dest);
1253 biba_ip6q_update(struct mbuf *m, struct label *mlabel, struct ip6q *q6,
1254 struct label *q6label)
1257 /* NOOP: we only accept matching labels, so no need to update */
1261 biba_ipq_create(struct mbuf *m, struct label *mlabel, struct ipq *q,
1262 struct label *qlabel)
1264 struct mac_biba *source, *dest;
1266 source = SLOT(mlabel);
1267 dest = SLOT(qlabel);
1269 biba_copy_effective(source, dest);
1273 biba_ipq_match(struct mbuf *m, struct label *mlabel, struct ipq *q,
1274 struct label *qlabel)
1276 struct mac_biba *a, *b;
1281 return (biba_equal_effective(a, b));
1285 biba_ipq_reassemble(struct ipq *q, struct label *qlabel, struct mbuf *m,
1286 struct label *mlabel)
1288 struct mac_biba *source, *dest;
1290 source = SLOT(qlabel);
1291 dest = SLOT(mlabel);
1293 /* Just use the head, since we require them all to match. */
1294 biba_copy_effective(source, dest);
1298 biba_ipq_update(struct mbuf *m, struct label *mlabel, struct ipq *q,
1299 struct label *qlabel)
1302 /* NOOP: we only accept matching labels, so no need to update */
1306 biba_kld_check_load(struct ucred *cred, struct vnode *vp,
1307 struct label *vplabel)
1309 struct mac_biba *subj, *obj;
1315 subj = SLOT(cred->cr_label);
1317 error = biba_subject_privileged(subj);
1321 obj = SLOT(vplabel);
1322 if (!biba_high_effective(obj))
1329 biba_mount_check_stat(struct ucred *cred, struct mount *mp,
1330 struct label *mplabel)
1332 struct mac_biba *subj, *obj;
1337 subj = SLOT(cred->cr_label);
1338 obj = SLOT(mplabel);
1340 if (!biba_dominate_effective(obj, subj))
1347 biba_mount_create(struct ucred *cred, struct mount *mp,
1348 struct label *mplabel)
1350 struct mac_biba *source, *dest;
1352 source = SLOT(cred->cr_label);
1353 dest = SLOT(mplabel);
1355 biba_copy_effective(source, dest);
1359 biba_netatalk_aarp_send(struct ifnet *ifp, struct label *ifplabel,
1360 struct mbuf *m, struct label *mlabel)
1362 struct mac_biba *dest;
1364 dest = SLOT(mlabel);
1366 biba_set_effective(dest, MAC_BIBA_TYPE_EQUAL, 0, NULL);
1370 biba_netinet_arp_send(struct ifnet *ifp, struct label *ifplabel,
1371 struct mbuf *m, struct label *mlabel)
1373 struct mac_biba *dest;
1375 dest = SLOT(mlabel);
1377 biba_set_effective(dest, MAC_BIBA_TYPE_EQUAL, 0, NULL);
1381 biba_netinet_firewall_reply(struct mbuf *mrecv, struct label *mrecvlabel,
1382 struct mbuf *msend, struct label *msendlabel)
1384 struct mac_biba *source, *dest;
1386 source = SLOT(mrecvlabel);
1387 dest = SLOT(msendlabel);
1389 biba_copy_effective(source, dest);
1393 biba_netinet_firewall_send(struct mbuf *m, struct label *mlabel)
1395 struct mac_biba *dest;
1397 dest = SLOT(mlabel);
1399 /* XXX: where is the label for the firewall really coming from? */
1400 biba_set_effective(dest, MAC_BIBA_TYPE_EQUAL, 0, NULL);
1404 biba_netinet_fragment(struct mbuf *m, struct label *mlabel,
1405 struct mbuf *frag, struct label *fraglabel)
1407 struct mac_biba *source, *dest;
1409 source = SLOT(mlabel);
1410 dest = SLOT(fraglabel);
1412 biba_copy_effective(source, dest);
1416 biba_netinet_icmp_reply(struct mbuf *mrecv, struct label *mrecvlabel,
1417 struct mbuf *msend, struct label *msendlabel)
1419 struct mac_biba *source, *dest;
1421 source = SLOT(mrecvlabel);
1422 dest = SLOT(msendlabel);
1424 biba_copy_effective(source, dest);
1428 biba_netinet_igmp_send(struct ifnet *ifp, struct label *ifplabel,
1429 struct mbuf *m, struct label *mlabel)
1431 struct mac_biba *dest;
1433 dest = SLOT(mlabel);
1435 biba_set_effective(dest, MAC_BIBA_TYPE_EQUAL, 0, NULL);
1439 biba_netinet6_nd6_send(struct ifnet *ifp, struct label *ifplabel,
1440 struct mbuf *m, struct label *mlabel)
1442 struct mac_biba *dest;
1444 dest = SLOT(mlabel);
1446 biba_set_effective(dest, MAC_BIBA_TYPE_EQUAL, 0, NULL);
1450 biba_pipe_check_ioctl(struct ucred *cred, struct pipepair *pp,
1451 struct label *pplabel, unsigned long cmd, void /* caddr_t */ *data)
1457 /* XXX: This will be implemented soon... */
1463 biba_pipe_check_poll(struct ucred *cred, struct pipepair *pp,
1464 struct label *pplabel)
1466 struct mac_biba *subj, *obj;
1471 subj = SLOT(cred->cr_label);
1472 obj = SLOT(pplabel);
1474 if (!biba_dominate_effective(obj, subj))
1481 biba_pipe_check_read(struct ucred *cred, struct pipepair *pp,
1482 struct label *pplabel)
1484 struct mac_biba *subj, *obj;
1489 subj = SLOT(cred->cr_label);
1490 obj = SLOT(pplabel);
1492 if (!biba_dominate_effective(obj, subj))
1499 biba_pipe_check_relabel(struct ucred *cred, struct pipepair *pp,
1500 struct label *pplabel, struct label *newlabel)
1502 struct mac_biba *subj, *obj, *new;
1505 new = SLOT(newlabel);
1506 subj = SLOT(cred->cr_label);
1507 obj = SLOT(pplabel);
1510 * If there is a Biba label update for a pipe, it must be a effective
1513 error = biba_atmostflags(new, MAC_BIBA_FLAG_EFFECTIVE);
1518 * To perform a relabel of a pipe (Biba label or not), Biba must
1519 * authorize the relabel.
1521 if (!biba_effective_in_range(obj, subj))
1525 * If the Biba label is to be changed, authorize as appropriate.
1527 if (new->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) {
1529 * To change the Biba label on a pipe, the new pipe label
1530 * must be in the subject range.
1532 if (!biba_effective_in_range(new, subj))
1536 * To change the Biba label on a pipe to be EQUAL, the
1537 * subject must have appropriate privilege.
1539 if (biba_contains_equal(new)) {
1540 error = biba_subject_privileged(subj);
1550 biba_pipe_check_stat(struct ucred *cred, struct pipepair *pp,
1551 struct label *pplabel)
1553 struct mac_biba *subj, *obj;
1558 subj = SLOT(cred->cr_label);
1559 obj = SLOT(pplabel);
1561 if (!biba_dominate_effective(obj, subj))
1568 biba_pipe_check_write(struct ucred *cred, struct pipepair *pp,
1569 struct label *pplabel)
1571 struct mac_biba *subj, *obj;
1576 subj = SLOT(cred->cr_label);
1577 obj = SLOT(pplabel);
1579 if (!biba_dominate_effective(subj, obj))
1586 biba_pipe_create(struct ucred *cred, struct pipepair *pp,
1587 struct label *pplabel)
1589 struct mac_biba *source, *dest;
1591 source = SLOT(cred->cr_label);
1592 dest = SLOT(pplabel);
1594 biba_copy_effective(source, dest);
1598 biba_pipe_relabel(struct ucred *cred, struct pipepair *pp,
1599 struct label *pplabel, struct label *newlabel)
1601 struct mac_biba *source, *dest;
1603 source = SLOT(newlabel);
1604 dest = SLOT(pplabel);
1606 biba_copy(source, dest);
1610 biba_posixsem_check_openunlink(struct ucred *cred, struct ksem *ks,
1611 struct label *kslabel)
1613 struct mac_biba *subj, *obj;
1618 subj = SLOT(cred->cr_label);
1619 obj = SLOT(kslabel);
1621 if (!biba_dominate_effective(subj, obj))
1628 biba_posixsem_check_setmode(struct ucred *cred, struct ksem *ks,
1629 struct label *kslabel, mode_t mode)
1631 struct mac_biba *subj, *obj;
1636 subj = SLOT(cred->cr_label);
1637 obj = SLOT(kslabel);
1639 if (!biba_dominate_effective(subj, obj))
1646 biba_posixsem_check_setowner(struct ucred *cred, struct ksem *ks,
1647 struct label *kslabel, uid_t uid, gid_t gid)
1649 struct mac_biba *subj, *obj;
1654 subj = SLOT(cred->cr_label);
1655 obj = SLOT(kslabel);
1657 if (!biba_dominate_effective(subj, obj))
1664 biba_posixsem_check_write(struct ucred *active_cred, struct ucred *file_cred,
1665 struct ksem *ks, struct label *kslabel)
1667 struct mac_biba *subj, *obj;
1672 subj = SLOT(active_cred->cr_label);
1673 obj = SLOT(kslabel);
1675 if (!biba_dominate_effective(subj, obj))
1682 biba_posixsem_check_rdonly(struct ucred *active_cred, struct ucred *file_cred,
1683 struct ksem *ks, struct label *kslabel)
1685 struct mac_biba *subj, *obj;
1690 subj = SLOT(active_cred->cr_label);
1691 obj = SLOT(kslabel);
1693 if (!biba_dominate_effective(obj, subj))
1700 biba_posixsem_create(struct ucred *cred, struct ksem *ks,
1701 struct label *kslabel)
1703 struct mac_biba *source, *dest;
1705 source = SLOT(cred->cr_label);
1706 dest = SLOT(kslabel);
1708 biba_copy_effective(source, dest);
1712 biba_posixshm_check_mmap(struct ucred *cred, struct shmfd *shmfd,
1713 struct label *shmlabel, int prot, int flags)
1715 struct mac_biba *subj, *obj;
1717 if (!biba_enabled || !revocation_enabled)
1720 subj = SLOT(cred->cr_label);
1721 obj = SLOT(shmlabel);
1723 if (prot & (VM_PROT_READ | VM_PROT_EXECUTE)) {
1724 if (!biba_dominate_effective(obj, subj))
1727 if (((prot & VM_PROT_WRITE) != 0) && ((flags & MAP_SHARED) != 0)) {
1728 if (!biba_dominate_effective(subj, obj))
1736 biba_posixshm_check_open(struct ucred *cred, struct shmfd *shmfd,
1737 struct label *shmlabel, accmode_t accmode)
1739 struct mac_biba *subj, *obj;
1744 subj = SLOT(cred->cr_label);
1745 obj = SLOT(shmlabel);
1747 if (accmode & (VREAD | VEXEC | VSTAT_PERMS)) {
1748 if (!biba_dominate_effective(obj, subj))
1751 if (accmode & VMODIFY_PERMS) {
1752 if (!biba_dominate_effective(subj, obj))
1760 biba_posixshm_check_setmode(struct ucred *cred, struct shmfd *shmfd,
1761 struct label *shmlabel, mode_t mode)
1763 struct mac_biba *subj, *obj;
1768 subj = SLOT(cred->cr_label);
1769 obj = SLOT(shmlabel);
1771 if (!biba_dominate_effective(subj, obj))
1778 biba_posixshm_check_setowner(struct ucred *cred, struct shmfd *shmfd,
1779 struct label *shmlabel, uid_t uid, gid_t gid)
1781 struct mac_biba *subj, *obj;
1786 subj = SLOT(cred->cr_label);
1787 obj = SLOT(shmlabel);
1789 if (!biba_dominate_effective(subj, obj))
1796 biba_posixshm_check_stat(struct ucred *active_cred, struct ucred *file_cred,
1797 struct shmfd *shmfd, struct label *shmlabel)
1799 struct mac_biba *subj, *obj;
1804 subj = SLOT(active_cred->cr_label);
1805 obj = SLOT(shmlabel);
1807 if (!biba_dominate_effective(obj, subj))
1814 biba_posixshm_check_truncate(struct ucred *active_cred,
1815 struct ucred *file_cred, struct shmfd *shmfd, struct label *shmlabel)
1817 struct mac_biba *subj, *obj;
1822 subj = SLOT(active_cred->cr_label);
1823 obj = SLOT(shmlabel);
1825 if (!biba_dominate_effective(subj, obj))
1832 biba_posixshm_check_unlink(struct ucred *cred, struct shmfd *shmfd,
1833 struct label *shmlabel)
1835 struct mac_biba *subj, *obj;
1840 subj = SLOT(cred->cr_label);
1841 obj = SLOT(shmlabel);
1843 if (!biba_dominate_effective(subj, obj))
1850 biba_posixshm_create(struct ucred *cred, struct shmfd *shmfd,
1851 struct label *shmlabel)
1853 struct mac_biba *source, *dest;
1855 source = SLOT(cred->cr_label);
1856 dest = SLOT(shmlabel);
1858 biba_copy_effective(source, dest);
1862 * Some system privileges are allowed regardless of integrity grade; others
1863 * are allowed only when running with privilege with respect to the Biba
1864 * policy as they might otherwise allow bypassing of the integrity policy.
1867 biba_priv_check(struct ucred *cred, int priv)
1869 struct mac_biba *subj;
1876 * Exempt only specific privileges from the Biba integrity policy.
1883 * Allow processes to manipulate basic process audit properties, and
1884 * to submit audit records.
1886 case PRIV_AUDIT_GETAUDIT:
1887 case PRIV_AUDIT_SETAUDIT:
1888 case PRIV_AUDIT_SUBMIT:
1891 * Allow processes to manipulate their regular UNIX credentials.
1893 case PRIV_CRED_SETUID:
1894 case PRIV_CRED_SETEUID:
1895 case PRIV_CRED_SETGID:
1896 case PRIV_CRED_SETEGID:
1897 case PRIV_CRED_SETGROUPS:
1898 case PRIV_CRED_SETREUID:
1899 case PRIV_CRED_SETREGID:
1900 case PRIV_CRED_SETRESUID:
1901 case PRIV_CRED_SETRESGID:
1904 * Allow processes to perform system monitoring.
1906 case PRIV_SEEOTHERGIDS:
1907 case PRIV_SEEOTHERUIDS:
1911 * Allow access to general process debugging facilities. We
1912 * separately control debugging based on MAC label.
1914 case PRIV_DEBUG_DIFFCRED:
1915 case PRIV_DEBUG_SUGID:
1916 case PRIV_DEBUG_UNPRIV:
1919 * Allow manipulating jails.
1921 case PRIV_JAIL_ATTACH:
1924 * Allow privilege with respect to the Partition policy, but not the
1927 case PRIV_MAC_PARTITION:
1930 * Allow privilege with respect to process resource limits and login
1933 case PRIV_PROC_LIMIT:
1934 case PRIV_PROC_SETLOGIN:
1935 case PRIV_PROC_SETRLIMIT:
1938 * Allow System V and POSIX IPC privileges.
1941 case PRIV_IPC_WRITE:
1942 case PRIV_IPC_ADMIN:
1943 case PRIV_IPC_MSGSIZE:
1947 * Allow certain scheduler manipulations -- possibly this should be
1948 * controlled by more fine-grained policy, as potentially low
1949 * integrity processes can deny CPU to higher integrity ones.
1951 case PRIV_SCHED_DIFFCRED:
1952 case PRIV_SCHED_SETPRIORITY:
1953 case PRIV_SCHED_RTPRIO:
1954 case PRIV_SCHED_SETPOLICY:
1955 case PRIV_SCHED_SET:
1956 case PRIV_SCHED_SETPARAM:
1959 * More IPC privileges.
1961 case PRIV_SEM_WRITE:
1964 * Allow signaling privileges subject to integrity policy.
1966 case PRIV_SIGNAL_DIFFCRED:
1967 case PRIV_SIGNAL_SUGID:
1970 * Allow access to only limited sysctls from lower integrity levels;
1971 * piggy-back on the Jail definition.
1973 case PRIV_SYSCTL_WRITEJAIL:
1976 * Allow TTY-based privileges, subject to general device access using
1977 * labels on TTY device nodes, but not console privilege.
1979 case PRIV_TTY_DRAINWAIT:
1980 case PRIV_TTY_DTRWAIT:
1981 case PRIV_TTY_EXCLUSIVE:
1986 * Grant most VFS privileges, as almost all are in practice bounded
1987 * by more specific checks using labels.
1990 case PRIV_VFS_WRITE:
1991 case PRIV_VFS_ADMIN:
1993 case PRIV_VFS_LOOKUP:
1994 case PRIV_VFS_CHFLAGS_DEV:
1995 case PRIV_VFS_CHOWN:
1996 case PRIV_VFS_CHROOT:
1997 case PRIV_VFS_RETAINSUGID:
1998 case PRIV_VFS_EXCEEDQUOTA:
1999 case PRIV_VFS_FCHROOT:
2000 case PRIV_VFS_FHOPEN:
2001 case PRIV_VFS_FHSTATFS:
2002 case PRIV_VFS_GENERATION:
2003 case PRIV_VFS_GETFH:
2004 case PRIV_VFS_GETQUOTA:
2006 case PRIV_VFS_MOUNT:
2007 case PRIV_VFS_MOUNT_OWNER:
2008 case PRIV_VFS_MOUNT_PERM:
2009 case PRIV_VFS_MOUNT_SUIDDIR:
2010 case PRIV_VFS_MOUNT_NONUSER:
2011 case PRIV_VFS_SETGID:
2012 case PRIV_VFS_STICKYFILE:
2013 case PRIV_VFS_SYSFLAGS:
2014 case PRIV_VFS_UNMOUNT:
2017 * Allow VM privileges; it would be nice if these were subject to
2020 case PRIV_VM_MADV_PROTECT:
2022 case PRIV_VM_MUNLOCK:
2023 case PRIV_VM_SWAP_NOQUOTA:
2024 case PRIV_VM_SWAP_NORLIMIT:
2027 * Allow some but not all network privileges. In general, dont allow
2028 * reconfiguring the network stack, just normal use.
2030 case PRIV_NETATALK_RESERVEDPORT:
2031 case PRIV_NETINET_RESERVEDPORT:
2032 case PRIV_NETINET_RAW:
2033 case PRIV_NETINET_REUSEPORT:
2034 case PRIV_NETIPX_RESERVEDPORT:
2035 case PRIV_NETIPX_RAW:
2039 * All remaining system privileges are allow only if the process
2040 * holds privilege with respect to the Biba policy.
2043 subj = SLOT(cred->cr_label);
2044 error = biba_subject_privileged(subj);
2052 biba_proc_check_debug(struct ucred *cred, struct proc *p)
2054 struct mac_biba *subj, *obj;
2059 subj = SLOT(cred->cr_label);
2060 obj = SLOT(p->p_ucred->cr_label);
2062 /* XXX: range checks */
2063 if (!biba_dominate_effective(obj, subj))
2065 if (!biba_dominate_effective(subj, obj))
2072 biba_proc_check_sched(struct ucred *cred, struct proc *p)
2074 struct mac_biba *subj, *obj;
2079 subj = SLOT(cred->cr_label);
2080 obj = SLOT(p->p_ucred->cr_label);
2082 /* XXX: range checks */
2083 if (!biba_dominate_effective(obj, subj))
2085 if (!biba_dominate_effective(subj, obj))
2092 biba_proc_check_signal(struct ucred *cred, struct proc *p, int signum)
2094 struct mac_biba *subj, *obj;
2099 subj = SLOT(cred->cr_label);
2100 obj = SLOT(p->p_ucred->cr_label);
2102 /* XXX: range checks */
2103 if (!biba_dominate_effective(obj, subj))
2105 if (!biba_dominate_effective(subj, obj))
2112 biba_socket_check_deliver(struct socket *so, struct label *solabel,
2113 struct mbuf *m, struct label *mlabel)
2115 struct mac_biba *p, *s;
2125 error = biba_equal_effective(p, s) ? 0 : EACCES;
2131 biba_socket_check_relabel(struct ucred *cred, struct socket *so,
2132 struct label *solabel, struct label *newlabel)
2134 struct mac_biba *subj, *obj, *new;
2137 SOCK_LOCK_ASSERT(so);
2139 new = SLOT(newlabel);
2140 subj = SLOT(cred->cr_label);
2141 obj = SLOT(solabel);
2144 * If there is a Biba label update for the socket, it may be an
2145 * update of effective.
2147 error = biba_atmostflags(new, MAC_BIBA_FLAG_EFFECTIVE);
2152 * To relabel a socket, the old socket effective must be in the
2155 if (!biba_effective_in_range(obj, subj))
2159 * If the Biba label is to be changed, authorize as appropriate.
2161 if (new->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) {
2163 * To relabel a socket, the new socket effective must be in
2164 * the subject range.
2166 if (!biba_effective_in_range(new, subj))
2170 * To change the Biba label on the socket to contain EQUAL,
2171 * the subject must have appropriate privilege.
2173 if (biba_contains_equal(new)) {
2174 error = biba_subject_privileged(subj);
2184 biba_socket_check_visible(struct ucred *cred, struct socket *so,
2185 struct label *solabel)
2187 struct mac_biba *subj, *obj;
2192 subj = SLOT(cred->cr_label);
2193 obj = SLOT(solabel);
2196 if (!biba_dominate_effective(obj, subj)) {
2206 biba_socket_create(struct ucred *cred, struct socket *so,
2207 struct label *solabel)
2209 struct mac_biba *source, *dest;
2211 source = SLOT(cred->cr_label);
2212 dest = SLOT(solabel);
2214 biba_copy_effective(source, dest);
2218 biba_socket_create_mbuf(struct socket *so, struct label *solabel,
2219 struct mbuf *m, struct label *mlabel)
2221 struct mac_biba *source, *dest;
2223 source = SLOT(solabel);
2224 dest = SLOT(mlabel);
2227 biba_copy_effective(source, dest);
2232 biba_socket_newconn(struct socket *oldso, struct label *oldsolabel,
2233 struct socket *newso, struct label *newsolabel)
2235 struct mac_biba source, *dest;
2238 source = *SLOT(oldsolabel);
2241 dest = SLOT(newsolabel);
2244 biba_copy_effective(&source, dest);
2249 biba_socket_relabel(struct ucred *cred, struct socket *so,
2250 struct label *solabel, struct label *newlabel)
2252 struct mac_biba *source, *dest;
2254 SOCK_LOCK_ASSERT(so);
2256 source = SLOT(newlabel);
2257 dest = SLOT(solabel);
2259 biba_copy(source, dest);
2263 biba_socketpeer_set_from_mbuf(struct mbuf *m, struct label *mlabel,
2264 struct socket *so, struct label *sopeerlabel)
2266 struct mac_biba *source, *dest;
2268 source = SLOT(mlabel);
2269 dest = SLOT(sopeerlabel);
2272 biba_copy_effective(source, dest);
2277 biba_socketpeer_set_from_socket(struct socket *oldso,
2278 struct label *oldsolabel, struct socket *newso,
2279 struct label *newsopeerlabel)
2281 struct mac_biba source, *dest;
2284 source = *SLOT(oldsolabel);
2286 dest = SLOT(newsopeerlabel);
2289 biba_copy_effective(&source, dest);
2294 biba_syncache_create(struct label *label, struct inpcb *inp)
2296 struct mac_biba *source, *dest;
2298 source = SLOT(inp->inp_label);
2300 biba_copy_effective(source, dest);
2304 biba_syncache_create_mbuf(struct label *sc_label, struct mbuf *m,
2305 struct label *mlabel)
2307 struct mac_biba *source, *dest;
2309 source = SLOT(sc_label);
2310 dest = SLOT(mlabel);
2311 biba_copy_effective(source, dest);
2315 biba_system_check_acct(struct ucred *cred, struct vnode *vp,
2316 struct label *vplabel)
2318 struct mac_biba *subj, *obj;
2324 subj = SLOT(cred->cr_label);
2326 error = biba_subject_privileged(subj);
2330 if (vplabel == NULL)
2333 obj = SLOT(vplabel);
2334 if (!biba_high_effective(obj))
2341 biba_system_check_auditctl(struct ucred *cred, struct vnode *vp,
2342 struct label *vplabel)
2344 struct mac_biba *subj, *obj;
2350 subj = SLOT(cred->cr_label);
2352 error = biba_subject_privileged(subj);
2356 if (vplabel == NULL)
2359 obj = SLOT(vplabel);
2360 if (!biba_high_effective(obj))
2367 biba_system_check_auditon(struct ucred *cred, int cmd)
2369 struct mac_biba *subj;
2375 subj = SLOT(cred->cr_label);
2377 error = biba_subject_privileged(subj);
2385 biba_system_check_swapoff(struct ucred *cred, struct vnode *vp,
2386 struct label *label)
2388 struct mac_biba *subj;
2394 subj = SLOT(cred->cr_label);
2396 error = biba_subject_privileged(subj);
2404 biba_system_check_swapon(struct ucred *cred, struct vnode *vp,
2405 struct label *vplabel)
2407 struct mac_biba *subj, *obj;
2413 subj = SLOT(cred->cr_label);
2414 obj = SLOT(vplabel);
2416 error = biba_subject_privileged(subj);
2420 if (!biba_high_effective(obj))
2427 biba_system_check_sysctl(struct ucred *cred, struct sysctl_oid *oidp,
2428 void *arg1, int arg2, struct sysctl_req *req)
2430 struct mac_biba *subj;
2436 subj = SLOT(cred->cr_label);
2439 * Treat sysctl variables without CTLFLAG_ANYBODY flag as biba/high,
2440 * but also require privilege to change them.
2442 if (req->newptr != NULL && (oidp->oid_kind & CTLFLAG_ANYBODY) == 0) {
2443 if (!biba_subject_dominate_high(subj))
2446 error = biba_subject_privileged(subj);
2455 biba_sysvmsg_cleanup(struct label *msglabel)
2458 bzero(SLOT(msglabel), sizeof(struct mac_biba));
2462 biba_sysvmsg_create(struct ucred *cred, struct msqid_kernel *msqkptr,
2463 struct label *msqlabel, struct msg *msgptr, struct label *msglabel)
2465 struct mac_biba *source, *dest;
2467 /* Ignore the msgq label */
2468 source = SLOT(cred->cr_label);
2469 dest = SLOT(msglabel);
2471 biba_copy_effective(source, dest);
2475 biba_sysvmsq_check_msgrcv(struct ucred *cred, struct msg *msgptr,
2476 struct label *msglabel)
2478 struct mac_biba *subj, *obj;
2483 subj = SLOT(cred->cr_label);
2484 obj = SLOT(msglabel);
2486 if (!biba_dominate_effective(obj, subj))
2493 biba_sysvmsq_check_msgrmid(struct ucred *cred, struct msg *msgptr,
2494 struct label *msglabel)
2496 struct mac_biba *subj, *obj;
2501 subj = SLOT(cred->cr_label);
2502 obj = SLOT(msglabel);
2504 if (!biba_dominate_effective(subj, obj))
2511 biba_sysvmsq_check_msqget(struct ucred *cred, struct msqid_kernel *msqkptr,
2512 struct label *msqklabel)
2514 struct mac_biba *subj, *obj;
2519 subj = SLOT(cred->cr_label);
2520 obj = SLOT(msqklabel);
2522 if (!biba_dominate_effective(obj, subj))
2529 biba_sysvmsq_check_msqsnd(struct ucred *cred, struct msqid_kernel *msqkptr,
2530 struct label *msqklabel)
2532 struct mac_biba *subj, *obj;
2537 subj = SLOT(cred->cr_label);
2538 obj = SLOT(msqklabel);
2540 if (!biba_dominate_effective(subj, obj))
2547 biba_sysvmsq_check_msqrcv(struct ucred *cred, struct msqid_kernel *msqkptr,
2548 struct label *msqklabel)
2550 struct mac_biba *subj, *obj;
2555 subj = SLOT(cred->cr_label);
2556 obj = SLOT(msqklabel);
2558 if (!biba_dominate_effective(obj, subj))
2565 biba_sysvmsq_check_msqctl(struct ucred *cred, struct msqid_kernel *msqkptr,
2566 struct label *msqklabel, int cmd)
2568 struct mac_biba *subj, *obj;
2573 subj = SLOT(cred->cr_label);
2574 obj = SLOT(msqklabel);
2579 if (!biba_dominate_effective(subj, obj))
2584 if (!biba_dominate_effective(obj, subj))
2596 biba_sysvmsq_cleanup(struct label *msqlabel)
2599 bzero(SLOT(msqlabel), sizeof(struct mac_biba));
2603 biba_sysvmsq_create(struct ucred *cred, struct msqid_kernel *msqkptr,
2604 struct label *msqlabel)
2606 struct mac_biba *source, *dest;
2608 source = SLOT(cred->cr_label);
2609 dest = SLOT(msqlabel);
2611 biba_copy_effective(source, dest);
2615 biba_sysvsem_check_semctl(struct ucred *cred, struct semid_kernel *semakptr,
2616 struct label *semaklabel, int cmd)
2618 struct mac_biba *subj, *obj;
2623 subj = SLOT(cred->cr_label);
2624 obj = SLOT(semaklabel);
2631 if (!biba_dominate_effective(subj, obj))
2641 if (!biba_dominate_effective(obj, subj))
2653 biba_sysvsem_check_semget(struct ucred *cred, struct semid_kernel *semakptr,
2654 struct label *semaklabel)
2656 struct mac_biba *subj, *obj;
2661 subj = SLOT(cred->cr_label);
2662 obj = SLOT(semaklabel);
2664 if (!biba_dominate_effective(obj, subj))
2671 biba_sysvsem_check_semop(struct ucred *cred, struct semid_kernel *semakptr,
2672 struct label *semaklabel, size_t accesstype)
2674 struct mac_biba *subj, *obj;
2679 subj = SLOT(cred->cr_label);
2680 obj = SLOT(semaklabel);
2682 if (accesstype & SEM_R)
2683 if (!biba_dominate_effective(obj, subj))
2686 if (accesstype & SEM_A)
2687 if (!biba_dominate_effective(subj, obj))
2694 biba_sysvsem_cleanup(struct label *semalabel)
2697 bzero(SLOT(semalabel), sizeof(struct mac_biba));
2701 biba_sysvsem_create(struct ucred *cred, struct semid_kernel *semakptr,
2702 struct label *semalabel)
2704 struct mac_biba *source, *dest;
2706 source = SLOT(cred->cr_label);
2707 dest = SLOT(semalabel);
2709 biba_copy_effective(source, dest);
2713 biba_sysvshm_check_shmat(struct ucred *cred, struct shmid_kernel *shmsegptr,
2714 struct label *shmseglabel, int shmflg)
2716 struct mac_biba *subj, *obj;
2721 subj = SLOT(cred->cr_label);
2722 obj = SLOT(shmseglabel);
2724 if (!biba_dominate_effective(obj, subj))
2726 if ((shmflg & SHM_RDONLY) == 0) {
2727 if (!biba_dominate_effective(subj, obj))
2735 biba_sysvshm_check_shmctl(struct ucred *cred, struct shmid_kernel *shmsegptr,
2736 struct label *shmseglabel, int cmd)
2738 struct mac_biba *subj, *obj;
2743 subj = SLOT(cred->cr_label);
2744 obj = SLOT(shmseglabel);
2749 if (!biba_dominate_effective(subj, obj))
2755 if (!biba_dominate_effective(obj, subj))
2767 biba_sysvshm_check_shmget(struct ucred *cred, struct shmid_kernel *shmsegptr,
2768 struct label *shmseglabel, int shmflg)
2770 struct mac_biba *subj, *obj;
2775 subj = SLOT(cred->cr_label);
2776 obj = SLOT(shmseglabel);
2778 if (!biba_dominate_effective(obj, subj))
2785 biba_sysvshm_cleanup(struct label *shmlabel)
2788 bzero(SLOT(shmlabel), sizeof(struct mac_biba));
2792 biba_sysvshm_create(struct ucred *cred, struct shmid_kernel *shmsegptr,
2793 struct label *shmlabel)
2795 struct mac_biba *source, *dest;
2797 source = SLOT(cred->cr_label);
2798 dest = SLOT(shmlabel);
2800 biba_copy_effective(source, dest);
2804 biba_vnode_associate_extattr(struct mount *mp, struct label *mplabel,
2805 struct vnode *vp, struct label *vplabel)
2807 struct mac_biba mb_temp, *source, *dest;
2810 source = SLOT(mplabel);
2811 dest = SLOT(vplabel);
2813 buflen = sizeof(mb_temp);
2814 bzero(&mb_temp, buflen);
2816 error = vn_extattr_get(vp, IO_NODELOCKED, MAC_BIBA_EXTATTR_NAMESPACE,
2817 MAC_BIBA_EXTATTR_NAME, &buflen, (char *) &mb_temp, curthread);
2818 if (error == ENOATTR || error == EOPNOTSUPP) {
2819 /* Fall back to the mntlabel. */
2820 biba_copy_effective(source, dest);
2825 if (buflen != sizeof(mb_temp)) {
2826 printf("biba_vnode_associate_extattr: bad size %d\n",
2830 if (biba_valid(&mb_temp) != 0) {
2831 printf("biba_vnode_associate_extattr: invalid\n");
2834 if ((mb_temp.mb_flags & MAC_BIBA_FLAGS_BOTH) !=
2835 MAC_BIBA_FLAG_EFFECTIVE) {
2836 printf("biba_vnode_associate_extattr: not effective\n");
2840 biba_copy_effective(&mb_temp, dest);
2845 biba_vnode_associate_singlelabel(struct mount *mp, struct label *mplabel,
2846 struct vnode *vp, struct label *vplabel)
2848 struct mac_biba *source, *dest;
2850 source = SLOT(mplabel);
2851 dest = SLOT(vplabel);
2853 biba_copy_effective(source, dest);
2857 biba_vnode_check_chdir(struct ucred *cred, struct vnode *dvp,
2858 struct label *dvplabel)
2860 struct mac_biba *subj, *obj;
2865 subj = SLOT(cred->cr_label);
2866 obj = SLOT(dvplabel);
2868 if (!biba_dominate_effective(obj, subj))
2875 biba_vnode_check_chroot(struct ucred *cred, struct vnode *dvp,
2876 struct label *dvplabel)
2878 struct mac_biba *subj, *obj;
2883 subj = SLOT(cred->cr_label);
2884 obj = SLOT(dvplabel);
2886 if (!biba_dominate_effective(obj, subj))
2893 biba_vnode_check_create(struct ucred *cred, struct vnode *dvp,
2894 struct label *dvplabel, struct componentname *cnp, struct vattr *vap)
2896 struct mac_biba *subj, *obj;
2901 subj = SLOT(cred->cr_label);
2902 obj = SLOT(dvplabel);
2904 if (!biba_dominate_effective(subj, obj))
2911 biba_vnode_check_deleteacl(struct ucred *cred, struct vnode *vp,
2912 struct label *vplabel, acl_type_t type)
2914 struct mac_biba *subj, *obj;
2919 subj = SLOT(cred->cr_label);
2920 obj = SLOT(vplabel);
2922 if (!biba_dominate_effective(subj, obj))
2929 biba_vnode_check_deleteextattr(struct ucred *cred, struct vnode *vp,
2930 struct label *vplabel, int attrnamespace, const char *name)
2932 struct mac_biba *subj, *obj;
2937 subj = SLOT(cred->cr_label);
2938 obj = SLOT(vplabel);
2940 if (!biba_dominate_effective(subj, obj))
2947 biba_vnode_check_exec(struct ucred *cred, struct vnode *vp,
2948 struct label *vplabel, struct image_params *imgp,
2949 struct label *execlabel)
2951 struct mac_biba *subj, *obj, *exec;
2954 if (execlabel != NULL) {
2956 * We currently don't permit labels to be changed at
2957 * exec-time as part of Biba, so disallow non-NULL Biba label
2958 * elements in the execlabel.
2960 exec = SLOT(execlabel);
2961 error = biba_atmostflags(exec, 0);
2969 subj = SLOT(cred->cr_label);
2970 obj = SLOT(vplabel);
2972 if (!biba_dominate_effective(obj, subj))
2979 biba_vnode_check_getacl(struct ucred *cred, struct vnode *vp,
2980 struct label *vplabel, acl_type_t type)
2982 struct mac_biba *subj, *obj;
2987 subj = SLOT(cred->cr_label);
2988 obj = SLOT(vplabel);
2990 if (!biba_dominate_effective(obj, subj))
2997 biba_vnode_check_getextattr(struct ucred *cred, struct vnode *vp,
2998 struct label *vplabel, int attrnamespace, const char *name)
3000 struct mac_biba *subj, *obj;
3005 subj = SLOT(cred->cr_label);
3006 obj = SLOT(vplabel);
3008 if (!biba_dominate_effective(obj, subj))
3015 biba_vnode_check_link(struct ucred *cred, struct vnode *dvp,
3016 struct label *dvplabel, struct vnode *vp, struct label *vplabel,
3017 struct componentname *cnp)
3019 struct mac_biba *subj, *obj;
3024 subj = SLOT(cred->cr_label);
3025 obj = SLOT(dvplabel);
3027 if (!biba_dominate_effective(subj, obj))
3030 obj = SLOT(vplabel);
3032 if (!biba_dominate_effective(subj, obj))
3039 biba_vnode_check_listextattr(struct ucred *cred, struct vnode *vp,
3040 struct label *vplabel, int attrnamespace)
3042 struct mac_biba *subj, *obj;
3047 subj = SLOT(cred->cr_label);
3048 obj = SLOT(vplabel);
3050 if (!biba_dominate_effective(obj, subj))
3057 biba_vnode_check_lookup(struct ucred *cred, struct vnode *dvp,
3058 struct label *dvplabel, struct componentname *cnp)
3060 struct mac_biba *subj, *obj;
3065 subj = SLOT(cred->cr_label);
3066 obj = SLOT(dvplabel);
3068 if (!biba_dominate_effective(obj, subj))
3075 biba_vnode_check_mmap(struct ucred *cred, struct vnode *vp,
3076 struct label *vplabel, int prot, int flags)
3078 struct mac_biba *subj, *obj;
3081 * Rely on the use of open()-time protections to handle
3082 * non-revocation cases.
3084 if (!biba_enabled || !revocation_enabled)
3087 subj = SLOT(cred->cr_label);
3088 obj = SLOT(vplabel);
3090 if (prot & (VM_PROT_READ | VM_PROT_EXECUTE)) {
3091 if (!biba_dominate_effective(obj, subj))
3094 if (((prot & VM_PROT_WRITE) != 0) && ((flags & MAP_SHARED) != 0)) {
3095 if (!biba_dominate_effective(subj, obj))
3103 biba_vnode_check_open(struct ucred *cred, struct vnode *vp,
3104 struct label *vplabel, accmode_t accmode)
3106 struct mac_biba *subj, *obj;
3111 subj = SLOT(cred->cr_label);
3112 obj = SLOT(vplabel);
3114 /* XXX privilege override for admin? */
3115 if (accmode & (VREAD | VEXEC | VSTAT_PERMS)) {
3116 if (!biba_dominate_effective(obj, subj))
3119 if (accmode & VMODIFY_PERMS) {
3120 if (!biba_dominate_effective(subj, obj))
3128 biba_vnode_check_poll(struct ucred *active_cred, struct ucred *file_cred,
3129 struct vnode *vp, struct label *vplabel)
3131 struct mac_biba *subj, *obj;
3133 if (!biba_enabled || !revocation_enabled)
3136 subj = SLOT(active_cred->cr_label);
3137 obj = SLOT(vplabel);
3139 if (!biba_dominate_effective(obj, subj))
3146 biba_vnode_check_read(struct ucred *active_cred, struct ucred *file_cred,
3147 struct vnode *vp, struct label *vplabel)
3149 struct mac_biba *subj, *obj;
3151 if (!biba_enabled || !revocation_enabled)
3154 subj = SLOT(active_cred->cr_label);
3155 obj = SLOT(vplabel);
3157 if (!biba_dominate_effective(obj, subj))
3164 biba_vnode_check_readdir(struct ucred *cred, struct vnode *dvp,
3165 struct label *dvplabel)
3167 struct mac_biba *subj, *obj;
3172 subj = SLOT(cred->cr_label);
3173 obj = SLOT(dvplabel);
3175 if (!biba_dominate_effective(obj, subj))
3182 biba_vnode_check_readlink(struct ucred *cred, struct vnode *vp,
3183 struct label *vplabel)
3185 struct mac_biba *subj, *obj;
3190 subj = SLOT(cred->cr_label);
3191 obj = SLOT(vplabel);
3193 if (!biba_dominate_effective(obj, subj))
3200 biba_vnode_check_relabel(struct ucred *cred, struct vnode *vp,
3201 struct label *vplabel, struct label *newlabel)
3203 struct mac_biba *old, *new, *subj;
3206 old = SLOT(vplabel);
3207 new = SLOT(newlabel);
3208 subj = SLOT(cred->cr_label);
3211 * If there is a Biba label update for the vnode, it must be a
3214 error = biba_atmostflags(new, MAC_BIBA_FLAG_EFFECTIVE);
3219 * To perform a relabel of the vnode (Biba label or not), Biba must
3220 * authorize the relabel.
3222 if (!biba_effective_in_range(old, subj))
3226 * If the Biba label is to be changed, authorize as appropriate.
3228 if (new->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) {
3230 * To change the Biba label on a vnode, the new vnode label
3231 * must be in the subject range.
3233 if (!biba_effective_in_range(new, subj))
3237 * To change the Biba label on the vnode to be EQUAL, the
3238 * subject must have appropriate privilege.
3240 if (biba_contains_equal(new)) {
3241 error = biba_subject_privileged(subj);
3251 biba_vnode_check_rename_from(struct ucred *cred, struct vnode *dvp,
3252 struct label *dvplabel, struct vnode *vp, struct label *vplabel,
3253 struct componentname *cnp)
3255 struct mac_biba *subj, *obj;
3260 subj = SLOT(cred->cr_label);
3261 obj = SLOT(dvplabel);
3263 if (!biba_dominate_effective(subj, obj))
3266 obj = SLOT(vplabel);
3268 if (!biba_dominate_effective(subj, obj))
3275 biba_vnode_check_rename_to(struct ucred *cred, struct vnode *dvp,
3276 struct label *dvplabel, struct vnode *vp, struct label *vplabel,
3277 int samedir, struct componentname *cnp)
3279 struct mac_biba *subj, *obj;
3284 subj = SLOT(cred->cr_label);
3285 obj = SLOT(dvplabel);
3287 if (!biba_dominate_effective(subj, obj))
3291 obj = SLOT(vplabel);
3293 if (!biba_dominate_effective(subj, obj))
3301 biba_vnode_check_revoke(struct ucred *cred, struct vnode *vp,
3302 struct label *vplabel)
3304 struct mac_biba *subj, *obj;
3309 subj = SLOT(cred->cr_label);
3310 obj = SLOT(vplabel);
3312 if (!biba_dominate_effective(subj, obj))
3319 biba_vnode_check_setacl(struct ucred *cred, struct vnode *vp,
3320 struct label *vplabel, acl_type_t type, struct acl *acl)
3322 struct mac_biba *subj, *obj;
3327 subj = SLOT(cred->cr_label);
3328 obj = SLOT(vplabel);
3330 if (!biba_dominate_effective(subj, obj))
3337 biba_vnode_check_setextattr(struct ucred *cred, struct vnode *vp,
3338 struct label *vplabel, int attrnamespace, const char *name)
3340 struct mac_biba *subj, *obj;
3345 subj = SLOT(cred->cr_label);
3346 obj = SLOT(vplabel);
3348 if (!biba_dominate_effective(subj, obj))
3351 /* XXX: protect the MAC EA in a special way? */
3357 biba_vnode_check_setflags(struct ucred *cred, struct vnode *vp,
3358 struct label *vplabel, u_long flags)
3360 struct mac_biba *subj, *obj;
3365 subj = SLOT(cred->cr_label);
3366 obj = SLOT(vplabel);
3368 if (!biba_dominate_effective(subj, obj))
3375 biba_vnode_check_setmode(struct ucred *cred, struct vnode *vp,
3376 struct label *vplabel, mode_t mode)
3378 struct mac_biba *subj, *obj;
3383 subj = SLOT(cred->cr_label);
3384 obj = SLOT(vplabel);
3386 if (!biba_dominate_effective(subj, obj))
3393 biba_vnode_check_setowner(struct ucred *cred, struct vnode *vp,
3394 struct label *vplabel, uid_t uid, gid_t gid)
3396 struct mac_biba *subj, *obj;
3401 subj = SLOT(cred->cr_label);
3402 obj = SLOT(vplabel);
3404 if (!biba_dominate_effective(subj, obj))
3411 biba_vnode_check_setutimes(struct ucred *cred, struct vnode *vp,
3412 struct label *vplabel, struct timespec atime, struct timespec mtime)
3414 struct mac_biba *subj, *obj;
3419 subj = SLOT(cred->cr_label);
3420 obj = SLOT(vplabel);
3422 if (!biba_dominate_effective(subj, obj))
3429 biba_vnode_check_stat(struct ucred *active_cred, struct ucred *file_cred,
3430 struct vnode *vp, struct label *vplabel)
3432 struct mac_biba *subj, *obj;
3437 subj = SLOT(active_cred->cr_label);
3438 obj = SLOT(vplabel);
3440 if (!biba_dominate_effective(obj, subj))
3447 biba_vnode_check_unlink(struct ucred *cred, struct vnode *dvp,
3448 struct label *dvplabel, struct vnode *vp, struct label *vplabel,
3449 struct componentname *cnp)
3451 struct mac_biba *subj, *obj;
3456 subj = SLOT(cred->cr_label);
3457 obj = SLOT(dvplabel);
3459 if (!biba_dominate_effective(subj, obj))
3462 obj = SLOT(vplabel);
3464 if (!biba_dominate_effective(subj, obj))
3471 biba_vnode_check_write(struct ucred *active_cred,
3472 struct ucred *file_cred, struct vnode *vp, struct label *vplabel)
3474 struct mac_biba *subj, *obj;
3476 if (!biba_enabled || !revocation_enabled)
3479 subj = SLOT(active_cred->cr_label);
3480 obj = SLOT(vplabel);
3482 if (!biba_dominate_effective(subj, obj))
3489 biba_vnode_create_extattr(struct ucred *cred, struct mount *mp,
3490 struct label *mplabel, struct vnode *dvp, struct label *dvplabel,
3491 struct vnode *vp, struct label *vplabel, struct componentname *cnp)
3493 struct mac_biba *source, *dest, mb_temp;
3497 buflen = sizeof(mb_temp);
3498 bzero(&mb_temp, buflen);
3500 source = SLOT(cred->cr_label);
3501 dest = SLOT(vplabel);
3502 biba_copy_effective(source, &mb_temp);
3504 error = vn_extattr_set(vp, IO_NODELOCKED, MAC_BIBA_EXTATTR_NAMESPACE,
3505 MAC_BIBA_EXTATTR_NAME, buflen, (char *) &mb_temp, curthread);
3507 biba_copy_effective(source, dest);
3512 biba_vnode_relabel(struct ucred *cred, struct vnode *vp,
3513 struct label *vplabel, struct label *newlabel)
3515 struct mac_biba *source, *dest;
3517 source = SLOT(newlabel);
3518 dest = SLOT(vplabel);
3520 biba_copy(source, dest);
3524 biba_vnode_setlabel_extattr(struct ucred *cred, struct vnode *vp,
3525 struct label *vplabel, struct label *intlabel)
3527 struct mac_biba *source, mb_temp;
3531 buflen = sizeof(mb_temp);
3532 bzero(&mb_temp, buflen);
3534 source = SLOT(intlabel);
3535 if ((source->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) == 0)
3538 biba_copy_effective(source, &mb_temp);
3540 error = vn_extattr_set(vp, IO_NODELOCKED, MAC_BIBA_EXTATTR_NAMESPACE,
3541 MAC_BIBA_EXTATTR_NAME, buflen, (char *) &mb_temp, curthread);
3545 static struct mac_policy_ops mac_biba_ops =
3547 .mpo_init = biba_init,
3549 .mpo_bpfdesc_check_receive = biba_bpfdesc_check_receive,
3550 .mpo_bpfdesc_create = biba_bpfdesc_create,
3551 .mpo_bpfdesc_create_mbuf = biba_bpfdesc_create_mbuf,
3552 .mpo_bpfdesc_destroy_label = biba_destroy_label,
3553 .mpo_bpfdesc_init_label = biba_init_label,
3555 .mpo_cred_associate_nfsd = biba_cred_associate_nfsd,
3556 .mpo_cred_check_relabel = biba_cred_check_relabel,
3557 .mpo_cred_check_visible = biba_cred_check_visible,
3558 .mpo_cred_copy_label = biba_copy_label,
3559 .mpo_cred_create_init = biba_cred_create_init,
3560 .mpo_cred_create_swapper = biba_cred_create_swapper,
3561 .mpo_cred_destroy_label = biba_destroy_label,
3562 .mpo_cred_externalize_label = biba_externalize_label,
3563 .mpo_cred_init_label = biba_init_label,
3564 .mpo_cred_internalize_label = biba_internalize_label,
3565 .mpo_cred_relabel = biba_cred_relabel,
3567 .mpo_devfs_create_device = biba_devfs_create_device,
3568 .mpo_devfs_create_directory = biba_devfs_create_directory,
3569 .mpo_devfs_create_symlink = biba_devfs_create_symlink,
3570 .mpo_devfs_destroy_label = biba_destroy_label,
3571 .mpo_devfs_init_label = biba_init_label,
3572 .mpo_devfs_update = biba_devfs_update,
3573 .mpo_devfs_vnode_associate = biba_devfs_vnode_associate,
3575 .mpo_ifnet_check_relabel = biba_ifnet_check_relabel,
3576 .mpo_ifnet_check_transmit = biba_ifnet_check_transmit,
3577 .mpo_ifnet_copy_label = biba_copy_label,
3578 .mpo_ifnet_create = biba_ifnet_create,
3579 .mpo_ifnet_create_mbuf = biba_ifnet_create_mbuf,
3580 .mpo_ifnet_destroy_label = biba_destroy_label,
3581 .mpo_ifnet_externalize_label = biba_externalize_label,
3582 .mpo_ifnet_init_label = biba_init_label,
3583 .mpo_ifnet_internalize_label = biba_internalize_label,
3584 .mpo_ifnet_relabel = biba_ifnet_relabel,
3586 .mpo_inpcb_check_deliver = biba_inpcb_check_deliver,
3587 .mpo_inpcb_check_visible = biba_inpcb_check_visible,
3588 .mpo_inpcb_create = biba_inpcb_create,
3589 .mpo_inpcb_create_mbuf = biba_inpcb_create_mbuf,
3590 .mpo_inpcb_destroy_label = biba_destroy_label,
3591 .mpo_inpcb_init_label = biba_init_label_waitcheck,
3592 .mpo_inpcb_sosetlabel = biba_inpcb_sosetlabel,
3594 .mpo_ip6q_create = biba_ip6q_create,
3595 .mpo_ip6q_destroy_label = biba_destroy_label,
3596 .mpo_ip6q_init_label = biba_init_label_waitcheck,
3597 .mpo_ip6q_match = biba_ip6q_match,
3598 .mpo_ip6q_reassemble = biba_ip6q_reassemble,
3599 .mpo_ip6q_update = biba_ip6q_update,
3601 .mpo_ipq_create = biba_ipq_create,
3602 .mpo_ipq_destroy_label = biba_destroy_label,
3603 .mpo_ipq_init_label = biba_init_label_waitcheck,
3604 .mpo_ipq_match = biba_ipq_match,
3605 .mpo_ipq_reassemble = biba_ipq_reassemble,
3606 .mpo_ipq_update = biba_ipq_update,
3608 .mpo_kld_check_load = biba_kld_check_load,
3610 .mpo_mbuf_copy_label = biba_copy_label,
3611 .mpo_mbuf_destroy_label = biba_destroy_label,
3612 .mpo_mbuf_init_label = biba_init_label_waitcheck,
3614 .mpo_mount_check_stat = biba_mount_check_stat,
3615 .mpo_mount_create = biba_mount_create,
3616 .mpo_mount_destroy_label = biba_destroy_label,
3617 .mpo_mount_init_label = biba_init_label,
3619 .mpo_netatalk_aarp_send = biba_netatalk_aarp_send,
3621 .mpo_netinet_arp_send = biba_netinet_arp_send,
3622 .mpo_netinet_firewall_reply = biba_netinet_firewall_reply,
3623 .mpo_netinet_firewall_send = biba_netinet_firewall_send,
3624 .mpo_netinet_fragment = biba_netinet_fragment,
3625 .mpo_netinet_icmp_reply = biba_netinet_icmp_reply,
3626 .mpo_netinet_igmp_send = biba_netinet_igmp_send,
3628 .mpo_netinet6_nd6_send = biba_netinet6_nd6_send,
3630 .mpo_pipe_check_ioctl = biba_pipe_check_ioctl,
3631 .mpo_pipe_check_poll = biba_pipe_check_poll,
3632 .mpo_pipe_check_read = biba_pipe_check_read,
3633 .mpo_pipe_check_relabel = biba_pipe_check_relabel,
3634 .mpo_pipe_check_stat = biba_pipe_check_stat,
3635 .mpo_pipe_check_write = biba_pipe_check_write,
3636 .mpo_pipe_copy_label = biba_copy_label,
3637 .mpo_pipe_create = biba_pipe_create,
3638 .mpo_pipe_destroy_label = biba_destroy_label,
3639 .mpo_pipe_externalize_label = biba_externalize_label,
3640 .mpo_pipe_init_label = biba_init_label,
3641 .mpo_pipe_internalize_label = biba_internalize_label,
3642 .mpo_pipe_relabel = biba_pipe_relabel,
3644 .mpo_posixsem_check_getvalue = biba_posixsem_check_rdonly,
3645 .mpo_posixsem_check_open = biba_posixsem_check_openunlink,
3646 .mpo_posixsem_check_post = biba_posixsem_check_write,
3647 .mpo_posixsem_check_setmode = biba_posixsem_check_setmode,
3648 .mpo_posixsem_check_setowner = biba_posixsem_check_setowner,
3649 .mpo_posixsem_check_stat = biba_posixsem_check_rdonly,
3650 .mpo_posixsem_check_unlink = biba_posixsem_check_openunlink,
3651 .mpo_posixsem_check_wait = biba_posixsem_check_write,
3652 .mpo_posixsem_create = biba_posixsem_create,
3653 .mpo_posixsem_destroy_label = biba_destroy_label,
3654 .mpo_posixsem_init_label = biba_init_label,
3656 .mpo_posixshm_check_mmap = biba_posixshm_check_mmap,
3657 .mpo_posixshm_check_open = biba_posixshm_check_open,
3658 .mpo_posixshm_check_setmode = biba_posixshm_check_setmode,
3659 .mpo_posixshm_check_setowner = biba_posixshm_check_setowner,
3660 .mpo_posixshm_check_stat = biba_posixshm_check_stat,
3661 .mpo_posixshm_check_truncate = biba_posixshm_check_truncate,
3662 .mpo_posixshm_check_unlink = biba_posixshm_check_unlink,
3663 .mpo_posixshm_create = biba_posixshm_create,
3664 .mpo_posixshm_destroy_label = biba_destroy_label,
3665 .mpo_posixshm_init_label = biba_init_label,
3667 .mpo_priv_check = biba_priv_check,
3669 .mpo_proc_check_debug = biba_proc_check_debug,
3670 .mpo_proc_check_sched = biba_proc_check_sched,
3671 .mpo_proc_check_signal = biba_proc_check_signal,
3673 .mpo_socket_check_deliver = biba_socket_check_deliver,
3674 .mpo_socket_check_relabel = biba_socket_check_relabel,
3675 .mpo_socket_check_visible = biba_socket_check_visible,
3676 .mpo_socket_copy_label = biba_copy_label,
3677 .mpo_socket_create = biba_socket_create,
3678 .mpo_socket_create_mbuf = biba_socket_create_mbuf,
3679 .mpo_socket_destroy_label = biba_destroy_label,
3680 .mpo_socket_externalize_label = biba_externalize_label,
3681 .mpo_socket_init_label = biba_init_label_waitcheck,
3682 .mpo_socket_internalize_label = biba_internalize_label,
3683 .mpo_socket_newconn = biba_socket_newconn,
3684 .mpo_socket_relabel = biba_socket_relabel,
3686 .mpo_socketpeer_destroy_label = biba_destroy_label,
3687 .mpo_socketpeer_externalize_label = biba_externalize_label,
3688 .mpo_socketpeer_init_label = biba_init_label_waitcheck,
3689 .mpo_socketpeer_set_from_mbuf = biba_socketpeer_set_from_mbuf,
3690 .mpo_socketpeer_set_from_socket = biba_socketpeer_set_from_socket,
3692 .mpo_syncache_create = biba_syncache_create,
3693 .mpo_syncache_create_mbuf = biba_syncache_create_mbuf,
3694 .mpo_syncache_destroy_label = biba_destroy_label,
3695 .mpo_syncache_init_label = biba_init_label_waitcheck,
3697 .mpo_system_check_acct = biba_system_check_acct,
3698 .mpo_system_check_auditctl = biba_system_check_auditctl,
3699 .mpo_system_check_auditon = biba_system_check_auditon,
3700 .mpo_system_check_swapoff = biba_system_check_swapoff,
3701 .mpo_system_check_swapon = biba_system_check_swapon,
3702 .mpo_system_check_sysctl = biba_system_check_sysctl,
3704 .mpo_sysvmsg_cleanup = biba_sysvmsg_cleanup,
3705 .mpo_sysvmsg_create = biba_sysvmsg_create,
3706 .mpo_sysvmsg_destroy_label = biba_destroy_label,
3707 .mpo_sysvmsg_init_label = biba_init_label,
3709 .mpo_sysvmsq_check_msgrcv = biba_sysvmsq_check_msgrcv,
3710 .mpo_sysvmsq_check_msgrmid = biba_sysvmsq_check_msgrmid,
3711 .mpo_sysvmsq_check_msqget = biba_sysvmsq_check_msqget,
3712 .mpo_sysvmsq_check_msqsnd = biba_sysvmsq_check_msqsnd,
3713 .mpo_sysvmsq_check_msqrcv = biba_sysvmsq_check_msqrcv,
3714 .mpo_sysvmsq_check_msqctl = biba_sysvmsq_check_msqctl,
3715 .mpo_sysvmsq_cleanup = biba_sysvmsq_cleanup,
3716 .mpo_sysvmsq_create = biba_sysvmsq_create,
3717 .mpo_sysvmsq_destroy_label = biba_destroy_label,
3718 .mpo_sysvmsq_init_label = biba_init_label,
3720 .mpo_sysvsem_check_semctl = biba_sysvsem_check_semctl,
3721 .mpo_sysvsem_check_semget = biba_sysvsem_check_semget,
3722 .mpo_sysvsem_check_semop = biba_sysvsem_check_semop,
3723 .mpo_sysvsem_cleanup = biba_sysvsem_cleanup,
3724 .mpo_sysvsem_create = biba_sysvsem_create,
3725 .mpo_sysvsem_destroy_label = biba_destroy_label,
3726 .mpo_sysvsem_init_label = biba_init_label,
3728 .mpo_sysvshm_check_shmat = biba_sysvshm_check_shmat,
3729 .mpo_sysvshm_check_shmctl = biba_sysvshm_check_shmctl,
3730 .mpo_sysvshm_check_shmget = biba_sysvshm_check_shmget,
3731 .mpo_sysvshm_cleanup = biba_sysvshm_cleanup,
3732 .mpo_sysvshm_create = biba_sysvshm_create,
3733 .mpo_sysvshm_destroy_label = biba_destroy_label,
3734 .mpo_sysvshm_init_label = biba_init_label,
3736 .mpo_vnode_associate_extattr = biba_vnode_associate_extattr,
3737 .mpo_vnode_associate_singlelabel = biba_vnode_associate_singlelabel,
3738 .mpo_vnode_check_access = biba_vnode_check_open,
3739 .mpo_vnode_check_chdir = biba_vnode_check_chdir,
3740 .mpo_vnode_check_chroot = biba_vnode_check_chroot,
3741 .mpo_vnode_check_create = biba_vnode_check_create,
3742 .mpo_vnode_check_deleteacl = biba_vnode_check_deleteacl,
3743 .mpo_vnode_check_deleteextattr = biba_vnode_check_deleteextattr,
3744 .mpo_vnode_check_exec = biba_vnode_check_exec,
3745 .mpo_vnode_check_getacl = biba_vnode_check_getacl,
3746 .mpo_vnode_check_getextattr = biba_vnode_check_getextattr,
3747 .mpo_vnode_check_link = biba_vnode_check_link,
3748 .mpo_vnode_check_listextattr = biba_vnode_check_listextattr,
3749 .mpo_vnode_check_lookup = biba_vnode_check_lookup,
3750 .mpo_vnode_check_mmap = biba_vnode_check_mmap,
3751 .mpo_vnode_check_open = biba_vnode_check_open,
3752 .mpo_vnode_check_poll = biba_vnode_check_poll,
3753 .mpo_vnode_check_read = biba_vnode_check_read,
3754 .mpo_vnode_check_readdir = biba_vnode_check_readdir,
3755 .mpo_vnode_check_readlink = biba_vnode_check_readlink,
3756 .mpo_vnode_check_relabel = biba_vnode_check_relabel,
3757 .mpo_vnode_check_rename_from = biba_vnode_check_rename_from,
3758 .mpo_vnode_check_rename_to = biba_vnode_check_rename_to,
3759 .mpo_vnode_check_revoke = biba_vnode_check_revoke,
3760 .mpo_vnode_check_setacl = biba_vnode_check_setacl,
3761 .mpo_vnode_check_setextattr = biba_vnode_check_setextattr,
3762 .mpo_vnode_check_setflags = biba_vnode_check_setflags,
3763 .mpo_vnode_check_setmode = biba_vnode_check_setmode,
3764 .mpo_vnode_check_setowner = biba_vnode_check_setowner,
3765 .mpo_vnode_check_setutimes = biba_vnode_check_setutimes,
3766 .mpo_vnode_check_stat = biba_vnode_check_stat,
3767 .mpo_vnode_check_unlink = biba_vnode_check_unlink,
3768 .mpo_vnode_check_write = biba_vnode_check_write,
3769 .mpo_vnode_create_extattr = biba_vnode_create_extattr,
3770 .mpo_vnode_copy_label = biba_copy_label,
3771 .mpo_vnode_destroy_label = biba_destroy_label,
3772 .mpo_vnode_externalize_label = biba_externalize_label,
3773 .mpo_vnode_init_label = biba_init_label,
3774 .mpo_vnode_internalize_label = biba_internalize_label,
3775 .mpo_vnode_relabel = biba_vnode_relabel,
3776 .mpo_vnode_setlabel_extattr = biba_vnode_setlabel_extattr,
3779 MAC_POLICY_SET(&mac_biba_ops, mac_biba, "TrustedBSD MAC/Biba",
3780 MPC_LOADTIME_FLAG_NOTLATE, &biba_slot);