mac_biba.c revision 168954
1101099Srwatson/*- 2166533Srwatson * Copyright (c) 1999-2002, 2007 Robert N. M. Watson 3140628Srwatson * Copyright (c) 2001-2005 McAfee, Inc. 4101099Srwatson * All rights reserved. 5101099Srwatson * 6101099Srwatson * This software was developed by Robert Watson for the TrustedBSD Project. 7101099Srwatson * 8140628Srwatson * This software was developed for the FreeBSD Project in part by McAfee 9140628Srwatson * Research, the Security Research Division of McAfee, Inc. under 10140628Srwatson * DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA 11140628Srwatson * CHATS research program. 12101099Srwatson * 13101099Srwatson * Redistribution and use in source and binary forms, with or without 14101099Srwatson * modification, are permitted provided that the following conditions 15101099Srwatson * are met: 16101099Srwatson * 1. Redistributions of source code must retain the above copyright 17101099Srwatson * notice, this list of conditions and the following disclaimer. 18101099Srwatson * 2. Redistributions in binary form must reproduce the above copyright 19101099Srwatson * notice, this list of conditions and the following disclaimer in the 20101099Srwatson * documentation and/or other materials provided with the distribution. 21101099Srwatson * 22101099Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 23101099Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24101099Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25101099Srwatson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 26101099Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27101099Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28101099Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29101099Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30101099Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31101099Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32101099Srwatson * SUCH DAMAGE. 33101099Srwatson * 34101099Srwatson * $FreeBSD: head/sys/security/mac_biba/mac_biba.c 168954 2007-04-22 16:18:10Z rwatson $ 35101099Srwatson */ 36101099Srwatson 37101099Srwatson/* 38101099Srwatson * Developed by the TrustedBSD Project. 39168951Srwatson * 40101099Srwatson * Biba fixed label mandatory integrity policy. 41101099Srwatson */ 42101099Srwatson 43101099Srwatson#include <sys/param.h> 44101099Srwatson#include <sys/conf.h> 45105988Srwatson#include <sys/extattr.h> 46101099Srwatson#include <sys/kernel.h> 47164184Strhodes#include <sys/ksem.h> 48103183Sbde#include <sys/malloc.h> 49145076Scsjp#include <sys/mman.h> 50101099Srwatson#include <sys/mount.h> 51168951Srwatson#include <sys/priv.h> 52101099Srwatson#include <sys/proc.h> 53115497Srwatson#include <sys/sbuf.h> 54101099Srwatson#include <sys/systm.h> 55101099Srwatson#include <sys/sysproto.h> 56101099Srwatson#include <sys/sysent.h> 57105696Srwatson#include <sys/systm.h> 58101099Srwatson#include <sys/vnode.h> 59101099Srwatson#include <sys/file.h> 60101099Srwatson#include <sys/socket.h> 61101099Srwatson#include <sys/socketvar.h> 62101099Srwatson#include <sys/pipe.h> 63150340Sphk#include <sys/sx.h> 64101099Srwatson#include <sys/sysctl.h> 65140628Srwatson#include <sys/msg.h> 66140628Srwatson#include <sys/sem.h> 67140628Srwatson#include <sys/shm.h> 68101099Srwatson 69101099Srwatson#include <fs/devfs/devfs.h> 70101099Srwatson 71101099Srwatson#include <net/bpfdesc.h> 72101099Srwatson#include <net/if.h> 73101099Srwatson#include <net/if_types.h> 74101099Srwatson#include <net/if_var.h> 75101099Srwatson 76101099Srwatson#include <netinet/in.h> 77122875Srwatson#include <netinet/in_pcb.h> 78101099Srwatson#include <netinet/ip_var.h> 79101099Srwatson 80122879Srwatson#include <vm/uma.h> 81101099Srwatson#include <vm/vm.h> 82101099Srwatson 83165469Srwatson#include <security/mac/mac_policy.h> 84101099Srwatson#include <security/mac_biba/mac_biba.h> 85101099Srwatson 86101099SrwatsonSYSCTL_DECL(_security_mac); 87101099Srwatson 88101099SrwatsonSYSCTL_NODE(_security_mac, OID_AUTO, biba, CTLFLAG_RW, 0, 89101099Srwatson "TrustedBSD mac_biba policy controls"); 90101099Srwatson 91105988Srwatsonstatic int mac_biba_label_size = sizeof(struct mac_biba); 92105988SrwatsonSYSCTL_INT(_security_mac_biba, OID_AUTO, label_size, CTLFLAG_RD, 93105988Srwatson &mac_biba_label_size, 0, "Size of struct mac_biba"); 94105988Srwatson 95107731Srwatsonstatic int mac_biba_enabled = 1; 96101099SrwatsonSYSCTL_INT(_security_mac_biba, OID_AUTO, enabled, CTLFLAG_RW, 97101099Srwatson &mac_biba_enabled, 0, "Enforce MAC/Biba policy"); 98102980SrwatsonTUNABLE_INT("security.mac.biba.enabled", &mac_biba_enabled); 99101099Srwatson 100101099Srwatsonstatic int destroyed_not_inited; 101101099SrwatsonSYSCTL_INT(_security_mac_biba, OID_AUTO, destroyed_not_inited, CTLFLAG_RD, 102101099Srwatson &destroyed_not_inited, 0, "Count of labels destroyed but not inited"); 103101099Srwatson 104101099Srwatsonstatic int trust_all_interfaces = 0; 105101099SrwatsonSYSCTL_INT(_security_mac_biba, OID_AUTO, trust_all_interfaces, CTLFLAG_RD, 106101099Srwatson &trust_all_interfaces, 0, "Consider all interfaces 'trusted' by MAC/Biba"); 107101099SrwatsonTUNABLE_INT("security.mac.biba.trust_all_interfaces", &trust_all_interfaces); 108101099Srwatson 109101099Srwatsonstatic char trusted_interfaces[128]; 110101099SrwatsonSYSCTL_STRING(_security_mac_biba, OID_AUTO, trusted_interfaces, CTLFLAG_RD, 111101099Srwatson trusted_interfaces, 0, "Interfaces considered 'trusted' by MAC/Biba"); 112101099SrwatsonTUNABLE_STR("security.mac.biba.trusted_interfaces", trusted_interfaces, 113101099Srwatson sizeof(trusted_interfaces)); 114101099Srwatson 115105643Srwatsonstatic int max_compartments = MAC_BIBA_MAX_COMPARTMENTS; 116105643SrwatsonSYSCTL_INT(_security_mac_biba, OID_AUTO, max_compartments, CTLFLAG_RD, 117105643Srwatson &max_compartments, 0, "Maximum supported compartments"); 118105643Srwatson 119105606Srwatsonstatic int ptys_equal = 0; 120105606SrwatsonSYSCTL_INT(_security_mac_biba, OID_AUTO, ptys_equal, CTLFLAG_RW, 121105606Srwatson &ptys_equal, 0, "Label pty devices as biba/equal on create"); 122105606SrwatsonTUNABLE_INT("security.mac.biba.ptys_equal", &ptys_equal); 123105606Srwatson 124153927Scsjpstatic int interfaces_equal; 125153927ScsjpSYSCTL_INT(_security_mac_biba, OID_AUTO, interfaces_equal, CTLFLAG_RW, 126153927Scsjp &interfaces_equal, 0, "Label network interfaces as biba/equal on create"); 127153927ScsjpTUNABLE_INT("security.mac.biba.interfaces_equal", &interfaces_equal); 128153927Scsjp 129105637Srwatsonstatic int revocation_enabled = 0; 130101099SrwatsonSYSCTL_INT(_security_mac_biba, OID_AUTO, revocation_enabled, CTLFLAG_RW, 131105637Srwatson &revocation_enabled, 0, "Revoke access to objects on relabel"); 132105637SrwatsonTUNABLE_INT("security.mac.biba.revocation_enabled", &revocation_enabled); 133101099Srwatson 134101099Srwatsonstatic int mac_biba_slot; 135166533Srwatson#define SLOT(l) ((struct mac_biba *)mac_label_get((l), mac_biba_slot)) 136166533Srwatson#define SLOT_SET(l, val) mac_label_set((l), mac_biba_slot, (uintptr_t)(val)) 137101099Srwatson 138122879Srwatsonstatic uma_zone_t zone_biba; 139101099Srwatson 140105643Srwatsonstatic __inline int 141105643Srwatsonbiba_bit_set_empty(u_char *set) { 142105643Srwatson int i; 143105643Srwatson 144105643Srwatson for (i = 0; i < MAC_BIBA_MAX_COMPARTMENTS >> 3; i++) 145105643Srwatson if (set[i] != 0) 146105643Srwatson return (0); 147105643Srwatson return (1); 148105643Srwatson} 149105643Srwatson 150101099Srwatsonstatic struct mac_biba * 151104514Srwatsonbiba_alloc(int flag) 152101099Srwatson{ 153101099Srwatson 154122879Srwatson return (uma_zalloc(zone_biba, flag | M_ZERO)); 155101099Srwatson} 156101099Srwatson 157101099Srwatsonstatic void 158101099Srwatsonbiba_free(struct mac_biba *mac_biba) 159101099Srwatson{ 160101099Srwatson 161101099Srwatson if (mac_biba != NULL) 162122879Srwatson uma_zfree(zone_biba, mac_biba); 163101099Srwatson else 164101099Srwatson atomic_add_int(&destroyed_not_inited, 1); 165101099Srwatson} 166101099Srwatson 167101099Srwatsonstatic int 168105634Srwatsonbiba_atmostflags(struct mac_biba *mac_biba, int flags) 169105634Srwatson{ 170105634Srwatson 171105634Srwatson if ((mac_biba->mb_flags & flags) != mac_biba->mb_flags) 172105634Srwatson return (EINVAL); 173105634Srwatson return (0); 174105634Srwatson} 175105634Srwatson 176105634Srwatsonstatic int 177101099Srwatsonmac_biba_dominate_element(struct mac_biba_element *a, 178101099Srwatson struct mac_biba_element *b) 179101099Srwatson{ 180105643Srwatson int bit; 181101099Srwatson 182105736Srwatson switch (a->mbe_type) { 183101099Srwatson case MAC_BIBA_TYPE_EQUAL: 184101099Srwatson case MAC_BIBA_TYPE_HIGH: 185101099Srwatson return (1); 186101099Srwatson 187101099Srwatson case MAC_BIBA_TYPE_LOW: 188101099Srwatson switch (b->mbe_type) { 189101099Srwatson case MAC_BIBA_TYPE_GRADE: 190101099Srwatson case MAC_BIBA_TYPE_HIGH: 191101099Srwatson return (0); 192101099Srwatson 193101099Srwatson case MAC_BIBA_TYPE_EQUAL: 194101099Srwatson case MAC_BIBA_TYPE_LOW: 195101099Srwatson return (1); 196101099Srwatson 197101099Srwatson default: 198101099Srwatson panic("mac_biba_dominate_element: b->mbe_type invalid"); 199101099Srwatson } 200101099Srwatson 201101099Srwatson case MAC_BIBA_TYPE_GRADE: 202101099Srwatson switch (b->mbe_type) { 203101099Srwatson case MAC_BIBA_TYPE_EQUAL: 204101099Srwatson case MAC_BIBA_TYPE_LOW: 205101099Srwatson return (1); 206101099Srwatson 207101099Srwatson case MAC_BIBA_TYPE_HIGH: 208101099Srwatson return (0); 209101099Srwatson 210101099Srwatson case MAC_BIBA_TYPE_GRADE: 211105643Srwatson for (bit = 1; bit <= MAC_BIBA_MAX_COMPARTMENTS; bit++) 212105643Srwatson if (!MAC_BIBA_BIT_TEST(bit, 213105643Srwatson a->mbe_compartments) && 214105643Srwatson MAC_BIBA_BIT_TEST(bit, b->mbe_compartments)) 215105643Srwatson return (0); 216101099Srwatson return (a->mbe_grade >= b->mbe_grade); 217101099Srwatson 218101099Srwatson default: 219101099Srwatson panic("mac_biba_dominate_element: b->mbe_type invalid"); 220101099Srwatson } 221101099Srwatson 222101099Srwatson default: 223101099Srwatson panic("mac_biba_dominate_element: a->mbe_type invalid"); 224101099Srwatson } 225101099Srwatson 226101099Srwatson return (0); 227101099Srwatson} 228101099Srwatson 229101099Srwatsonstatic int 230105988Srwatsonmac_biba_subject_dominate_high(struct mac_biba *mac_biba) 231105988Srwatson{ 232105988Srwatson struct mac_biba_element *element; 233105988Srwatson 234132232Srwatson KASSERT((mac_biba->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) != 0, 235132232Srwatson ("mac_biba_effective_in_range: mac_biba not effective")); 236132232Srwatson element = &mac_biba->mb_effective; 237105988Srwatson 238105988Srwatson return (element->mbe_type == MAC_BIBA_TYPE_EQUAL || 239105988Srwatson element->mbe_type == MAC_BIBA_TYPE_HIGH); 240105988Srwatson} 241105988Srwatson 242105988Srwatsonstatic int 243101099Srwatsonmac_biba_range_in_range(struct mac_biba *rangea, struct mac_biba *rangeb) 244101099Srwatson{ 245101099Srwatson 246101099Srwatson return (mac_biba_dominate_element(&rangeb->mb_rangehigh, 247101099Srwatson &rangea->mb_rangehigh) && 248101099Srwatson mac_biba_dominate_element(&rangea->mb_rangelow, 249101099Srwatson &rangeb->mb_rangelow)); 250101099Srwatson} 251101099Srwatson 252101099Srwatsonstatic int 253136774Srwatsonmac_biba_effective_in_range(struct mac_biba *effective, 254136774Srwatson struct mac_biba *range) 255101099Srwatson{ 256101099Srwatson 257132232Srwatson KASSERT((effective->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) != 0, 258132232Srwatson ("mac_biba_effective_in_range: a not effective")); 259103750Srwatson KASSERT((range->mb_flags & MAC_BIBA_FLAG_RANGE) != 0, 260132232Srwatson ("mac_biba_effective_in_range: b not range")); 261101099Srwatson 262101099Srwatson return (mac_biba_dominate_element(&range->mb_rangehigh, 263132232Srwatson &effective->mb_effective) && 264132232Srwatson mac_biba_dominate_element(&effective->mb_effective, 265101099Srwatson &range->mb_rangelow)); 266101099Srwatson 267101099Srwatson return (1); 268101099Srwatson} 269101099Srwatson 270101099Srwatsonstatic int 271132232Srwatsonmac_biba_dominate_effective(struct mac_biba *a, struct mac_biba *b) 272101099Srwatson{ 273132232Srwatson KASSERT((a->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) != 0, 274132232Srwatson ("mac_biba_dominate_effective: a not effective")); 275132232Srwatson KASSERT((b->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) != 0, 276132232Srwatson ("mac_biba_dominate_effective: b not effective")); 277101099Srwatson 278132232Srwatson return (mac_biba_dominate_element(&a->mb_effective, &b->mb_effective)); 279101099Srwatson} 280101099Srwatson 281101099Srwatsonstatic int 282101099Srwatsonmac_biba_equal_element(struct mac_biba_element *a, struct mac_biba_element *b) 283101099Srwatson{ 284101099Srwatson 285101099Srwatson if (a->mbe_type == MAC_BIBA_TYPE_EQUAL || 286101099Srwatson b->mbe_type == MAC_BIBA_TYPE_EQUAL) 287101099Srwatson return (1); 288101099Srwatson 289101099Srwatson return (a->mbe_type == b->mbe_type && a->mbe_grade == b->mbe_grade); 290101099Srwatson} 291101099Srwatson 292101099Srwatsonstatic int 293132232Srwatsonmac_biba_equal_effective(struct mac_biba *a, struct mac_biba *b) 294101099Srwatson{ 295101099Srwatson 296132232Srwatson KASSERT((a->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) != 0, 297132232Srwatson ("mac_biba_equal_effective: a not effective")); 298132232Srwatson KASSERT((b->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) != 0, 299132232Srwatson ("mac_biba_equal_effective: b not effective")); 300101099Srwatson 301132232Srwatson return (mac_biba_equal_element(&a->mb_effective, &b->mb_effective)); 302101099Srwatson} 303101099Srwatson 304101099Srwatsonstatic int 305105634Srwatsonmac_biba_contains_equal(struct mac_biba *mac_biba) 306105634Srwatson{ 307105634Srwatson 308132232Srwatson if (mac_biba->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) 309132232Srwatson if (mac_biba->mb_effective.mbe_type == MAC_BIBA_TYPE_EQUAL) 310105634Srwatson return (1); 311105634Srwatson 312105634Srwatson if (mac_biba->mb_flags & MAC_BIBA_FLAG_RANGE) { 313105634Srwatson if (mac_biba->mb_rangelow.mbe_type == MAC_BIBA_TYPE_EQUAL) 314105634Srwatson return (1); 315105634Srwatson if (mac_biba->mb_rangehigh.mbe_type == MAC_BIBA_TYPE_EQUAL) 316105637Srwatson return (1); 317105634Srwatson } 318105634Srwatson 319105634Srwatson return (0); 320105634Srwatson} 321105634Srwatson 322105634Srwatsonstatic int 323106090Srwatsonmac_biba_subject_privileged(struct mac_biba *mac_biba) 324105634Srwatson{ 325105634Srwatson 326105634Srwatson KASSERT((mac_biba->mb_flags & MAC_BIBA_FLAGS_BOTH) == 327105634Srwatson MAC_BIBA_FLAGS_BOTH, 328106090Srwatson ("mac_biba_subject_privileged: subject doesn't have both labels")); 329105634Srwatson 330132232Srwatson /* If the effective is EQUAL, it's ok. */ 331132232Srwatson if (mac_biba->mb_effective.mbe_type == MAC_BIBA_TYPE_EQUAL) 332105634Srwatson return (0); 333105634Srwatson 334105634Srwatson /* If either range endpoint is EQUAL, it's ok. */ 335105634Srwatson if (mac_biba->mb_rangelow.mbe_type == MAC_BIBA_TYPE_EQUAL || 336105634Srwatson mac_biba->mb_rangehigh.mbe_type == MAC_BIBA_TYPE_EQUAL) 337105634Srwatson return (0); 338105634Srwatson 339105634Srwatson /* If the range is low-high, it's ok. */ 340105634Srwatson if (mac_biba->mb_rangelow.mbe_type == MAC_BIBA_TYPE_LOW && 341105634Srwatson mac_biba->mb_rangehigh.mbe_type == MAC_BIBA_TYPE_HIGH) 342105634Srwatson return (0); 343105634Srwatson 344105634Srwatson /* It's not ok. */ 345105634Srwatson return (EPERM); 346105634Srwatson} 347105634Srwatson 348106091Srwatsonstatic int 349132232Srwatsonmac_biba_high_effective(struct mac_biba *mac_biba) 350105988Srwatson{ 351105988Srwatson 352132232Srwatson KASSERT((mac_biba->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) != 0, 353132232Srwatson ("mac_biba_equal_effective: mac_biba not effective")); 354105988Srwatson 355132232Srwatson return (mac_biba->mb_effective.mbe_type == MAC_BIBA_TYPE_HIGH); 356105988Srwatson} 357105988Srwatson 358105634Srwatsonstatic int 359101099Srwatsonmac_biba_valid(struct mac_biba *mac_biba) 360101099Srwatson{ 361101099Srwatson 362132232Srwatson if (mac_biba->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) { 363132232Srwatson switch (mac_biba->mb_effective.mbe_type) { 364101099Srwatson case MAC_BIBA_TYPE_GRADE: 365101099Srwatson break; 366101099Srwatson 367101099Srwatson case MAC_BIBA_TYPE_EQUAL: 368101099Srwatson case MAC_BIBA_TYPE_HIGH: 369101099Srwatson case MAC_BIBA_TYPE_LOW: 370132232Srwatson if (mac_biba->mb_effective.mbe_grade != 0 || 371105643Srwatson !MAC_BIBA_BIT_SET_EMPTY( 372132232Srwatson mac_biba->mb_effective.mbe_compartments)) 373101099Srwatson return (EINVAL); 374101099Srwatson break; 375101099Srwatson 376101099Srwatson default: 377101099Srwatson return (EINVAL); 378101099Srwatson } 379101099Srwatson } else { 380132232Srwatson if (mac_biba->mb_effective.mbe_type != MAC_BIBA_TYPE_UNDEF) 381101099Srwatson return (EINVAL); 382101099Srwatson } 383101099Srwatson 384101099Srwatson if (mac_biba->mb_flags & MAC_BIBA_FLAG_RANGE) { 385101099Srwatson switch (mac_biba->mb_rangelow.mbe_type) { 386101099Srwatson case MAC_BIBA_TYPE_GRADE: 387101099Srwatson break; 388101099Srwatson 389101099Srwatson case MAC_BIBA_TYPE_EQUAL: 390101099Srwatson case MAC_BIBA_TYPE_HIGH: 391101099Srwatson case MAC_BIBA_TYPE_LOW: 392105643Srwatson if (mac_biba->mb_rangelow.mbe_grade != 0 || 393105643Srwatson !MAC_BIBA_BIT_SET_EMPTY( 394105643Srwatson mac_biba->mb_rangelow.mbe_compartments)) 395101099Srwatson return (EINVAL); 396101099Srwatson break; 397101099Srwatson 398101099Srwatson default: 399101099Srwatson return (EINVAL); 400101099Srwatson } 401101099Srwatson 402101099Srwatson switch (mac_biba->mb_rangehigh.mbe_type) { 403101099Srwatson case MAC_BIBA_TYPE_GRADE: 404101099Srwatson break; 405101099Srwatson 406101099Srwatson case MAC_BIBA_TYPE_EQUAL: 407101099Srwatson case MAC_BIBA_TYPE_HIGH: 408101099Srwatson case MAC_BIBA_TYPE_LOW: 409105643Srwatson if (mac_biba->mb_rangehigh.mbe_grade != 0 || 410105643Srwatson !MAC_BIBA_BIT_SET_EMPTY( 411105643Srwatson mac_biba->mb_rangehigh.mbe_compartments)) 412101099Srwatson return (EINVAL); 413101099Srwatson break; 414101099Srwatson 415101099Srwatson default: 416101099Srwatson return (EINVAL); 417101099Srwatson } 418101099Srwatson if (!mac_biba_dominate_element(&mac_biba->mb_rangehigh, 419101099Srwatson &mac_biba->mb_rangelow)) 420101099Srwatson return (EINVAL); 421101099Srwatson } else { 422101099Srwatson if (mac_biba->mb_rangelow.mbe_type != MAC_BIBA_TYPE_UNDEF || 423101099Srwatson mac_biba->mb_rangehigh.mbe_type != MAC_BIBA_TYPE_UNDEF) 424101099Srwatson return (EINVAL); 425101099Srwatson } 426101099Srwatson 427101099Srwatson return (0); 428101099Srwatson} 429101099Srwatson 430101099Srwatsonstatic void 431101099Srwatsonmac_biba_set_range(struct mac_biba *mac_biba, u_short typelow, 432105643Srwatson u_short gradelow, u_char *compartmentslow, u_short typehigh, 433105643Srwatson u_short gradehigh, u_char *compartmentshigh) 434101099Srwatson{ 435101099Srwatson 436101099Srwatson mac_biba->mb_rangelow.mbe_type = typelow; 437101099Srwatson mac_biba->mb_rangelow.mbe_grade = gradelow; 438105643Srwatson if (compartmentslow != NULL) 439105643Srwatson memcpy(mac_biba->mb_rangelow.mbe_compartments, 440105643Srwatson compartmentslow, 441105643Srwatson sizeof(mac_biba->mb_rangelow.mbe_compartments)); 442101099Srwatson mac_biba->mb_rangehigh.mbe_type = typehigh; 443101099Srwatson mac_biba->mb_rangehigh.mbe_grade = gradehigh; 444105643Srwatson if (compartmentshigh != NULL) 445105643Srwatson memcpy(mac_biba->mb_rangehigh.mbe_compartments, 446105643Srwatson compartmentshigh, 447105643Srwatson sizeof(mac_biba->mb_rangehigh.mbe_compartments)); 448101099Srwatson mac_biba->mb_flags |= MAC_BIBA_FLAG_RANGE; 449101099Srwatson} 450101099Srwatson 451101099Srwatsonstatic void 452132232Srwatsonmac_biba_set_effective(struct mac_biba *mac_biba, u_short type, u_short grade, 453105643Srwatson u_char *compartments) 454101099Srwatson{ 455101099Srwatson 456132232Srwatson mac_biba->mb_effective.mbe_type = type; 457132232Srwatson mac_biba->mb_effective.mbe_grade = grade; 458105643Srwatson if (compartments != NULL) 459132232Srwatson memcpy(mac_biba->mb_effective.mbe_compartments, compartments, 460132232Srwatson sizeof(mac_biba->mb_effective.mbe_compartments)); 461132232Srwatson mac_biba->mb_flags |= MAC_BIBA_FLAG_EFFECTIVE; 462101099Srwatson} 463101099Srwatson 464101099Srwatsonstatic void 465101099Srwatsonmac_biba_copy_range(struct mac_biba *labelfrom, struct mac_biba *labelto) 466101099Srwatson{ 467105643Srwatson 468101099Srwatson KASSERT((labelfrom->mb_flags & MAC_BIBA_FLAG_RANGE) != 0, 469101099Srwatson ("mac_biba_copy_range: labelfrom not range")); 470101099Srwatson 471101099Srwatson labelto->mb_rangelow = labelfrom->mb_rangelow; 472101099Srwatson labelto->mb_rangehigh = labelfrom->mb_rangehigh; 473101099Srwatson labelto->mb_flags |= MAC_BIBA_FLAG_RANGE; 474101099Srwatson} 475101099Srwatson 476101099Srwatsonstatic void 477132232Srwatsonmac_biba_copy_effective(struct mac_biba *labelfrom, struct mac_biba *labelto) 478101099Srwatson{ 479101099Srwatson 480132232Srwatson KASSERT((labelfrom->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) != 0, 481132232Srwatson ("mac_biba_copy_effective: labelfrom not effective")); 482101099Srwatson 483132232Srwatson labelto->mb_effective = labelfrom->mb_effective; 484132232Srwatson labelto->mb_flags |= MAC_BIBA_FLAG_EFFECTIVE; 485101099Srwatson} 486101099Srwatson 487105656Srwatsonstatic void 488105656Srwatsonmac_biba_copy(struct mac_biba *source, struct mac_biba *dest) 489105656Srwatson{ 490105656Srwatson 491132232Srwatson if (source->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) 492132232Srwatson mac_biba_copy_effective(source, dest); 493105656Srwatson if (source->mb_flags & MAC_BIBA_FLAG_RANGE) 494105656Srwatson mac_biba_copy_range(source, dest); 495105656Srwatson} 496105656Srwatson 497101099Srwatson/* 498101099Srwatson * Policy module operations. 499101099Srwatson */ 500101099Srwatsonstatic void 501101099Srwatsonmac_biba_init(struct mac_policy_conf *conf) 502101099Srwatson{ 503101099Srwatson 504122879Srwatson zone_biba = uma_zcreate("mac_biba", sizeof(struct mac_biba), NULL, 505122879Srwatson NULL, NULL, NULL, UMA_ALIGN_PTR, 0); 506101099Srwatson} 507101099Srwatson 508101099Srwatson/* 509101099Srwatson * Label operations. 510101099Srwatson */ 511101099Srwatsonstatic void 512104514Srwatsonmac_biba_init_label(struct label *label) 513101099Srwatson{ 514101099Srwatson 515132781Skan SLOT_SET(label, biba_alloc(M_WAITOK)); 516101099Srwatson} 517101099Srwatson 518101099Srwatsonstatic int 519104514Srwatsonmac_biba_init_label_waitcheck(struct label *label, int flag) 520101099Srwatson{ 521101099Srwatson 522132781Skan SLOT_SET(label, biba_alloc(flag)); 523101099Srwatson if (SLOT(label) == NULL) 524101099Srwatson return (ENOMEM); 525101099Srwatson 526101099Srwatson return (0); 527101099Srwatson} 528101099Srwatson 529101099Srwatsonstatic void 530104514Srwatsonmac_biba_destroy_label(struct label *label) 531101099Srwatson{ 532101099Srwatson 533101099Srwatson biba_free(SLOT(label)); 534132781Skan SLOT_SET(label, NULL); 535101099Srwatson} 536101099Srwatson 537105696Srwatson/* 538115497Srwatson * mac_biba_element_to_string() accepts an sbuf and Biba element. It 539115497Srwatson * converts the Biba element to a string and stores the result in the 540115497Srwatson * sbuf; if there isn't space in the sbuf, -1 is returned. 541105696Srwatson */ 542115497Srwatsonstatic int 543115497Srwatsonmac_biba_element_to_string(struct sbuf *sb, struct mac_biba_element *element) 544105696Srwatson{ 545115497Srwatson int i, first; 546105696Srwatson 547105696Srwatson switch (element->mbe_type) { 548105696Srwatson case MAC_BIBA_TYPE_HIGH: 549115497Srwatson return (sbuf_printf(sb, "high")); 550105696Srwatson 551105696Srwatson case MAC_BIBA_TYPE_LOW: 552115497Srwatson return (sbuf_printf(sb, "low")); 553105696Srwatson 554105696Srwatson case MAC_BIBA_TYPE_EQUAL: 555115497Srwatson return (sbuf_printf(sb, "equal")); 556105696Srwatson 557105696Srwatson case MAC_BIBA_TYPE_GRADE: 558115497Srwatson if (sbuf_printf(sb, "%d", element->mbe_grade) == -1) 559115497Srwatson return (-1); 560115497Srwatson 561115497Srwatson first = 1; 562115497Srwatson for (i = 1; i <= MAC_BIBA_MAX_COMPARTMENTS; i++) { 563115497Srwatson if (MAC_BIBA_BIT_TEST(i, element->mbe_compartments)) { 564115497Srwatson if (first) { 565115497Srwatson if (sbuf_putc(sb, ':') == -1) 566115497Srwatson return (-1); 567115497Srwatson if (sbuf_printf(sb, "%d", i) == -1) 568115497Srwatson return (-1); 569115497Srwatson first = 0; 570115497Srwatson } else { 571115497Srwatson if (sbuf_printf(sb, "+%d", i) == -1) 572115497Srwatson return (-1); 573115497Srwatson } 574115497Srwatson } 575105696Srwatson } 576115497Srwatson return (0); 577105696Srwatson 578105696Srwatson default: 579105696Srwatson panic("mac_biba_element_to_string: invalid type (%d)", 580105696Srwatson element->mbe_type); 581105696Srwatson } 582105696Srwatson} 583105696Srwatson 584115497Srwatson/* 585116701Srwatson * mac_biba_to_string() converts a Biba label to a string, and places 586116701Srwatson * the results in the passed sbuf. It returns 0 on success, or EINVAL 587116701Srwatson * if there isn't room in the sbuf. Note: the sbuf will be modified 588116701Srwatson * even in a failure case, so the caller may need to revert the sbuf 589116701Srwatson * by restoring the offset if that's undesired. 590115497Srwatson */ 591101099Srwatsonstatic int 592116701Srwatsonmac_biba_to_string(struct sbuf *sb, struct mac_biba *mac_biba) 593101099Srwatson{ 594105696Srwatson 595132232Srwatson if (mac_biba->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) { 596132232Srwatson if (mac_biba_element_to_string(sb, &mac_biba->mb_effective) 597115497Srwatson == -1) 598105696Srwatson return (EINVAL); 599105696Srwatson } 600105696Srwatson 601105696Srwatson if (mac_biba->mb_flags & MAC_BIBA_FLAG_RANGE) { 602116701Srwatson if (sbuf_putc(sb, '(') == -1) 603105696Srwatson return (EINVAL); 604105696Srwatson 605116701Srwatson if (mac_biba_element_to_string(sb, &mac_biba->mb_rangelow) 606115497Srwatson == -1) 607105696Srwatson return (EINVAL); 608105696Srwatson 609116701Srwatson if (sbuf_putc(sb, '-') == -1) 610105696Srwatson return (EINVAL); 611105696Srwatson 612116701Srwatson if (mac_biba_element_to_string(sb, &mac_biba->mb_rangehigh) 613115497Srwatson == -1) 614105696Srwatson return (EINVAL); 615105696Srwatson 616116701Srwatson if (sbuf_putc(sb, ')') == -1) 617105696Srwatson return (EINVAL); 618105696Srwatson } 619105696Srwatson 620105696Srwatson return (0); 621105696Srwatson} 622105696Srwatson 623105696Srwatsonstatic int 624105696Srwatsonmac_biba_externalize_label(struct label *label, char *element_name, 625116701Srwatson struct sbuf *sb, int *claimed) 626105696Srwatson{ 627101099Srwatson struct mac_biba *mac_biba; 628101099Srwatson 629105696Srwatson if (strcmp(MAC_BIBA_LABEL_NAME, element_name) != 0) 630105696Srwatson return (0); 631105696Srwatson 632105696Srwatson (*claimed)++; 633105696Srwatson 634101099Srwatson mac_biba = SLOT(label); 635116701Srwatson return (mac_biba_to_string(sb, mac_biba)); 636105696Srwatson} 637105696Srwatson 638105696Srwatsonstatic int 639105696Srwatsonmac_biba_parse_element(struct mac_biba_element *element, char *string) 640101099Srwatson{ 641115395Srwatson char *compartment, *end, *grade; 642115395Srwatson int value; 643105696Srwatson 644105696Srwatson if (strcmp(string, "high") == 0 || 645105696Srwatson strcmp(string, "hi") == 0) { 646105696Srwatson element->mbe_type = MAC_BIBA_TYPE_HIGH; 647105696Srwatson element->mbe_grade = MAC_BIBA_TYPE_UNDEF; 648105696Srwatson } else if (strcmp(string, "low") == 0 || 649105696Srwatson strcmp(string, "lo") == 0) { 650105696Srwatson element->mbe_type = MAC_BIBA_TYPE_LOW; 651105696Srwatson element->mbe_grade = MAC_BIBA_TYPE_UNDEF; 652105696Srwatson } else if (strcmp(string, "equal") == 0 || 653105696Srwatson strcmp(string, "eq") == 0) { 654105696Srwatson element->mbe_type = MAC_BIBA_TYPE_EQUAL; 655105696Srwatson element->mbe_grade = MAC_BIBA_TYPE_UNDEF; 656105696Srwatson } else { 657115395Srwatson element->mbe_type = MAC_BIBA_TYPE_GRADE; 658105696Srwatson 659115395Srwatson /* 660115395Srwatson * Numeric grade piece of the element. 661115395Srwatson */ 662115395Srwatson grade = strsep(&string, ":"); 663115395Srwatson value = strtol(grade, &end, 10); 664115395Srwatson if (end == grade || *end != '\0') 665105696Srwatson return (EINVAL); 666115395Srwatson if (value < 0 || value > 65535) 667115395Srwatson return (EINVAL); 668115395Srwatson element->mbe_grade = value; 669105696Srwatson 670115395Srwatson /* 671115395Srwatson * Optional compartment piece of the element. If none 672115395Srwatson * are included, we assume that the label has no 673115395Srwatson * compartments. 674115395Srwatson */ 675115395Srwatson if (string == NULL) 676115395Srwatson return (0); 677115395Srwatson if (*string == '\0') 678115395Srwatson return (0); 679105696Srwatson 680115395Srwatson while ((compartment = strsep(&string, "+")) != NULL) { 681115395Srwatson value = strtol(compartment, &end, 10); 682115395Srwatson if (compartment == end || *end != '\0') 683105696Srwatson return (EINVAL); 684115395Srwatson if (value < 1 || value > MAC_BIBA_MAX_COMPARTMENTS) 685105696Srwatson return (EINVAL); 686115395Srwatson MAC_BIBA_BIT_SET(value, element->mbe_compartments); 687105696Srwatson } 688105696Srwatson } 689105696Srwatson 690105696Srwatson return (0); 691105696Srwatson} 692105696Srwatson 693105696Srwatson/* 694105696Srwatson * Note: destructively consumes the string, make a local copy before 695105696Srwatson * calling if that's a problem. 696105696Srwatson */ 697105696Srwatsonstatic int 698105696Srwatsonmac_biba_parse(struct mac_biba *mac_biba, char *string) 699105696Srwatson{ 700132232Srwatson char *rangehigh, *rangelow, *effective; 701101099Srwatson int error; 702101099Srwatson 703132232Srwatson effective = strsep(&string, "("); 704132232Srwatson if (*effective == '\0') 705132232Srwatson effective = NULL; 706115395Srwatson 707115395Srwatson if (string != NULL) { 708115395Srwatson rangelow = strsep(&string, "-"); 709115395Srwatson if (string == NULL) 710105696Srwatson return (EINVAL); 711115395Srwatson rangehigh = strsep(&string, ")"); 712115395Srwatson if (string == NULL) 713105696Srwatson return (EINVAL); 714115395Srwatson if (*string != '\0') 715105696Srwatson return (EINVAL); 716115395Srwatson } else { 717115395Srwatson rangelow = NULL; 718115395Srwatson rangehigh = NULL; 719105696Srwatson } 720115395Srwatson 721105696Srwatson KASSERT((rangelow != NULL && rangehigh != NULL) || 722105696Srwatson (rangelow == NULL && rangehigh == NULL), 723115395Srwatson ("mac_biba_parse: range mismatch")); 724101099Srwatson 725105696Srwatson bzero(mac_biba, sizeof(*mac_biba)); 726132232Srwatson if (effective != NULL) { 727132232Srwatson error = mac_biba_parse_element(&mac_biba->mb_effective, effective); 728105696Srwatson if (error) 729105696Srwatson return (error); 730132232Srwatson mac_biba->mb_flags |= MAC_BIBA_FLAG_EFFECTIVE; 731105696Srwatson } 732105696Srwatson 733105696Srwatson if (rangelow != NULL) { 734105696Srwatson error = mac_biba_parse_element(&mac_biba->mb_rangelow, 735105696Srwatson rangelow); 736105696Srwatson if (error) 737105696Srwatson return (error); 738105696Srwatson error = mac_biba_parse_element(&mac_biba->mb_rangehigh, 739105696Srwatson rangehigh); 740105696Srwatson if (error) 741105696Srwatson return (error); 742105696Srwatson mac_biba->mb_flags |= MAC_BIBA_FLAG_RANGE; 743105696Srwatson } 744105696Srwatson 745101099Srwatson error = mac_biba_valid(mac_biba); 746101099Srwatson if (error) 747101099Srwatson return (error); 748101099Srwatson 749105696Srwatson return (0); 750105696Srwatson} 751101099Srwatson 752105696Srwatsonstatic int 753105696Srwatsonmac_biba_internalize_label(struct label *label, char *element_name, 754105696Srwatson char *element_data, int *claimed) 755105696Srwatson{ 756105696Srwatson struct mac_biba *mac_biba, mac_biba_temp; 757105696Srwatson int error; 758105696Srwatson 759105696Srwatson if (strcmp(MAC_BIBA_LABEL_NAME, element_name) != 0) 760105696Srwatson return (0); 761105696Srwatson 762105696Srwatson (*claimed)++; 763105696Srwatson 764105696Srwatson error = mac_biba_parse(&mac_biba_temp, element_data); 765105696Srwatson if (error) 766105696Srwatson return (error); 767105696Srwatson 768105696Srwatson mac_biba = SLOT(label); 769105696Srwatson *mac_biba = mac_biba_temp; 770105696Srwatson 771101099Srwatson return (0); 772101099Srwatson} 773101099Srwatson 774105696Srwatsonstatic void 775105696Srwatsonmac_biba_copy_label(struct label *src, struct label *dest) 776105696Srwatson{ 777105696Srwatson 778105696Srwatson *SLOT(dest) = *SLOT(src); 779105696Srwatson} 780105696Srwatson 781101099Srwatson/* 782101099Srwatson * Labeling event operations: file system objects, and things that look 783101099Srwatson * a lot like file system objects. 784101099Srwatson */ 785101099Srwatsonstatic void 786147982Srwatsonmac_biba_create_devfs_device(struct ucred *cred, struct mount *mp, 787147982Srwatson struct cdev *dev, struct devfs_dirent *devfs_dirent, struct label *label) 788101099Srwatson{ 789101099Srwatson struct mac_biba *mac_biba; 790101099Srwatson int biba_type; 791101099Srwatson 792101099Srwatson mac_biba = SLOT(label); 793101099Srwatson if (strcmp(dev->si_name, "null") == 0 || 794101099Srwatson strcmp(dev->si_name, "zero") == 0 || 795101099Srwatson strcmp(dev->si_name, "random") == 0 || 796101099Srwatson strncmp(dev->si_name, "fd/", strlen("fd/")) == 0) 797101099Srwatson biba_type = MAC_BIBA_TYPE_EQUAL; 798105606Srwatson else if (ptys_equal && 799105606Srwatson (strncmp(dev->si_name, "ttyp", strlen("ttyp")) == 0 || 800105606Srwatson strncmp(dev->si_name, "ptyp", strlen("ptyp")) == 0)) 801105606Srwatson biba_type = MAC_BIBA_TYPE_EQUAL; 802101099Srwatson else 803101099Srwatson biba_type = MAC_BIBA_TYPE_HIGH; 804132232Srwatson mac_biba_set_effective(mac_biba, biba_type, 0, NULL); 805101099Srwatson} 806101099Srwatson 807101099Srwatsonstatic void 808107698Srwatsonmac_biba_create_devfs_directory(struct mount *mp, char *dirname, 809107698Srwatson int dirnamelen, struct devfs_dirent *devfs_dirent, struct label *label) 810101099Srwatson{ 811101099Srwatson struct mac_biba *mac_biba; 812101099Srwatson 813101099Srwatson mac_biba = SLOT(label); 814132232Srwatson mac_biba_set_effective(mac_biba, MAC_BIBA_TYPE_HIGH, 0, NULL); 815101099Srwatson} 816101099Srwatson 817101099Srwatsonstatic void 818107698Srwatsonmac_biba_create_devfs_symlink(struct ucred *cred, struct mount *mp, 819107698Srwatson struct devfs_dirent *dd, struct label *ddlabel, struct devfs_dirent *de, 820122563Srwatson struct label *delabel) 821104535Srwatson{ 822104535Srwatson struct mac_biba *source, *dest; 823104535Srwatson 824122524Srwatson source = SLOT(cred->cr_label); 825104535Srwatson dest = SLOT(delabel); 826104535Srwatson 827132232Srwatson mac_biba_copy_effective(source, dest); 828104535Srwatson} 829104535Srwatson 830104535Srwatsonstatic void 831101099Srwatsonmac_biba_create_mount(struct ucred *cred, struct mount *mp, 832168954Srwatson struct label *mntlabel) 833101099Srwatson{ 834101099Srwatson struct mac_biba *source, *dest; 835101099Srwatson 836122524Srwatson source = SLOT(cred->cr_label); 837101099Srwatson dest = SLOT(mntlabel); 838132232Srwatson mac_biba_copy_effective(source, dest); 839101099Srwatson} 840101099Srwatson 841101099Srwatsonstatic void 842101099Srwatsonmac_biba_relabel_vnode(struct ucred *cred, struct vnode *vp, 843101099Srwatson struct label *vnodelabel, struct label *label) 844101099Srwatson{ 845101099Srwatson struct mac_biba *source, *dest; 846101099Srwatson 847101099Srwatson source = SLOT(label); 848101099Srwatson dest = SLOT(vnodelabel); 849101099Srwatson 850105656Srwatson mac_biba_copy(source, dest); 851101099Srwatson} 852101099Srwatson 853101099Srwatsonstatic void 854107698Srwatsonmac_biba_update_devfsdirent(struct mount *mp, 855107698Srwatson struct devfs_dirent *devfs_dirent, struct label *direntlabel, 856107698Srwatson struct vnode *vp, struct label *vnodelabel) 857101099Srwatson{ 858101099Srwatson struct mac_biba *source, *dest; 859101099Srwatson 860101099Srwatson source = SLOT(vnodelabel); 861101099Srwatson dest = SLOT(direntlabel); 862101099Srwatson 863105656Srwatson mac_biba_copy(source, dest); 864101099Srwatson} 865101099Srwatson 866101099Srwatsonstatic void 867168954Srwatsonmac_biba_associate_vnode_devfs(struct mount *mp, struct label *mntlabel, 868105988Srwatson struct devfs_dirent *de, struct label *delabel, struct vnode *vp, 869105988Srwatson struct label *vlabel) 870101099Srwatson{ 871101099Srwatson struct mac_biba *source, *dest; 872101099Srwatson 873105988Srwatson source = SLOT(delabel); 874105988Srwatson dest = SLOT(vlabel); 875101099Srwatson 876132232Srwatson mac_biba_copy_effective(source, dest); 877101099Srwatson} 878101099Srwatson 879101099Srwatsonstatic int 880168954Srwatsonmac_biba_associate_vnode_extattr(struct mount *mp, struct label *mntlabel, 881105988Srwatson struct vnode *vp, struct label *vlabel) 882101099Srwatson{ 883105988Srwatson struct mac_biba temp, *source, *dest; 884106354Smux int buflen, error; 885101099Srwatson 886168954Srwatson source = SLOT(mntlabel); 887105988Srwatson dest = SLOT(vlabel); 888101099Srwatson 889105988Srwatson buflen = sizeof(temp); 890105988Srwatson bzero(&temp, buflen); 891105988Srwatson 892105988Srwatson error = vn_extattr_get(vp, IO_NODELOCKED, MAC_BIBA_EXTATTR_NAMESPACE, 893105988Srwatson MAC_BIBA_EXTATTR_NAME, &buflen, (char *) &temp, curthread); 894105988Srwatson if (error == ENOATTR || error == EOPNOTSUPP) { 895168954Srwatson /* Fall back to the mntlabel. */ 896132232Srwatson mac_biba_copy_effective(source, dest); 897105988Srwatson return (0); 898105988Srwatson } else if (error) 899101099Srwatson return (error); 900101099Srwatson 901105988Srwatson if (buflen != sizeof(temp)) { 902105988Srwatson printf("mac_biba_associate_vnode_extattr: bad size %d\n", 903105988Srwatson buflen); 904105988Srwatson return (EPERM); 905105988Srwatson } 906105988Srwatson if (mac_biba_valid(&temp) != 0) { 907105988Srwatson printf("mac_biba_associate_vnode_extattr: invalid\n"); 908105988Srwatson return (EPERM); 909105988Srwatson } 910132232Srwatson if ((temp.mb_flags & MAC_BIBA_FLAGS_BOTH) != MAC_BIBA_FLAG_EFFECTIVE) { 911132232Srwatson printf("mac_biba_associate_vnode_extattr: not effective\n"); 912105988Srwatson return (EPERM); 913105988Srwatson } 914101099Srwatson 915132232Srwatson mac_biba_copy_effective(&temp, dest); 916101099Srwatson return (0); 917101099Srwatson} 918101099Srwatson 919101099Srwatsonstatic void 920105988Srwatsonmac_biba_associate_vnode_singlelabel(struct mount *mp, 921168954Srwatson struct label *mntlabel, struct vnode *vp, struct label *vlabel) 922101099Srwatson{ 923101099Srwatson struct mac_biba *source, *dest; 924101099Srwatson 925168954Srwatson source = SLOT(mntlabel); 926105988Srwatson dest = SLOT(vlabel); 927101099Srwatson 928132232Srwatson mac_biba_copy_effective(source, dest); 929101099Srwatson} 930101099Srwatson 931105988Srwatsonstatic int 932105988Srwatsonmac_biba_create_vnode_extattr(struct ucred *cred, struct mount *mp, 933168954Srwatson struct label *mntlabel, struct vnode *dvp, struct label *dlabel, 934105988Srwatson struct vnode *vp, struct label *vlabel, struct componentname *cnp) 935105988Srwatson{ 936105988Srwatson struct mac_biba *source, *dest, temp; 937105988Srwatson size_t buflen; 938105988Srwatson int error; 939105988Srwatson 940105988Srwatson buflen = sizeof(temp); 941105988Srwatson bzero(&temp, buflen); 942105988Srwatson 943122524Srwatson source = SLOT(cred->cr_label); 944105988Srwatson dest = SLOT(vlabel); 945132232Srwatson mac_biba_copy_effective(source, &temp); 946105988Srwatson 947105988Srwatson error = vn_extattr_set(vp, IO_NODELOCKED, MAC_BIBA_EXTATTR_NAMESPACE, 948105988Srwatson MAC_BIBA_EXTATTR_NAME, buflen, (char *) &temp, curthread); 949105988Srwatson if (error == 0) 950132232Srwatson mac_biba_copy_effective(source, dest); 951105988Srwatson return (error); 952105988Srwatson} 953105988Srwatson 954105988Srwatsonstatic int 955105988Srwatsonmac_biba_setlabel_vnode_extattr(struct ucred *cred, struct vnode *vp, 956105988Srwatson struct label *vlabel, struct label *intlabel) 957105988Srwatson{ 958105988Srwatson struct mac_biba *source, temp; 959105988Srwatson size_t buflen; 960105988Srwatson int error; 961105988Srwatson 962105988Srwatson buflen = sizeof(temp); 963105988Srwatson bzero(&temp, buflen); 964105988Srwatson 965105988Srwatson source = SLOT(intlabel); 966132232Srwatson if ((source->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) == 0) 967105988Srwatson return (0); 968105988Srwatson 969132232Srwatson mac_biba_copy_effective(source, &temp); 970105988Srwatson 971105988Srwatson error = vn_extattr_set(vp, IO_NODELOCKED, MAC_BIBA_EXTATTR_NAMESPACE, 972105988Srwatson MAC_BIBA_EXTATTR_NAME, buflen, (char *) &temp, curthread); 973105988Srwatson return (error); 974105988Srwatson} 975105988Srwatson 976101099Srwatson/* 977101099Srwatson * Labeling event operations: IPC object. 978101099Srwatson */ 979101099Srwatsonstatic void 980122875Srwatsonmac_biba_create_inpcb_from_socket(struct socket *so, struct label *solabel, 981122875Srwatson struct inpcb *inp, struct label *inplabel) 982122875Srwatson{ 983122875Srwatson struct mac_biba *source, *dest; 984122875Srwatson 985122875Srwatson source = SLOT(solabel); 986122875Srwatson dest = SLOT(inplabel); 987122875Srwatson 988132232Srwatson mac_biba_copy_effective(source, dest); 989122875Srwatson} 990122875Srwatson 991122875Srwatsonstatic void 992101099Srwatsonmac_biba_create_mbuf_from_socket(struct socket *so, struct label *socketlabel, 993101099Srwatson struct mbuf *m, struct label *mbuflabel) 994101099Srwatson{ 995101099Srwatson struct mac_biba *source, *dest; 996101099Srwatson 997101099Srwatson source = SLOT(socketlabel); 998101099Srwatson dest = SLOT(mbuflabel); 999101099Srwatson 1000132232Srwatson mac_biba_copy_effective(source, dest); 1001101099Srwatson} 1002101099Srwatson 1003101099Srwatsonstatic void 1004101099Srwatsonmac_biba_create_socket(struct ucred *cred, struct socket *socket, 1005101099Srwatson struct label *socketlabel) 1006101099Srwatson{ 1007101099Srwatson struct mac_biba *source, *dest; 1008101099Srwatson 1009122524Srwatson source = SLOT(cred->cr_label); 1010101099Srwatson dest = SLOT(socketlabel); 1011101099Srwatson 1012132232Srwatson mac_biba_copy_effective(source, dest); 1013101099Srwatson} 1014101099Srwatson 1015101099Srwatsonstatic void 1016125293Srwatsonmac_biba_create_pipe(struct ucred *cred, struct pipepair *pp, 1017101099Srwatson struct label *pipelabel) 1018101099Srwatson{ 1019101099Srwatson struct mac_biba *source, *dest; 1020101099Srwatson 1021122524Srwatson source = SLOT(cred->cr_label); 1022101099Srwatson dest = SLOT(pipelabel); 1023101099Srwatson 1024132232Srwatson mac_biba_copy_effective(source, dest); 1025101099Srwatson} 1026101099Srwatson 1027101099Srwatsonstatic void 1028145855Srwatsonmac_biba_create_posix_sem(struct ucred *cred, struct ksem *ksemptr, 1029145855Srwatson struct label *ks_label) 1030145855Srwatson{ 1031145855Srwatson struct mac_biba *source, *dest; 1032145855Srwatson 1033145855Srwatson source = SLOT(cred->cr_label); 1034145855Srwatson dest = SLOT(ks_label); 1035145855Srwatson 1036145855Srwatson mac_biba_copy_effective(source, dest); 1037145855Srwatson} 1038145855Srwatson 1039145855Srwatsonstatic void 1040101099Srwatsonmac_biba_create_socket_from_socket(struct socket *oldsocket, 1041101099Srwatson struct label *oldsocketlabel, struct socket *newsocket, 1042101099Srwatson struct label *newsocketlabel) 1043101099Srwatson{ 1044101099Srwatson struct mac_biba *source, *dest; 1045101099Srwatson 1046101099Srwatson source = SLOT(oldsocketlabel); 1047101099Srwatson dest = SLOT(newsocketlabel); 1048101099Srwatson 1049132232Srwatson mac_biba_copy_effective(source, dest); 1050101099Srwatson} 1051101099Srwatson 1052101099Srwatsonstatic void 1053101099Srwatsonmac_biba_relabel_socket(struct ucred *cred, struct socket *socket, 1054101099Srwatson struct label *socketlabel, struct label *newlabel) 1055101099Srwatson{ 1056101099Srwatson struct mac_biba *source, *dest; 1057101099Srwatson 1058101099Srwatson source = SLOT(newlabel); 1059101099Srwatson dest = SLOT(socketlabel); 1060101099Srwatson 1061105656Srwatson mac_biba_copy(source, dest); 1062101099Srwatson} 1063101099Srwatson 1064101099Srwatsonstatic void 1065125293Srwatsonmac_biba_relabel_pipe(struct ucred *cred, struct pipepair *pp, 1066101099Srwatson struct label *pipelabel, struct label *newlabel) 1067101099Srwatson{ 1068101099Srwatson struct mac_biba *source, *dest; 1069101099Srwatson 1070101099Srwatson source = SLOT(newlabel); 1071101099Srwatson dest = SLOT(pipelabel); 1072101099Srwatson 1073105656Srwatson mac_biba_copy(source, dest); 1074101099Srwatson} 1075101099Srwatson 1076101099Srwatsonstatic void 1077101099Srwatsonmac_biba_set_socket_peer_from_mbuf(struct mbuf *mbuf, struct label *mbuflabel, 1078101099Srwatson struct socket *socket, struct label *socketpeerlabel) 1079101099Srwatson{ 1080101099Srwatson struct mac_biba *source, *dest; 1081101099Srwatson 1082101099Srwatson source = SLOT(mbuflabel); 1083101099Srwatson dest = SLOT(socketpeerlabel); 1084101099Srwatson 1085132232Srwatson mac_biba_copy_effective(source, dest); 1086101099Srwatson} 1087101099Srwatson 1088101099Srwatson/* 1089140628Srwatson * Labeling event operations: System V IPC objects. 1090140628Srwatson */ 1091140628Srwatson 1092140628Srwatsonstatic void 1093140628Srwatsonmac_biba_create_sysv_msgmsg(struct ucred *cred, struct msqid_kernel *msqkptr, 1094140628Srwatson struct label *msqlabel, struct msg *msgptr, struct label *msglabel) 1095140628Srwatson{ 1096140628Srwatson struct mac_biba *source, *dest; 1097140628Srwatson 1098140628Srwatson /* Ignore the msgq label */ 1099140628Srwatson source = SLOT(cred->cr_label); 1100140628Srwatson dest = SLOT(msglabel); 1101140628Srwatson 1102140628Srwatson mac_biba_copy_effective(source, dest); 1103140628Srwatson} 1104140628Srwatson 1105140628Srwatsonstatic void 1106140628Srwatsonmac_biba_create_sysv_msgqueue(struct ucred *cred, 1107140628Srwatson struct msqid_kernel *msqkptr, struct label *msqlabel) 1108140628Srwatson{ 1109140628Srwatson struct mac_biba *source, *dest; 1110140628Srwatson 1111140628Srwatson source = SLOT(cred->cr_label); 1112140628Srwatson dest = SLOT(msqlabel); 1113140628Srwatson 1114140628Srwatson mac_biba_copy_effective(source, dest); 1115140628Srwatson} 1116140628Srwatson 1117140628Srwatsonstatic void 1118147091Srwatsonmac_biba_create_sysv_sem(struct ucred *cred, struct semid_kernel *semakptr, 1119140628Srwatson struct label *semalabel) 1120140628Srwatson{ 1121140628Srwatson struct mac_biba *source, *dest; 1122140628Srwatson 1123140628Srwatson source = SLOT(cred->cr_label); 1124140628Srwatson dest = SLOT(semalabel); 1125140628Srwatson 1126140628Srwatson mac_biba_copy_effective(source, dest); 1127140628Srwatson} 1128140628Srwatson 1129140628Srwatsonstatic void 1130140628Srwatsonmac_biba_create_sysv_shm(struct ucred *cred, struct shmid_kernel *shmsegptr, 1131140628Srwatson struct label *shmlabel) 1132140628Srwatson{ 1133140628Srwatson struct mac_biba *source, *dest; 1134140628Srwatson 1135140628Srwatson source = SLOT(cred->cr_label); 1136140628Srwatson dest = SLOT(shmlabel); 1137140628Srwatson 1138140628Srwatson mac_biba_copy_effective(source, dest); 1139140628Srwatson} 1140140628Srwatson 1141140628Srwatson/* 1142101099Srwatson * Labeling event operations: network objects. 1143101099Srwatson */ 1144101099Srwatsonstatic void 1145101099Srwatsonmac_biba_set_socket_peer_from_socket(struct socket *oldsocket, 1146101099Srwatson struct label *oldsocketlabel, struct socket *newsocket, 1147101099Srwatson struct label *newsocketpeerlabel) 1148101099Srwatson{ 1149101099Srwatson struct mac_biba *source, *dest; 1150101099Srwatson 1151101099Srwatson source = SLOT(oldsocketlabel); 1152101099Srwatson dest = SLOT(newsocketpeerlabel); 1153101099Srwatson 1154132232Srwatson mac_biba_copy_effective(source, dest); 1155101099Srwatson} 1156101099Srwatson 1157101099Srwatsonstatic void 1158101099Srwatsonmac_biba_create_bpfdesc(struct ucred *cred, struct bpf_d *bpf_d, 1159101099Srwatson struct label *bpflabel) 1160101099Srwatson{ 1161101099Srwatson struct mac_biba *source, *dest; 1162101099Srwatson 1163122524Srwatson source = SLOT(cred->cr_label); 1164101099Srwatson dest = SLOT(bpflabel); 1165101099Srwatson 1166132232Srwatson mac_biba_copy_effective(source, dest); 1167101099Srwatson} 1168101099Srwatson 1169101099Srwatsonstatic void 1170101099Srwatsonmac_biba_create_ifnet(struct ifnet *ifnet, struct label *ifnetlabel) 1171101099Srwatson{ 1172121816Sbrooks char tifname[IFNAMSIZ], *p, *q; 1173101099Srwatson char tiflist[sizeof(trusted_interfaces)]; 1174101099Srwatson struct mac_biba *dest; 1175110350Srwatson int len, type; 1176101099Srwatson 1177101099Srwatson dest = SLOT(ifnetlabel); 1178101099Srwatson 1179153927Scsjp if (ifnet->if_type == IFT_LOOP || interfaces_equal != 0) { 1180110350Srwatson type = MAC_BIBA_TYPE_EQUAL; 1181101099Srwatson goto set; 1182101099Srwatson } 1183101099Srwatson 1184101099Srwatson if (trust_all_interfaces) { 1185110350Srwatson type = MAC_BIBA_TYPE_HIGH; 1186101099Srwatson goto set; 1187101099Srwatson } 1188101099Srwatson 1189110350Srwatson type = MAC_BIBA_TYPE_LOW; 1190101099Srwatson 1191101099Srwatson if (trusted_interfaces[0] == '\0' || 1192101099Srwatson !strvalid(trusted_interfaces, sizeof(trusted_interfaces))) 1193101099Srwatson goto set; 1194101099Srwatson 1195106089Srwatson bzero(tiflist, sizeof(tiflist)); 1196101099Srwatson for (p = trusted_interfaces, q = tiflist; *p != '\0'; p++, q++) 1197101099Srwatson if(*p != ' ' && *p != '\t') 1198101099Srwatson *q = *p; 1199101099Srwatson 1200101099Srwatson for (p = q = tiflist;; p++) { 1201101099Srwatson if (*p == ',' || *p == '\0') { 1202101099Srwatson len = p - q; 1203101099Srwatson if (len < IFNAMSIZ) { 1204101099Srwatson bzero(tifname, sizeof(tifname)); 1205101099Srwatson bcopy(q, tifname, len); 1206121816Sbrooks if (strcmp(tifname, ifnet->if_xname) == 0) { 1207110350Srwatson type = MAC_BIBA_TYPE_HIGH; 1208101099Srwatson break; 1209101099Srwatson } 1210106089Srwatson } else { 1211106089Srwatson *p = '\0'; 1212106089Srwatson printf("mac_biba warning: interface name " 1213106089Srwatson "\"%s\" is too long (must be < %d)\n", 1214106089Srwatson q, IFNAMSIZ); 1215101099Srwatson } 1216101099Srwatson if (*p == '\0') 1217101099Srwatson break; 1218101099Srwatson q = p + 1; 1219101099Srwatson } 1220101099Srwatson } 1221101099Srwatsonset: 1222132232Srwatson mac_biba_set_effective(dest, type, 0, NULL); 1223110350Srwatson mac_biba_set_range(dest, type, 0, NULL, type, 0, NULL); 1224101099Srwatson} 1225101099Srwatson 1226101099Srwatsonstatic void 1227101099Srwatsonmac_biba_create_ipq(struct mbuf *fragment, struct label *fragmentlabel, 1228101099Srwatson struct ipq *ipq, struct label *ipqlabel) 1229101099Srwatson{ 1230101099Srwatson struct mac_biba *source, *dest; 1231101099Srwatson 1232101099Srwatson source = SLOT(fragmentlabel); 1233101099Srwatson dest = SLOT(ipqlabel); 1234101099Srwatson 1235132232Srwatson mac_biba_copy_effective(source, dest); 1236101099Srwatson} 1237101099Srwatson 1238101099Srwatsonstatic void 1239101099Srwatsonmac_biba_create_datagram_from_ipq(struct ipq *ipq, struct label *ipqlabel, 1240101099Srwatson struct mbuf *datagram, struct label *datagramlabel) 1241101099Srwatson{ 1242101099Srwatson struct mac_biba *source, *dest; 1243101099Srwatson 1244101099Srwatson source = SLOT(ipqlabel); 1245101099Srwatson dest = SLOT(datagramlabel); 1246101099Srwatson 1247101099Srwatson /* Just use the head, since we require them all to match. */ 1248132232Srwatson mac_biba_copy_effective(source, dest); 1249101099Srwatson} 1250101099Srwatson 1251101099Srwatsonstatic void 1252101099Srwatsonmac_biba_create_fragment(struct mbuf *datagram, struct label *datagramlabel, 1253101099Srwatson struct mbuf *fragment, struct label *fragmentlabel) 1254101099Srwatson{ 1255101099Srwatson struct mac_biba *source, *dest; 1256101099Srwatson 1257101099Srwatson source = SLOT(datagramlabel); 1258101099Srwatson dest = SLOT(fragmentlabel); 1259101099Srwatson 1260132232Srwatson mac_biba_copy_effective(source, dest); 1261101099Srwatson} 1262101099Srwatson 1263101099Srwatsonstatic void 1264123607Srwatsonmac_biba_create_mbuf_from_inpcb(struct inpcb *inp, struct label *inplabel, 1265123607Srwatson struct mbuf *m, struct label *mlabel) 1266123607Srwatson{ 1267123607Srwatson struct mac_biba *source, *dest; 1268123607Srwatson 1269123607Srwatson source = SLOT(inplabel); 1270123607Srwatson dest = SLOT(mlabel); 1271123607Srwatson 1272132232Srwatson mac_biba_copy_effective(source, dest); 1273123607Srwatson} 1274123607Srwatson 1275123607Srwatsonstatic void 1276101099Srwatsonmac_biba_create_mbuf_linklayer(struct ifnet *ifnet, struct label *ifnetlabel, 1277101099Srwatson struct mbuf *mbuf, struct label *mbuflabel) 1278101099Srwatson{ 1279101099Srwatson struct mac_biba *dest; 1280101099Srwatson 1281101099Srwatson dest = SLOT(mbuflabel); 1282101099Srwatson 1283132232Srwatson mac_biba_set_effective(dest, MAC_BIBA_TYPE_EQUAL, 0, NULL); 1284101099Srwatson} 1285101099Srwatson 1286101099Srwatsonstatic void 1287101099Srwatsonmac_biba_create_mbuf_from_bpfdesc(struct bpf_d *bpf_d, struct label *bpflabel, 1288101099Srwatson struct mbuf *mbuf, struct label *mbuflabel) 1289101099Srwatson{ 1290101099Srwatson struct mac_biba *source, *dest; 1291101099Srwatson 1292101099Srwatson source = SLOT(bpflabel); 1293101099Srwatson dest = SLOT(mbuflabel); 1294101099Srwatson 1295132232Srwatson mac_biba_copy_effective(source, dest); 1296101099Srwatson} 1297101099Srwatson 1298101099Srwatsonstatic void 1299101099Srwatsonmac_biba_create_mbuf_from_ifnet(struct ifnet *ifnet, struct label *ifnetlabel, 1300101099Srwatson struct mbuf *m, struct label *mbuflabel) 1301101099Srwatson{ 1302101099Srwatson struct mac_biba *source, *dest; 1303101099Srwatson 1304101099Srwatson source = SLOT(ifnetlabel); 1305101099Srwatson dest = SLOT(mbuflabel); 1306101099Srwatson 1307132232Srwatson mac_biba_copy_effective(source, dest); 1308101099Srwatson} 1309101099Srwatson 1310101099Srwatsonstatic void 1311101099Srwatsonmac_biba_create_mbuf_multicast_encap(struct mbuf *oldmbuf, 1312101099Srwatson struct label *oldmbuflabel, struct ifnet *ifnet, struct label *ifnetlabel, 1313101099Srwatson struct mbuf *newmbuf, struct label *newmbuflabel) 1314101099Srwatson{ 1315101099Srwatson struct mac_biba *source, *dest; 1316101099Srwatson 1317101099Srwatson source = SLOT(oldmbuflabel); 1318101099Srwatson dest = SLOT(newmbuflabel); 1319101099Srwatson 1320132232Srwatson mac_biba_copy_effective(source, dest); 1321101099Srwatson} 1322101099Srwatson 1323101099Srwatsonstatic void 1324101099Srwatsonmac_biba_create_mbuf_netlayer(struct mbuf *oldmbuf, struct label *oldmbuflabel, 1325101099Srwatson struct mbuf *newmbuf, struct label *newmbuflabel) 1326101099Srwatson{ 1327101099Srwatson struct mac_biba *source, *dest; 1328101099Srwatson 1329101099Srwatson source = SLOT(oldmbuflabel); 1330101099Srwatson dest = SLOT(newmbuflabel); 1331101099Srwatson 1332132232Srwatson mac_biba_copy_effective(source, dest); 1333101099Srwatson} 1334101099Srwatson 1335101099Srwatsonstatic int 1336101099Srwatsonmac_biba_fragment_match(struct mbuf *fragment, struct label *fragmentlabel, 1337101099Srwatson struct ipq *ipq, struct label *ipqlabel) 1338101099Srwatson{ 1339101099Srwatson struct mac_biba *a, *b; 1340101099Srwatson 1341101099Srwatson a = SLOT(ipqlabel); 1342101099Srwatson b = SLOT(fragmentlabel); 1343101099Srwatson 1344132232Srwatson return (mac_biba_equal_effective(a, b)); 1345101099Srwatson} 1346101099Srwatson 1347101099Srwatsonstatic void 1348101099Srwatsonmac_biba_relabel_ifnet(struct ucred *cred, struct ifnet *ifnet, 1349101099Srwatson struct label *ifnetlabel, struct label *newlabel) 1350101099Srwatson{ 1351101099Srwatson struct mac_biba *source, *dest; 1352101099Srwatson 1353101099Srwatson source = SLOT(newlabel); 1354101099Srwatson dest = SLOT(ifnetlabel); 1355101099Srwatson 1356105656Srwatson mac_biba_copy(source, dest); 1357101099Srwatson} 1358101099Srwatson 1359101099Srwatsonstatic void 1360101099Srwatsonmac_biba_update_ipq(struct mbuf *fragment, struct label *fragmentlabel, 1361101099Srwatson struct ipq *ipq, struct label *ipqlabel) 1362101099Srwatson{ 1363101099Srwatson 1364101099Srwatson /* NOOP: we only accept matching labels, so no need to update */ 1365101099Srwatson} 1366101099Srwatson 1367122875Srwatsonstatic void 1368122875Srwatsonmac_biba_inpcb_sosetlabel(struct socket *so, struct label *solabel, 1369122875Srwatson struct inpcb *inp, struct label *inplabel) 1370122875Srwatson{ 1371122875Srwatson struct mac_biba *source, *dest; 1372122875Srwatson 1373122875Srwatson source = SLOT(solabel); 1374122875Srwatson dest = SLOT(inplabel); 1375122875Srwatson 1376122875Srwatson mac_biba_copy(source, dest); 1377122875Srwatson} 1378122875Srwatson 1379162238Scsjpstatic void 1380162238Scsjpmac_biba_create_mbuf_from_firewall(struct mbuf *m, struct label *label) 1381162238Scsjp{ 1382162238Scsjp struct mac_biba *dest; 1383162238Scsjp 1384162238Scsjp dest = SLOT(label); 1385162238Scsjp 1386162238Scsjp /* XXX: where is the label for the firewall really comming from? */ 1387162238Scsjp mac_biba_set_effective(dest, MAC_BIBA_TYPE_EQUAL, 0, NULL); 1388162238Scsjp} 1389162238Scsjp 1390101099Srwatson/* 1391101099Srwatson * Labeling event operations: processes. 1392101099Srwatson */ 1393101099Srwatsonstatic void 1394101099Srwatsonmac_biba_create_proc0(struct ucred *cred) 1395101099Srwatson{ 1396101099Srwatson struct mac_biba *dest; 1397101099Srwatson 1398122524Srwatson dest = SLOT(cred->cr_label); 1399101099Srwatson 1400132232Srwatson mac_biba_set_effective(dest, MAC_BIBA_TYPE_EQUAL, 0, NULL); 1401105643Srwatson mac_biba_set_range(dest, MAC_BIBA_TYPE_LOW, 0, NULL, 1402105643Srwatson MAC_BIBA_TYPE_HIGH, 0, NULL); 1403101099Srwatson} 1404101099Srwatson 1405101099Srwatsonstatic void 1406101099Srwatsonmac_biba_create_proc1(struct ucred *cred) 1407101099Srwatson{ 1408101099Srwatson struct mac_biba *dest; 1409101099Srwatson 1410122524Srwatson dest = SLOT(cred->cr_label); 1411101099Srwatson 1412132232Srwatson mac_biba_set_effective(dest, MAC_BIBA_TYPE_HIGH, 0, NULL); 1413105643Srwatson mac_biba_set_range(dest, MAC_BIBA_TYPE_LOW, 0, NULL, 1414105643Srwatson MAC_BIBA_TYPE_HIGH, 0, NULL); 1415101099Srwatson} 1416101099Srwatson 1417101099Srwatsonstatic void 1418101099Srwatsonmac_biba_relabel_cred(struct ucred *cred, struct label *newlabel) 1419101099Srwatson{ 1420101099Srwatson struct mac_biba *source, *dest; 1421101099Srwatson 1422101099Srwatson source = SLOT(newlabel); 1423122524Srwatson dest = SLOT(cred->cr_label); 1424101099Srwatson 1425105656Srwatson mac_biba_copy(source, dest); 1426101099Srwatson} 1427101099Srwatson 1428101099Srwatson/* 1429140628Srwatson * Label cleanup/flush operations 1430140628Srwatson */ 1431140628Srwatsonstatic void 1432140628Srwatsonmac_biba_cleanup_sysv_msgmsg(struct label *msglabel) 1433140628Srwatson{ 1434140628Srwatson 1435140628Srwatson bzero(SLOT(msglabel), sizeof(struct mac_biba)); 1436140628Srwatson} 1437140628Srwatson 1438140628Srwatsonstatic void 1439140628Srwatsonmac_biba_cleanup_sysv_msgqueue(struct label *msqlabel) 1440140628Srwatson{ 1441140628Srwatson 1442140628Srwatson bzero(SLOT(msqlabel), sizeof(struct mac_biba)); 1443140628Srwatson} 1444140628Srwatson 1445140628Srwatsonstatic void 1446147091Srwatsonmac_biba_cleanup_sysv_sem(struct label *semalabel) 1447140628Srwatson{ 1448140628Srwatson 1449140628Srwatson bzero(SLOT(semalabel), sizeof(struct mac_biba)); 1450140628Srwatson} 1451140628Srwatson 1452140628Srwatsonstatic void 1453140628Srwatsonmac_biba_cleanup_sysv_shm(struct label *shmlabel) 1454140628Srwatson{ 1455140628Srwatson bzero(SLOT(shmlabel), sizeof(struct mac_biba)); 1456140628Srwatson} 1457140628Srwatson 1458140628Srwatson/* 1459101099Srwatson * Access control checks. 1460101099Srwatson */ 1461101099Srwatsonstatic int 1462101099Srwatsonmac_biba_check_bpfdesc_receive(struct bpf_d *bpf_d, struct label *bpflabel, 1463101099Srwatson struct ifnet *ifnet, struct label *ifnetlabel) 1464101099Srwatson{ 1465101099Srwatson struct mac_biba *a, *b; 1466101099Srwatson 1467101099Srwatson if (!mac_biba_enabled) 1468101099Srwatson return (0); 1469101099Srwatson 1470101099Srwatson a = SLOT(bpflabel); 1471101099Srwatson b = SLOT(ifnetlabel); 1472101099Srwatson 1473132232Srwatson if (mac_biba_equal_effective(a, b)) 1474101099Srwatson return (0); 1475101099Srwatson return (EACCES); 1476101099Srwatson} 1477101099Srwatson 1478101099Srwatsonstatic int 1479101099Srwatsonmac_biba_check_cred_relabel(struct ucred *cred, struct label *newlabel) 1480101099Srwatson{ 1481101099Srwatson struct mac_biba *subj, *new; 1482105634Srwatson int error; 1483101099Srwatson 1484122524Srwatson subj = SLOT(cred->cr_label); 1485101099Srwatson new = SLOT(newlabel); 1486101099Srwatson 1487101099Srwatson /* 1488105634Srwatson * If there is a Biba label update for the credential, it may 1489132232Srwatson * be an update of the effective, range, or both. 1490101099Srwatson */ 1491105634Srwatson error = biba_atmostflags(new, MAC_BIBA_FLAGS_BOTH); 1492105634Srwatson if (error) 1493105634Srwatson return (error); 1494101099Srwatson 1495101099Srwatson /* 1496105634Srwatson * If the Biba label is to be changed, authorize as appropriate. 1497101099Srwatson */ 1498105634Srwatson if (new->mb_flags & MAC_BIBA_FLAGS_BOTH) { 1499105634Srwatson /* 1500110351Srwatson * If the change request modifies both the Biba label 1501132232Srwatson * effective and range, check that the new effective will be 1502110351Srwatson * in the new range. 1503110351Srwatson */ 1504110351Srwatson if ((new->mb_flags & MAC_BIBA_FLAGS_BOTH) == 1505110351Srwatson MAC_BIBA_FLAGS_BOTH && 1506132232Srwatson !mac_biba_effective_in_range(new, new)) 1507110351Srwatson return (EINVAL); 1508110351Srwatson 1509110351Srwatson /* 1510132232Srwatson * To change the Biba effective label on a credential, the 1511132232Srwatson * new effective label must be in the current range. 1512105634Srwatson */ 1513132232Srwatson if (new->mb_flags & MAC_BIBA_FLAG_EFFECTIVE && 1514132232Srwatson !mac_biba_effective_in_range(new, subj)) 1515105634Srwatson return (EPERM); 1516101099Srwatson 1517105634Srwatson /* 1518105634Srwatson * To change the Biba range on a credential, the new 1519105634Srwatson * range label must be in the current range. 1520105634Srwatson */ 1521105634Srwatson if (new->mb_flags & MAC_BIBA_FLAG_RANGE && 1522105634Srwatson !mac_biba_range_in_range(new, subj)) 1523105634Srwatson return (EPERM); 1524101099Srwatson 1525105634Srwatson /* 1526105634Srwatson * To have EQUAL in any component of the new credential 1527105634Srwatson * Biba label, the subject must already have EQUAL in 1528105634Srwatson * their label. 1529105634Srwatson */ 1530105634Srwatson if (mac_biba_contains_equal(new)) { 1531106090Srwatson error = mac_biba_subject_privileged(subj); 1532105634Srwatson if (error) 1533105634Srwatson return (error); 1534105634Srwatson } 1535105634Srwatson } 1536105634Srwatson 1537101099Srwatson return (0); 1538101099Srwatson} 1539101099Srwatson 1540101099Srwatsonstatic int 1541101099Srwatsonmac_biba_check_cred_visible(struct ucred *u1, struct ucred *u2) 1542101099Srwatson{ 1543101099Srwatson struct mac_biba *subj, *obj; 1544101099Srwatson 1545101099Srwatson if (!mac_biba_enabled) 1546101099Srwatson return (0); 1547101099Srwatson 1548122524Srwatson subj = SLOT(u1->cr_label); 1549122524Srwatson obj = SLOT(u2->cr_label); 1550101099Srwatson 1551101099Srwatson /* XXX: range */ 1552132232Srwatson if (!mac_biba_dominate_effective(obj, subj)) 1553101099Srwatson return (ESRCH); 1554101099Srwatson 1555101099Srwatson return (0); 1556101099Srwatson} 1557101099Srwatson 1558101099Srwatsonstatic int 1559101099Srwatsonmac_biba_check_ifnet_relabel(struct ucred *cred, struct ifnet *ifnet, 1560101099Srwatson struct label *ifnetlabel, struct label *newlabel) 1561101099Srwatson{ 1562101099Srwatson struct mac_biba *subj, *new; 1563105634Srwatson int error; 1564101099Srwatson 1565122524Srwatson subj = SLOT(cred->cr_label); 1566101099Srwatson new = SLOT(newlabel); 1567101099Srwatson 1568105634Srwatson /* 1569105634Srwatson * If there is a Biba label update for the interface, it may 1570132232Srwatson * be an update of the effective, range, or both. 1571105634Srwatson */ 1572105634Srwatson error = biba_atmostflags(new, MAC_BIBA_FLAGS_BOTH); 1573105634Srwatson if (error) 1574105634Srwatson return (error); 1575101099Srwatson 1576105634Srwatson /* 1577106160Srwatson * Relabling network interfaces requires Biba privilege. 1578106160Srwatson */ 1579106160Srwatson error = mac_biba_subject_privileged(subj); 1580106160Srwatson if (error) 1581106160Srwatson return (error); 1582106160Srwatson 1583105634Srwatson return (0); 1584101099Srwatson} 1585101099Srwatson 1586103759Srwatsonstatic int 1587101099Srwatsonmac_biba_check_ifnet_transmit(struct ifnet *ifnet, struct label *ifnetlabel, 1588101099Srwatson struct mbuf *m, struct label *mbuflabel) 1589101099Srwatson{ 1590101099Srwatson struct mac_biba *p, *i; 1591103761Srwatson 1592101099Srwatson if (!mac_biba_enabled) 1593101099Srwatson return (0); 1594101099Srwatson 1595101099Srwatson p = SLOT(mbuflabel); 1596101099Srwatson i = SLOT(ifnetlabel); 1597103759Srwatson 1598132232Srwatson return (mac_biba_effective_in_range(p, i) ? 0 : EACCES); 1599101099Srwatson} 1600101099Srwatson 1601101099Srwatsonstatic int 1602122875Srwatsonmac_biba_check_inpcb_deliver(struct inpcb *inp, struct label *inplabel, 1603122875Srwatson struct mbuf *m, struct label *mlabel) 1604122875Srwatson{ 1605122875Srwatson struct mac_biba *p, *i; 1606122875Srwatson 1607122875Srwatson if (!mac_biba_enabled) 1608122875Srwatson return (0); 1609122875Srwatson 1610122875Srwatson p = SLOT(mlabel); 1611122875Srwatson i = SLOT(inplabel); 1612122875Srwatson 1613132232Srwatson return (mac_biba_equal_effective(p, i) ? 0 : EACCES); 1614122875Srwatson} 1615122875Srwatson 1616122875Srwatsonstatic int 1617140628Srwatsonmac_biba_check_sysv_msgrcv(struct ucred *cred, struct msg *msgptr, 1618140628Srwatson struct label *msglabel) 1619140628Srwatson{ 1620140628Srwatson struct mac_biba *subj, *obj; 1621140628Srwatson 1622140628Srwatson if (!mac_biba_enabled) 1623140628Srwatson return (0); 1624140628Srwatson 1625140628Srwatson subj = SLOT(cred->cr_label); 1626140628Srwatson obj = SLOT(msglabel); 1627140628Srwatson 1628140628Srwatson if (!mac_biba_dominate_effective(obj, subj)) 1629140628Srwatson return (EACCES); 1630140628Srwatson 1631140628Srwatson return (0); 1632140628Srwatson} 1633140628Srwatson 1634140628Srwatsonstatic int 1635140628Srwatsonmac_biba_check_sysv_msgrmid(struct ucred *cred, struct msg *msgptr, 1636140628Srwatson struct label *msglabel) 1637140628Srwatson{ 1638140628Srwatson struct mac_biba *subj, *obj; 1639140628Srwatson 1640140628Srwatson if (!mac_biba_enabled) 1641140628Srwatson return (0); 1642140628Srwatson 1643140628Srwatson subj = SLOT(cred->cr_label); 1644140628Srwatson obj = SLOT(msglabel); 1645140628Srwatson 1646140628Srwatson if (!mac_biba_dominate_effective(subj, obj)) 1647140628Srwatson return (EACCES); 1648140628Srwatson 1649140628Srwatson return (0); 1650140628Srwatson} 1651140628Srwatson 1652140628Srwatsonstatic int 1653140628Srwatsonmac_biba_check_sysv_msqget(struct ucred *cred, struct msqid_kernel *msqkptr, 1654140628Srwatson struct label *msqklabel) 1655140628Srwatson{ 1656140628Srwatson struct mac_biba *subj, *obj; 1657140628Srwatson 1658140628Srwatson if (!mac_biba_enabled) 1659140628Srwatson return (0); 1660140628Srwatson 1661140628Srwatson subj = SLOT(cred->cr_label); 1662140628Srwatson obj = SLOT(msqklabel); 1663140628Srwatson 1664140628Srwatson if (!mac_biba_dominate_effective(obj, subj)) 1665140628Srwatson return (EACCES); 1666140628Srwatson 1667140628Srwatson return (0); 1668140628Srwatson} 1669140628Srwatson 1670140628Srwatsonstatic int 1671140628Srwatsonmac_biba_check_sysv_msqsnd(struct ucred *cred, struct msqid_kernel *msqkptr, 1672140628Srwatson struct label *msqklabel) 1673140628Srwatson{ 1674140628Srwatson struct mac_biba *subj, *obj; 1675140628Srwatson 1676140628Srwatson if (!mac_biba_enabled) 1677140628Srwatson return (0); 1678140628Srwatson 1679140628Srwatson subj = SLOT(cred->cr_label); 1680140628Srwatson obj = SLOT(msqklabel); 1681140628Srwatson 1682140628Srwatson if (!mac_biba_dominate_effective(subj, obj)) 1683140628Srwatson return (EACCES); 1684140628Srwatson 1685140628Srwatson return (0); 1686140628Srwatson} 1687140628Srwatson 1688140628Srwatsonstatic int 1689140628Srwatsonmac_biba_check_sysv_msqrcv(struct ucred *cred, struct msqid_kernel *msqkptr, 1690140628Srwatson struct label *msqklabel) 1691140628Srwatson{ 1692140628Srwatson struct mac_biba *subj, *obj; 1693140628Srwatson 1694140628Srwatson if (!mac_biba_enabled) 1695140628Srwatson return (0); 1696140628Srwatson 1697140628Srwatson subj = SLOT(cred->cr_label); 1698140628Srwatson obj = SLOT(msqklabel); 1699140628Srwatson 1700140628Srwatson if (!mac_biba_dominate_effective(obj, subj)) 1701140628Srwatson return (EACCES); 1702140628Srwatson 1703140628Srwatson return (0); 1704140628Srwatson} 1705140628Srwatson 1706140628Srwatson 1707140628Srwatsonstatic int 1708140628Srwatsonmac_biba_check_sysv_msqctl(struct ucred *cred, struct msqid_kernel *msqkptr, 1709140628Srwatson struct label *msqklabel, int cmd) 1710140628Srwatson{ 1711140628Srwatson struct mac_biba *subj, *obj; 1712140628Srwatson 1713140628Srwatson if (!mac_biba_enabled) 1714140628Srwatson return (0); 1715140628Srwatson 1716140628Srwatson subj = SLOT(cred->cr_label); 1717140628Srwatson obj = SLOT(msqklabel); 1718140628Srwatson 1719140628Srwatson switch(cmd) { 1720140628Srwatson case IPC_RMID: 1721140628Srwatson case IPC_SET: 1722140628Srwatson if (!mac_biba_dominate_effective(subj, obj)) 1723140628Srwatson return (EACCES); 1724140628Srwatson break; 1725140628Srwatson 1726140628Srwatson case IPC_STAT: 1727140628Srwatson if (!mac_biba_dominate_effective(obj, subj)) 1728140628Srwatson return (EACCES); 1729140628Srwatson break; 1730140628Srwatson 1731140628Srwatson default: 1732140628Srwatson return (EACCES); 1733140628Srwatson } 1734140628Srwatson 1735140628Srwatson return (0); 1736140628Srwatson} 1737140628Srwatson 1738140628Srwatsonstatic int 1739140628Srwatsonmac_biba_check_sysv_semctl(struct ucred *cred, struct semid_kernel *semakptr, 1740140628Srwatson struct label *semaklabel, int cmd) 1741140628Srwatson{ 1742140628Srwatson struct mac_biba *subj, *obj; 1743140628Srwatson 1744140628Srwatson if (!mac_biba_enabled) 1745140628Srwatson return (0); 1746140628Srwatson 1747140628Srwatson subj = SLOT(cred->cr_label); 1748140628Srwatson obj = SLOT(semaklabel); 1749140628Srwatson 1750140628Srwatson switch(cmd) { 1751140628Srwatson case IPC_RMID: 1752140628Srwatson case IPC_SET: 1753140628Srwatson case SETVAL: 1754140628Srwatson case SETALL: 1755140628Srwatson if (!mac_biba_dominate_effective(subj, obj)) 1756140628Srwatson return (EACCES); 1757140628Srwatson break; 1758140628Srwatson 1759140628Srwatson case IPC_STAT: 1760140628Srwatson case GETVAL: 1761140628Srwatson case GETPID: 1762140628Srwatson case GETNCNT: 1763140628Srwatson case GETZCNT: 1764140628Srwatson case GETALL: 1765140628Srwatson if (!mac_biba_dominate_effective(obj, subj)) 1766140628Srwatson return (EACCES); 1767140628Srwatson break; 1768140628Srwatson 1769140628Srwatson default: 1770140628Srwatson return (EACCES); 1771140628Srwatson } 1772140628Srwatson 1773140628Srwatson return (0); 1774140628Srwatson} 1775140628Srwatson 1776140628Srwatson 1777140628Srwatsonstatic int 1778140628Srwatsonmac_biba_check_sysv_semget(struct ucred *cred, struct semid_kernel *semakptr, 1779140628Srwatson struct label *semaklabel) 1780140628Srwatson{ 1781140628Srwatson struct mac_biba *subj, *obj; 1782140628Srwatson 1783140628Srwatson if (!mac_biba_enabled) 1784140628Srwatson return (0); 1785140628Srwatson 1786140628Srwatson subj = SLOT(cred->cr_label); 1787140628Srwatson obj = SLOT(semaklabel); 1788140628Srwatson 1789140628Srwatson if (!mac_biba_dominate_effective(obj, subj)) 1790140628Srwatson return (EACCES); 1791140628Srwatson 1792140628Srwatson return (0); 1793140628Srwatson} 1794140628Srwatson 1795140628Srwatson 1796140628Srwatsonstatic int 1797140628Srwatsonmac_biba_check_sysv_semop(struct ucred *cred, struct semid_kernel *semakptr, 1798140628Srwatson struct label *semaklabel, size_t accesstype) 1799140628Srwatson{ 1800140628Srwatson struct mac_biba *subj, *obj; 1801140628Srwatson 1802140628Srwatson if (!mac_biba_enabled) 1803140628Srwatson return (0); 1804140628Srwatson 1805140628Srwatson subj = SLOT(cred->cr_label); 1806140628Srwatson obj = SLOT(semaklabel); 1807140628Srwatson 1808140628Srwatson if (accesstype & SEM_R) 1809140628Srwatson if (!mac_biba_dominate_effective(obj, subj)) 1810140628Srwatson return (EACCES); 1811140628Srwatson 1812140628Srwatson if (accesstype & SEM_A) 1813140628Srwatson if (!mac_biba_dominate_effective(subj, obj)) 1814140628Srwatson return (EACCES); 1815140628Srwatson 1816140628Srwatson return (0); 1817140628Srwatson} 1818140628Srwatson 1819140628Srwatsonstatic int 1820140628Srwatsonmac_biba_check_sysv_shmat(struct ucred *cred, struct shmid_kernel *shmsegptr, 1821140628Srwatson struct label *shmseglabel, int shmflg) 1822140628Srwatson{ 1823140628Srwatson struct mac_biba *subj, *obj; 1824140628Srwatson 1825140628Srwatson if (!mac_biba_enabled) 1826140628Srwatson return (0); 1827140628Srwatson 1828140628Srwatson subj = SLOT(cred->cr_label); 1829140628Srwatson obj = SLOT(shmseglabel); 1830140628Srwatson 1831140628Srwatson if (!mac_biba_dominate_effective(obj, subj)) 1832140628Srwatson return (EACCES); 1833140628Srwatson if ((shmflg & SHM_RDONLY) == 0) { 1834140628Srwatson if (!mac_biba_dominate_effective(subj, obj)) 1835140628Srwatson return (EACCES); 1836140628Srwatson } 1837140628Srwatson 1838140628Srwatson return (0); 1839140628Srwatson} 1840140628Srwatson 1841140628Srwatsonstatic int 1842140628Srwatsonmac_biba_check_sysv_shmctl(struct ucred *cred, struct shmid_kernel *shmsegptr, 1843140628Srwatson struct label *shmseglabel, int cmd) 1844140628Srwatson{ 1845140628Srwatson struct mac_biba *subj, *obj; 1846140628Srwatson 1847140628Srwatson if (!mac_biba_enabled) 1848140628Srwatson return (0); 1849140628Srwatson 1850140628Srwatson subj = SLOT(cred->cr_label); 1851140628Srwatson obj = SLOT(shmseglabel); 1852140628Srwatson 1853140628Srwatson switch(cmd) { 1854140628Srwatson case IPC_RMID: 1855140628Srwatson case IPC_SET: 1856140628Srwatson if (!mac_biba_dominate_effective(subj, obj)) 1857140628Srwatson return (EACCES); 1858140628Srwatson break; 1859140628Srwatson 1860140628Srwatson case IPC_STAT: 1861140628Srwatson case SHM_STAT: 1862140628Srwatson if (!mac_biba_dominate_effective(obj, subj)) 1863140628Srwatson return (EACCES); 1864140628Srwatson break; 1865140628Srwatson 1866140628Srwatson default: 1867140628Srwatson return (EACCES); 1868140628Srwatson } 1869140628Srwatson 1870140628Srwatson return (0); 1871140628Srwatson} 1872140628Srwatson 1873140628Srwatsonstatic int 1874140628Srwatsonmac_biba_check_sysv_shmget(struct ucred *cred, struct shmid_kernel *shmsegptr, 1875140628Srwatson struct label *shmseglabel, int shmflg) 1876140628Srwatson{ 1877140628Srwatson struct mac_biba *subj, *obj; 1878140628Srwatson 1879140628Srwatson if (!mac_biba_enabled) 1880140628Srwatson return (0); 1881140628Srwatson 1882140628Srwatson subj = SLOT(cred->cr_label); 1883140628Srwatson obj = SLOT(shmseglabel); 1884140628Srwatson 1885140628Srwatson if (!mac_biba_dominate_effective(obj, subj)) 1886140628Srwatson return (EACCES); 1887140628Srwatson 1888140628Srwatson return (0); 1889140628Srwatson} 1890140628Srwatson 1891140628Srwatsonstatic int 1892110354Srwatsonmac_biba_check_kld_load(struct ucred *cred, struct vnode *vp, 1893110354Srwatson struct label *label) 1894110354Srwatson{ 1895110354Srwatson struct mac_biba *subj, *obj; 1896110354Srwatson int error; 1897110354Srwatson 1898110354Srwatson if (!mac_biba_enabled) 1899110354Srwatson return (0); 1900110354Srwatson 1901122524Srwatson subj = SLOT(cred->cr_label); 1902110354Srwatson 1903110354Srwatson error = mac_biba_subject_privileged(subj); 1904110354Srwatson if (error) 1905110354Srwatson return (error); 1906110354Srwatson 1907110354Srwatson obj = SLOT(label); 1908132232Srwatson if (!mac_biba_high_effective(obj)) 1909110354Srwatson return (EACCES); 1910110354Srwatson 1911110354Srwatson return (0); 1912110354Srwatson} 1913110354Srwatson 1914110354Srwatson 1915110354Srwatsonstatic int 1916101099Srwatsonmac_biba_check_mount_stat(struct ucred *cred, struct mount *mp, 1917101099Srwatson struct label *mntlabel) 1918101099Srwatson{ 1919101099Srwatson struct mac_biba *subj, *obj; 1920101099Srwatson 1921101099Srwatson if (!mac_biba_enabled) 1922101099Srwatson return (0); 1923101099Srwatson 1924122524Srwatson subj = SLOT(cred->cr_label); 1925101099Srwatson obj = SLOT(mntlabel); 1926101099Srwatson 1927132232Srwatson if (!mac_biba_dominate_effective(obj, subj)) 1928101099Srwatson return (EACCES); 1929101099Srwatson 1930101099Srwatson return (0); 1931101099Srwatson} 1932101099Srwatson 1933101099Srwatsonstatic int 1934125293Srwatsonmac_biba_check_pipe_ioctl(struct ucred *cred, struct pipepair *pp, 1935101099Srwatson struct label *pipelabel, unsigned long cmd, void /* caddr_t */ *data) 1936101099Srwatson{ 1937103759Srwatson 1938101099Srwatson if(!mac_biba_enabled) 1939101099Srwatson return (0); 1940101099Srwatson 1941101099Srwatson /* XXX: This will be implemented soon... */ 1942101099Srwatson 1943101099Srwatson return (0); 1944101099Srwatson} 1945101099Srwatson 1946101099Srwatsonstatic int 1947125293Srwatsonmac_biba_check_pipe_poll(struct ucred *cred, struct pipepair *pp, 1948102115Srwatson struct label *pipelabel) 1949101099Srwatson{ 1950101099Srwatson struct mac_biba *subj, *obj; 1951101099Srwatson 1952101099Srwatson if (!mac_biba_enabled) 1953101099Srwatson return (0); 1954101099Srwatson 1955122524Srwatson subj = SLOT(cred->cr_label); 1956101099Srwatson obj = SLOT((pipelabel)); 1957101099Srwatson 1958132232Srwatson if (!mac_biba_dominate_effective(obj, subj)) 1959102115Srwatson return (EACCES); 1960101099Srwatson 1961101099Srwatson return (0); 1962101099Srwatson} 1963101099Srwatson 1964101099Srwatsonstatic int 1965125293Srwatsonmac_biba_check_pipe_read(struct ucred *cred, struct pipepair *pp, 1966102115Srwatson struct label *pipelabel) 1967102115Srwatson{ 1968102115Srwatson struct mac_biba *subj, *obj; 1969102115Srwatson 1970102115Srwatson if (!mac_biba_enabled) 1971102115Srwatson return (0); 1972102115Srwatson 1973122524Srwatson subj = SLOT(cred->cr_label); 1974102115Srwatson obj = SLOT((pipelabel)); 1975102115Srwatson 1976132232Srwatson if (!mac_biba_dominate_effective(obj, subj)) 1977102115Srwatson return (EACCES); 1978102115Srwatson 1979102115Srwatson return (0); 1980102115Srwatson} 1981102115Srwatson 1982102115Srwatsonstatic int 1983125293Srwatsonmac_biba_check_pipe_relabel(struct ucred *cred, struct pipepair *pp, 1984101099Srwatson struct label *pipelabel, struct label *newlabel) 1985101099Srwatson{ 1986101099Srwatson struct mac_biba *subj, *obj, *new; 1987105634Srwatson int error; 1988101099Srwatson 1989101099Srwatson new = SLOT(newlabel); 1990122524Srwatson subj = SLOT(cred->cr_label); 1991101099Srwatson obj = SLOT(pipelabel); 1992101099Srwatson 1993101099Srwatson /* 1994105634Srwatson * If there is a Biba label update for a pipe, it must be a 1995132232Srwatson * effective update. 1996101099Srwatson */ 1997132232Srwatson error = biba_atmostflags(new, MAC_BIBA_FLAG_EFFECTIVE); 1998105634Srwatson if (error) 1999105634Srwatson return (error); 2000101099Srwatson 2001101099Srwatson /* 2002105634Srwatson * To perform a relabel of a pipe (Biba label or not), Biba must 2003105634Srwatson * authorize the relabel. 2004101099Srwatson */ 2005132232Srwatson if (!mac_biba_effective_in_range(obj, subj)) 2006101099Srwatson return (EPERM); 2007101099Srwatson 2008101099Srwatson /* 2009105634Srwatson * If the Biba label is to be changed, authorize as appropriate. 2010101099Srwatson */ 2011132232Srwatson if (new->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) { 2012105634Srwatson /* 2013105634Srwatson * To change the Biba label on a pipe, the new pipe label 2014105634Srwatson * must be in the subject range. 2015105634Srwatson */ 2016132232Srwatson if (!mac_biba_effective_in_range(new, subj)) 2017105634Srwatson return (EPERM); 2018101099Srwatson 2019105634Srwatson /* 2020105634Srwatson * To change the Biba label on a pipe to be EQUAL, the 2021105634Srwatson * subject must have appropriate privilege. 2022105634Srwatson */ 2023105634Srwatson if (mac_biba_contains_equal(new)) { 2024106090Srwatson error = mac_biba_subject_privileged(subj); 2025105634Srwatson if (error) 2026105634Srwatson return (error); 2027105634Srwatson } 2028105634Srwatson } 2029105634Srwatson 2030101099Srwatson return (0); 2031101099Srwatson} 2032101099Srwatson 2033101099Srwatsonstatic int 2034125293Srwatsonmac_biba_check_pipe_stat(struct ucred *cred, struct pipepair *pp, 2035102115Srwatson struct label *pipelabel) 2036102115Srwatson{ 2037102115Srwatson struct mac_biba *subj, *obj; 2038102115Srwatson 2039102115Srwatson if (!mac_biba_enabled) 2040102115Srwatson return (0); 2041102115Srwatson 2042122524Srwatson subj = SLOT(cred->cr_label); 2043102115Srwatson obj = SLOT((pipelabel)); 2044102115Srwatson 2045132232Srwatson if (!mac_biba_dominate_effective(obj, subj)) 2046102115Srwatson return (EACCES); 2047102115Srwatson 2048102115Srwatson return (0); 2049102115Srwatson} 2050102115Srwatson 2051102115Srwatsonstatic int 2052125293Srwatsonmac_biba_check_pipe_write(struct ucred *cred, struct pipepair *pp, 2053102115Srwatson struct label *pipelabel) 2054102115Srwatson{ 2055102115Srwatson struct mac_biba *subj, *obj; 2056102115Srwatson 2057102115Srwatson if (!mac_biba_enabled) 2058102115Srwatson return (0); 2059102115Srwatson 2060122524Srwatson subj = SLOT(cred->cr_label); 2061102115Srwatson obj = SLOT((pipelabel)); 2062102115Srwatson 2063132232Srwatson if (!mac_biba_dominate_effective(subj, obj)) 2064102115Srwatson return (EACCES); 2065102115Srwatson 2066102115Srwatson return (0); 2067102115Srwatson} 2068102115Srwatson 2069102115Srwatsonstatic int 2070145855Srwatsonmac_biba_check_posix_sem_write(struct ucred *cred, struct ksem *ksemptr, 2071145855Srwatson struct label *ks_label) 2072145855Srwatson{ 2073145855Srwatson struct mac_biba *subj, *obj; 2074145855Srwatson 2075145855Srwatson if (!mac_biba_enabled) 2076145855Srwatson return (0); 2077145855Srwatson 2078145855Srwatson subj = SLOT(cred->cr_label); 2079145855Srwatson obj = SLOT(ks_label); 2080145855Srwatson 2081145855Srwatson if (!mac_biba_dominate_effective(subj, obj)) 2082145855Srwatson return (EACCES); 2083145855Srwatson 2084145855Srwatson return (0); 2085145855Srwatson} 2086145855Srwatson 2087145855Srwatsonstatic int 2088145855Srwatsonmac_biba_check_posix_sem_rdonly(struct ucred *cred, struct ksem *ksemptr, 2089145855Srwatson struct label *ks_label) 2090145855Srwatson{ 2091145855Srwatson struct mac_biba *subj, *obj; 2092145855Srwatson 2093145855Srwatson if (!mac_biba_enabled) 2094145855Srwatson return (0); 2095145855Srwatson 2096145855Srwatson subj = SLOT(cred->cr_label); 2097145855Srwatson obj = SLOT(ks_label); 2098145855Srwatson 2099145855Srwatson if (!mac_biba_dominate_effective(obj, subj)) 2100145855Srwatson return (EACCES); 2101145855Srwatson 2102145855Srwatson return (0); 2103145855Srwatson} 2104145855Srwatson 2105145855Srwatsonstatic int 2106101099Srwatsonmac_biba_check_proc_debug(struct ucred *cred, struct proc *proc) 2107101099Srwatson{ 2108101099Srwatson struct mac_biba *subj, *obj; 2109101099Srwatson 2110101099Srwatson if (!mac_biba_enabled) 2111101099Srwatson return (0); 2112101099Srwatson 2113122524Srwatson subj = SLOT(cred->cr_label); 2114122524Srwatson obj = SLOT(proc->p_ucred->cr_label); 2115101099Srwatson 2116101099Srwatson /* XXX: range checks */ 2117132232Srwatson if (!mac_biba_dominate_effective(obj, subj)) 2118101099Srwatson return (ESRCH); 2119132232Srwatson if (!mac_biba_dominate_effective(subj, obj)) 2120101099Srwatson return (EACCES); 2121101099Srwatson 2122101099Srwatson return (0); 2123101099Srwatson} 2124101099Srwatson 2125101099Srwatsonstatic int 2126101099Srwatsonmac_biba_check_proc_sched(struct ucred *cred, struct proc *proc) 2127101099Srwatson{ 2128101099Srwatson struct mac_biba *subj, *obj; 2129103759Srwatson 2130101099Srwatson if (!mac_biba_enabled) 2131101099Srwatson return (0); 2132101099Srwatson 2133122524Srwatson subj = SLOT(cred->cr_label); 2134122524Srwatson obj = SLOT(proc->p_ucred->cr_label); 2135103759Srwatson 2136101099Srwatson /* XXX: range checks */ 2137132232Srwatson if (!mac_biba_dominate_effective(obj, subj)) 2138101099Srwatson return (ESRCH); 2139132232Srwatson if (!mac_biba_dominate_effective(subj, obj)) 2140101099Srwatson return (EACCES); 2141101099Srwatson 2142101099Srwatson return (0); 2143101099Srwatson} 2144101099Srwatson 2145101099Srwatsonstatic int 2146101099Srwatsonmac_biba_check_proc_signal(struct ucred *cred, struct proc *proc, int signum) 2147101099Srwatson{ 2148101099Srwatson struct mac_biba *subj, *obj; 2149103759Srwatson 2150101099Srwatson if (!mac_biba_enabled) 2151101099Srwatson return (0); 2152101099Srwatson 2153122524Srwatson subj = SLOT(cred->cr_label); 2154122524Srwatson obj = SLOT(proc->p_ucred->cr_label); 2155103759Srwatson 2156101099Srwatson /* XXX: range checks */ 2157132232Srwatson if (!mac_biba_dominate_effective(obj, subj)) 2158101099Srwatson return (ESRCH); 2159132232Srwatson if (!mac_biba_dominate_effective(subj, obj)) 2160101099Srwatson return (EACCES); 2161101099Srwatson 2162101099Srwatson return (0); 2163101099Srwatson} 2164101099Srwatson 2165101099Srwatsonstatic int 2166101934Srwatsonmac_biba_check_socket_deliver(struct socket *so, struct label *socketlabel, 2167101099Srwatson struct mbuf *m, struct label *mbuflabel) 2168101099Srwatson{ 2169101099Srwatson struct mac_biba *p, *s; 2170101099Srwatson 2171101099Srwatson if (!mac_biba_enabled) 2172101099Srwatson return (0); 2173101099Srwatson 2174101099Srwatson p = SLOT(mbuflabel); 2175101099Srwatson s = SLOT(socketlabel); 2176101099Srwatson 2177132232Srwatson return (mac_biba_equal_effective(p, s) ? 0 : EACCES); 2178101099Srwatson} 2179101099Srwatson 2180101099Srwatsonstatic int 2181106214Srwatsonmac_biba_check_socket_relabel(struct ucred *cred, struct socket *so, 2182101099Srwatson struct label *socketlabel, struct label *newlabel) 2183101099Srwatson{ 2184101099Srwatson struct mac_biba *subj, *obj, *new; 2185105634Srwatson int error; 2186101099Srwatson 2187101099Srwatson new = SLOT(newlabel); 2188122524Srwatson subj = SLOT(cred->cr_label); 2189101099Srwatson obj = SLOT(socketlabel); 2190101099Srwatson 2191101099Srwatson /* 2192105634Srwatson * If there is a Biba label update for the socket, it may be 2193132232Srwatson * an update of effective. 2194101099Srwatson */ 2195132232Srwatson error = biba_atmostflags(new, MAC_BIBA_FLAG_EFFECTIVE); 2196105634Srwatson if (error) 2197105634Srwatson return (error); 2198101099Srwatson 2199101099Srwatson /* 2200132232Srwatson * To relabel a socket, the old socket effective must be in the subject 2201101099Srwatson * range. 2202101099Srwatson */ 2203132232Srwatson if (!mac_biba_effective_in_range(obj, subj)) 2204101099Srwatson return (EPERM); 2205101099Srwatson 2206101099Srwatson /* 2207105634Srwatson * If the Biba label is to be changed, authorize as appropriate. 2208101099Srwatson */ 2209132232Srwatson if (new->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) { 2210105634Srwatson /* 2211132232Srwatson * To relabel a socket, the new socket effective must be in 2212105634Srwatson * the subject range. 2213105634Srwatson */ 2214132232Srwatson if (!mac_biba_effective_in_range(new, subj)) 2215105634Srwatson return (EPERM); 2216101099Srwatson 2217105634Srwatson /* 2218105634Srwatson * To change the Biba label on the socket to contain EQUAL, 2219105634Srwatson * the subject must have appropriate privilege. 2220105634Srwatson */ 2221105634Srwatson if (mac_biba_contains_equal(new)) { 2222106090Srwatson error = mac_biba_subject_privileged(subj); 2223105634Srwatson if (error) 2224105634Srwatson return (error); 2225105634Srwatson } 2226105634Srwatson } 2227105634Srwatson 2228101099Srwatson return (0); 2229101099Srwatson} 2230101099Srwatson 2231101099Srwatsonstatic int 2232101099Srwatsonmac_biba_check_socket_visible(struct ucred *cred, struct socket *socket, 2233101099Srwatson struct label *socketlabel) 2234101099Srwatson{ 2235101099Srwatson struct mac_biba *subj, *obj; 2236101099Srwatson 2237105722Srwatson if (!mac_biba_enabled) 2238105722Srwatson return (0); 2239105722Srwatson 2240122524Srwatson subj = SLOT(cred->cr_label); 2241101099Srwatson obj = SLOT(socketlabel); 2242101099Srwatson 2243132232Srwatson if (!mac_biba_dominate_effective(obj, subj)) 2244101099Srwatson return (ENOENT); 2245101099Srwatson 2246101099Srwatson return (0); 2247101099Srwatson} 2248101099Srwatson 2249168951Srwatson/* 2250168951Srwatson * Some system privileges are allowed regardless of integrity grade; others 2251168951Srwatson * are allowed only when running with privilege with respect to the Biba 2252168951Srwatson * policy as they might otherwise allow bypassing of the integrity policy. 2253168951Srwatson */ 2254101099Srwatsonstatic int 2255168951Srwatsonmac_biba_priv_check(struct ucred *cred, int priv) 2256112574Srwatson{ 2257112574Srwatson struct mac_biba *subj; 2258112574Srwatson int error; 2259112574Srwatson 2260112574Srwatson if (!mac_biba_enabled) 2261112574Srwatson return (0); 2262112574Srwatson 2263168951Srwatson /* 2264168951Srwatson * Exempt only specific privileges from the Biba integrity policy. 2265168951Srwatson */ 2266168951Srwatson switch (priv) { 2267168951Srwatson case PRIV_KTRACE: 2268168951Srwatson case PRIV_MSGBUF: 2269112574Srwatson 2270168951Srwatson /* 2271168951Srwatson * Allow processes to manipulate basic process audit properties, and 2272168951Srwatson * to submit audit records. 2273168951Srwatson */ 2274168951Srwatson case PRIV_AUDIT_GETAUDIT: 2275168951Srwatson case PRIV_AUDIT_SETAUDIT: 2276168951Srwatson case PRIV_AUDIT_SUBMIT: 2277112574Srwatson 2278168951Srwatson /* 2279168951Srwatson * Allow processes to manipulate their regular UNIX credentials. 2280168951Srwatson */ 2281168951Srwatson case PRIV_CRED_SETUID: 2282168951Srwatson case PRIV_CRED_SETEUID: 2283168951Srwatson case PRIV_CRED_SETGID: 2284168951Srwatson case PRIV_CRED_SETEGID: 2285168951Srwatson case PRIV_CRED_SETGROUPS: 2286168951Srwatson case PRIV_CRED_SETREUID: 2287168951Srwatson case PRIV_CRED_SETREGID: 2288168951Srwatson case PRIV_CRED_SETRESUID: 2289168951Srwatson case PRIV_CRED_SETRESGID: 2290168951Srwatson 2291168951Srwatson /* 2292168951Srwatson * Allow processes to perform system monitoring. 2293168951Srwatson */ 2294168951Srwatson case PRIV_SEEOTHERGIDS: 2295168951Srwatson case PRIV_SEEOTHERUIDS: 2296168951Srwatson break; 2297168951Srwatson 2298168951Srwatson /* 2299168951Srwatson * Allow access to general process debugging facilities. We 2300168951Srwatson * separately control debugging based on MAC label. 2301168951Srwatson */ 2302168951Srwatson case PRIV_DEBUG_DIFFCRED: 2303168951Srwatson case PRIV_DEBUG_SUGID: 2304168951Srwatson case PRIV_DEBUG_UNPRIV: 2305168951Srwatson 2306168951Srwatson /* 2307168951Srwatson * Allow manipulating jails. 2308168951Srwatson */ 2309168951Srwatson case PRIV_JAIL_ATTACH: 2310168951Srwatson 2311168951Srwatson /* 2312168951Srwatson * Allow privilege with respect to the Partition policy, but not the 2313168951Srwatson * Privs policy. 2314168951Srwatson */ 2315168951Srwatson case PRIV_MAC_PARTITION: 2316168951Srwatson 2317168951Srwatson /* 2318168951Srwatson * Allow privilege with respect to process resource limits and login 2319168951Srwatson * context. 2320168951Srwatson */ 2321168951Srwatson case PRIV_PROC_LIMIT: 2322168951Srwatson case PRIV_PROC_SETLOGIN: 2323168951Srwatson case PRIV_PROC_SETRLIMIT: 2324168951Srwatson 2325168951Srwatson /* 2326168951Srwatson * Allow System V and POSIX IPC privileges. 2327168951Srwatson */ 2328168951Srwatson case PRIV_IPC_READ: 2329168951Srwatson case PRIV_IPC_WRITE: 2330168951Srwatson case PRIV_IPC_ADMIN: 2331168951Srwatson case PRIV_IPC_MSGSIZE: 2332168951Srwatson case PRIV_MQ_ADMIN: 2333168951Srwatson 2334168951Srwatson /* 2335168951Srwatson * Allow certain scheduler manipulations -- possibly this should be 2336168951Srwatson * controlled by more fine-grained policy, as potentially low 2337168951Srwatson * integrity processes can deny CPU to higher integrity ones. 2338168951Srwatson */ 2339168951Srwatson case PRIV_SCHED_DIFFCRED: 2340168951Srwatson case PRIV_SCHED_SETPRIORITY: 2341168951Srwatson case PRIV_SCHED_RTPRIO: 2342168951Srwatson case PRIV_SCHED_SETPOLICY: 2343168951Srwatson case PRIV_SCHED_SET: 2344168951Srwatson case PRIV_SCHED_SETPARAM: 2345168951Srwatson 2346168951Srwatson /* 2347168951Srwatson * More IPC privileges. 2348168951Srwatson */ 2349168951Srwatson case PRIV_SEM_WRITE: 2350168951Srwatson 2351168951Srwatson /* 2352168951Srwatson * Allow signaling privileges subject to integrity policy. 2353168951Srwatson */ 2354168951Srwatson case PRIV_SIGNAL_DIFFCRED: 2355168951Srwatson case PRIV_SIGNAL_SUGID: 2356168951Srwatson 2357168951Srwatson /* 2358168951Srwatson * Allow access to only limited sysctls from lower integrity levels; 2359168951Srwatson * piggy-back on the Jail definition. 2360168951Srwatson */ 2361168951Srwatson case PRIV_SYSCTL_WRITEJAIL: 2362168951Srwatson 2363168951Srwatson /* 2364168951Srwatson * Allow TTY-based privileges, subject to general device access using 2365168951Srwatson * labels on TTY device nodes, but not console privilege. 2366168951Srwatson */ 2367168951Srwatson case PRIV_TTY_DRAINWAIT: 2368168951Srwatson case PRIV_TTY_DTRWAIT: 2369168951Srwatson case PRIV_TTY_EXCLUSIVE: 2370168951Srwatson case PRIV_TTY_PRISON: 2371168951Srwatson case PRIV_TTY_STI: 2372168951Srwatson case PRIV_TTY_SETA: 2373168951Srwatson 2374168951Srwatson /* 2375168951Srwatson * Grant most VFS privileges, as almost all are in practice bounded 2376168951Srwatson * by more specific checks using labels. 2377168951Srwatson */ 2378168951Srwatson case PRIV_VFS_READ: 2379168951Srwatson case PRIV_VFS_WRITE: 2380168951Srwatson case PRIV_VFS_ADMIN: 2381168951Srwatson case PRIV_VFS_EXEC: 2382168951Srwatson case PRIV_VFS_LOOKUP: 2383168951Srwatson case PRIV_VFS_CHFLAGS_DEV: 2384168951Srwatson case PRIV_VFS_CHOWN: 2385168951Srwatson case PRIV_VFS_CHROOT: 2386168951Srwatson case PRIV_VFS_RETAINSUGID: 2387168951Srwatson case PRIV_VFS_EXCEEDQUOTA: 2388168951Srwatson case PRIV_VFS_FCHROOT: 2389168951Srwatson case PRIV_VFS_FHOPEN: 2390168951Srwatson case PRIV_VFS_FHSTATFS: 2391168951Srwatson case PRIV_VFS_GENERATION: 2392168951Srwatson case PRIV_VFS_GETFH: 2393168951Srwatson case PRIV_VFS_GETQUOTA: 2394168951Srwatson case PRIV_VFS_LINK: 2395168951Srwatson case PRIV_VFS_MOUNT: 2396168951Srwatson case PRIV_VFS_MOUNT_OWNER: 2397168951Srwatson case PRIV_VFS_MOUNT_PERM: 2398168951Srwatson case PRIV_VFS_MOUNT_SUIDDIR: 2399168951Srwatson case PRIV_VFS_MOUNT_NONUSER: 2400168951Srwatson case PRIV_VFS_SETGID: 2401168951Srwatson case PRIV_VFS_STICKYFILE: 2402168951Srwatson case PRIV_VFS_SYSFLAGS: 2403168951Srwatson case PRIV_VFS_UNMOUNT: 2404168951Srwatson 2405168951Srwatson /* 2406168951Srwatson * Allow VM privileges; it would be nice if these were subject to 2407168951Srwatson * resource limits. 2408168951Srwatson */ 2409168951Srwatson case PRIV_VM_MADV_PROTECT: 2410168951Srwatson case PRIV_VM_MLOCK: 2411168951Srwatson case PRIV_VM_MUNLOCK: 2412168951Srwatson 2413168951Srwatson /* 2414168951Srwatson * Allow some but not all network privileges. In general, dont allow 2415168951Srwatson * reconfiguring the network stack, just normal use. 2416168951Srwatson */ 2417168951Srwatson case PRIV_NETATALK_RESERVEDPORT: 2418168951Srwatson case PRIV_NETINET_RESERVEDPORT: 2419168951Srwatson case PRIV_NETINET_RAW: 2420168951Srwatson case PRIV_NETINET_REUSEPORT: 2421168951Srwatson case PRIV_NETIPX_RESERVEDPORT: 2422168951Srwatson case PRIV_NETIPX_RAW: 2423168951Srwatson break; 2424168951Srwatson 2425168951Srwatson /* 2426168951Srwatson * All remaining system privileges are allow only if the process 2427168951Srwatson * holds privilege with respect to the Biba policy. 2428168951Srwatson */ 2429168951Srwatson default: 2430168951Srwatson subj = SLOT(cred->cr_label); 2431168951Srwatson error = mac_biba_subject_privileged(subj); 2432168951Srwatson if (error) 2433168951Srwatson return (error); 2434168951Srwatson } 2435112574Srwatson return (0); 2436112574Srwatson} 2437112574Srwatson 2438112574Srwatsonstatic int 2439106418Srwatsonmac_biba_check_system_acct(struct ucred *cred, struct vnode *vp, 2440106418Srwatson struct label *label) 2441106418Srwatson{ 2442106418Srwatson struct mac_biba *subj, *obj; 2443106418Srwatson int error; 2444106418Srwatson 2445106418Srwatson if (!mac_biba_enabled) 2446106418Srwatson return (0); 2447106418Srwatson 2448122524Srwatson subj = SLOT(cred->cr_label); 2449106418Srwatson 2450106418Srwatson error = mac_biba_subject_privileged(subj); 2451106418Srwatson if (error) 2452106418Srwatson return (error); 2453106418Srwatson 2454106418Srwatson if (label == NULL) 2455106418Srwatson return (0); 2456106418Srwatson 2457106418Srwatson obj = SLOT(label); 2458132232Srwatson if (!mac_biba_high_effective(obj)) 2459106418Srwatson return (EACCES); 2460106418Srwatson 2461106418Srwatson return (0); 2462106418Srwatson} 2463106418Srwatson 2464106418Srwatsonstatic int 2465168933Srwatsonmac_biba_check_system_auditctl(struct ucred *cred, struct vnode *vp, 2466168933Srwatson struct label *vplabel) 2467168933Srwatson{ 2468168933Srwatson struct mac_biba *subj, *obj; 2469168933Srwatson int error; 2470168933Srwatson 2471168933Srwatson if (!mac_biba_enabled) 2472168933Srwatson return (0); 2473168933Srwatson 2474168933Srwatson subj = SLOT(cred->cr_label); 2475168933Srwatson 2476168933Srwatson error = mac_biba_subject_privileged(subj); 2477168933Srwatson if (error) 2478168933Srwatson return (error); 2479168933Srwatson 2480168933Srwatson if (vplabel == NULL) 2481168933Srwatson return (0); 2482168933Srwatson 2483168933Srwatson obj = SLOT(vplabel); 2484168933Srwatson if (!mac_biba_high_effective(obj)) 2485168933Srwatson return (EACCES); 2486168933Srwatson 2487168933Srwatson return (0); 2488168933Srwatson} 2489168933Srwatson 2490168933Srwatsonstatic int 2491168933Srwatsonmac_biba_check_system_auditon(struct ucred *cred, int cmd) 2492168933Srwatson{ 2493168933Srwatson struct mac_biba *subj; 2494168933Srwatson int error; 2495168933Srwatson 2496168933Srwatson if (!mac_biba_enabled) 2497168933Srwatson return (0); 2498168933Srwatson 2499168933Srwatson subj = SLOT(cred->cr_label); 2500168933Srwatson 2501168933Srwatson error = mac_biba_subject_privileged(subj); 2502168933Srwatson if (error) 2503168933Srwatson return (error); 2504168933Srwatson 2505168933Srwatson return (0); 2506168933Srwatson} 2507168933Srwatson 2508168933Srwatsonstatic int 2509106161Srwatsonmac_biba_check_system_swapon(struct ucred *cred, struct vnode *vp, 2510106161Srwatson struct label *label) 2511106161Srwatson{ 2512106161Srwatson struct mac_biba *subj, *obj; 2513106416Srwatson int error; 2514106161Srwatson 2515106161Srwatson if (!mac_biba_enabled) 2516106161Srwatson return (0); 2517106161Srwatson 2518122524Srwatson subj = SLOT(cred->cr_label); 2519106161Srwatson obj = SLOT(label); 2520106161Srwatson 2521106416Srwatson error = mac_biba_subject_privileged(subj); 2522106416Srwatson if (error) 2523106416Srwatson return (error); 2524106161Srwatson 2525132232Srwatson if (!mac_biba_high_effective(obj)) 2526106161Srwatson return (EACCES); 2527106161Srwatson 2528106161Srwatson return (0); 2529106161Srwatson} 2530106161Srwatson 2531106161Srwatsonstatic int 2532112574Srwatsonmac_biba_check_system_swapoff(struct ucred *cred, struct vnode *vp, 2533112574Srwatson struct label *label) 2534112574Srwatson{ 2535166617Srwatson struct mac_biba *subj; 2536112574Srwatson int error; 2537112574Srwatson 2538112574Srwatson if (!mac_biba_enabled) 2539112574Srwatson return (0); 2540112574Srwatson 2541122524Srwatson subj = SLOT(cred->cr_label); 2542112574Srwatson 2543112574Srwatson error = mac_biba_subject_privileged(subj); 2544112574Srwatson if (error) 2545112574Srwatson return (error); 2546112574Srwatson 2547112574Srwatson return (0); 2548112574Srwatson} 2549112574Srwatson 2550112574Srwatsonstatic int 2551126121Spjdmac_biba_check_system_sysctl(struct ucred *cred, struct sysctl_oid *oidp, 2552126121Spjd void *arg1, int arg2, struct sysctl_req *req) 2553106161Srwatson{ 2554106161Srwatson struct mac_biba *subj; 2555106161Srwatson int error; 2556106161Srwatson 2557106161Srwatson if (!mac_biba_enabled) 2558106161Srwatson return (0); 2559106161Srwatson 2560122524Srwatson subj = SLOT(cred->cr_label); 2561106161Srwatson 2562106161Srwatson /* 2563126121Spjd * Treat sysctl variables without CTLFLAG_ANYBODY flag as 2564126121Spjd * biba/high, but also require privilege to change them. 2565106161Srwatson */ 2566126121Spjd if (req->newptr != NULL && (oidp->oid_kind & CTLFLAG_ANYBODY) == 0) { 2567106161Srwatson if (!mac_biba_subject_dominate_high(subj)) 2568106161Srwatson return (EACCES); 2569106161Srwatson 2570106161Srwatson error = mac_biba_subject_privileged(subj); 2571106161Srwatson if (error) 2572106161Srwatson return (error); 2573106161Srwatson } 2574106161Srwatson 2575106161Srwatson return (0); 2576106161Srwatson} 2577106161Srwatson 2578106161Srwatsonstatic int 2579101099Srwatsonmac_biba_check_vnode_chdir(struct ucred *cred, struct vnode *dvp, 2580101099Srwatson struct label *dlabel) 2581101099Srwatson{ 2582101099Srwatson struct mac_biba *subj, *obj; 2583101099Srwatson 2584101099Srwatson if (!mac_biba_enabled) 2585101099Srwatson return (0); 2586101099Srwatson 2587122524Srwatson subj = SLOT(cred->cr_label); 2588101099Srwatson obj = SLOT(dlabel); 2589101099Srwatson 2590132232Srwatson if (!mac_biba_dominate_effective(obj, subj)) 2591101099Srwatson return (EACCES); 2592101099Srwatson 2593101099Srwatson return (0); 2594101099Srwatson} 2595101099Srwatson 2596101099Srwatsonstatic int 2597101099Srwatsonmac_biba_check_vnode_chroot(struct ucred *cred, struct vnode *dvp, 2598101099Srwatson struct label *dlabel) 2599101099Srwatson{ 2600101099Srwatson struct mac_biba *subj, *obj; 2601101099Srwatson 2602101099Srwatson if (!mac_biba_enabled) 2603101099Srwatson return (0); 2604101099Srwatson 2605122524Srwatson subj = SLOT(cred->cr_label); 2606101099Srwatson obj = SLOT(dlabel); 2607101099Srwatson 2608132232Srwatson if (!mac_biba_dominate_effective(obj, subj)) 2609101099Srwatson return (EACCES); 2610101099Srwatson 2611101099Srwatson return (0); 2612101099Srwatson} 2613101099Srwatson 2614101099Srwatsonstatic int 2615101099Srwatsonmac_biba_check_vnode_create(struct ucred *cred, struct vnode *dvp, 2616101099Srwatson struct label *dlabel, struct componentname *cnp, struct vattr *vap) 2617101099Srwatson{ 2618101099Srwatson struct mac_biba *subj, *obj; 2619101099Srwatson 2620101099Srwatson if (!mac_biba_enabled) 2621101099Srwatson return (0); 2622101099Srwatson 2623122524Srwatson subj = SLOT(cred->cr_label); 2624101099Srwatson obj = SLOT(dlabel); 2625101099Srwatson 2626132232Srwatson if (!mac_biba_dominate_effective(subj, obj)) 2627101099Srwatson return (EACCES); 2628101099Srwatson 2629101099Srwatson return (0); 2630101099Srwatson} 2631101099Srwatson 2632101099Srwatsonstatic int 2633101099Srwatsonmac_biba_check_vnode_delete(struct ucred *cred, struct vnode *dvp, 2634101099Srwatson struct label *dlabel, struct vnode *vp, struct label *label, 2635101099Srwatson struct componentname *cnp) 2636101099Srwatson{ 2637101099Srwatson struct mac_biba *subj, *obj; 2638101099Srwatson 2639101099Srwatson if (!mac_biba_enabled) 2640101099Srwatson return (0); 2641101099Srwatson 2642122524Srwatson subj = SLOT(cred->cr_label); 2643101099Srwatson obj = SLOT(dlabel); 2644101099Srwatson 2645132232Srwatson if (!mac_biba_dominate_effective(subj, obj)) 2646101099Srwatson return (EACCES); 2647101099Srwatson 2648101099Srwatson obj = SLOT(label); 2649101099Srwatson 2650132232Srwatson if (!mac_biba_dominate_effective(subj, obj)) 2651101099Srwatson return (EACCES); 2652101099Srwatson 2653101099Srwatson return (0); 2654101099Srwatson} 2655101099Srwatson 2656101099Srwatsonstatic int 2657101099Srwatsonmac_biba_check_vnode_deleteacl(struct ucred *cred, struct vnode *vp, 2658101099Srwatson struct label *label, acl_type_t type) 2659101099Srwatson{ 2660101099Srwatson struct mac_biba *subj, *obj; 2661101099Srwatson 2662101099Srwatson if (!mac_biba_enabled) 2663101099Srwatson return (0); 2664101099Srwatson 2665122524Srwatson subj = SLOT(cred->cr_label); 2666101099Srwatson obj = SLOT(label); 2667101099Srwatson 2668132232Srwatson if (!mac_biba_dominate_effective(subj, obj)) 2669101099Srwatson return (EACCES); 2670101099Srwatson 2671101099Srwatson return (0); 2672101099Srwatson} 2673101099Srwatson 2674101099Srwatsonstatic int 2675119202Srwatsonmac_biba_check_vnode_deleteextattr(struct ucred *cred, struct vnode *vp, 2676119202Srwatson struct label *label, int attrnamespace, const char *name) 2677119202Srwatson{ 2678119202Srwatson struct mac_biba *subj, *obj; 2679119202Srwatson 2680119202Srwatson if (!mac_biba_enabled) 2681119202Srwatson return (0); 2682119202Srwatson 2683122524Srwatson subj = SLOT(cred->cr_label); 2684119202Srwatson obj = SLOT(label); 2685119202Srwatson 2686132232Srwatson if (!mac_biba_dominate_effective(subj, obj)) 2687119202Srwatson return (EACCES); 2688119202Srwatson 2689119202Srwatson return (0); 2690119202Srwatson} 2691119202Srwatson 2692119202Srwatsonstatic int 2693101099Srwatsonmac_biba_check_vnode_exec(struct ucred *cred, struct vnode *vp, 2694106648Srwatson struct label *label, struct image_params *imgp, 2695106648Srwatson struct label *execlabel) 2696101099Srwatson{ 2697106648Srwatson struct mac_biba *subj, *obj, *exec; 2698106648Srwatson int error; 2699101099Srwatson 2700106648Srwatson if (execlabel != NULL) { 2701106648Srwatson /* 2702106648Srwatson * We currently don't permit labels to be changed at 2703106648Srwatson * exec-time as part of Biba, so disallow non-NULL 2704106648Srwatson * Biba label elements in the execlabel. 2705106648Srwatson */ 2706106648Srwatson exec = SLOT(execlabel); 2707106648Srwatson error = biba_atmostflags(exec, 0); 2708106648Srwatson if (error) 2709106648Srwatson return (error); 2710106648Srwatson } 2711106648Srwatson 2712101099Srwatson if (!mac_biba_enabled) 2713101099Srwatson return (0); 2714101099Srwatson 2715122524Srwatson subj = SLOT(cred->cr_label); 2716101099Srwatson obj = SLOT(label); 2717101099Srwatson 2718132232Srwatson if (!mac_biba_dominate_effective(obj, subj)) 2719101099Srwatson return (EACCES); 2720101099Srwatson 2721101099Srwatson return (0); 2722101099Srwatson} 2723101099Srwatson 2724101099Srwatsonstatic int 2725101099Srwatsonmac_biba_check_vnode_getacl(struct ucred *cred, struct vnode *vp, 2726101099Srwatson struct label *label, acl_type_t type) 2727101099Srwatson{ 2728101099Srwatson struct mac_biba *subj, *obj; 2729101099Srwatson 2730101099Srwatson if (!mac_biba_enabled) 2731101099Srwatson return (0); 2732101099Srwatson 2733122524Srwatson subj = SLOT(cred->cr_label); 2734101099Srwatson obj = SLOT(label); 2735101099Srwatson 2736132232Srwatson if (!mac_biba_dominate_effective(obj, subj)) 2737101099Srwatson return (EACCES); 2738101099Srwatson 2739101099Srwatson return (0); 2740101099Srwatson} 2741101099Srwatson 2742101099Srwatsonstatic int 2743101099Srwatsonmac_biba_check_vnode_getextattr(struct ucred *cred, struct vnode *vp, 2744101099Srwatson struct label *label, int attrnamespace, const char *name, struct uio *uio) 2745101099Srwatson{ 2746101099Srwatson struct mac_biba *subj, *obj; 2747101099Srwatson 2748101099Srwatson if (!mac_biba_enabled) 2749101099Srwatson return (0); 2750101099Srwatson 2751122524Srwatson subj = SLOT(cred->cr_label); 2752101099Srwatson obj = SLOT(label); 2753101099Srwatson 2754132232Srwatson if (!mac_biba_dominate_effective(obj, subj)) 2755101099Srwatson return (EACCES); 2756101099Srwatson 2757101099Srwatson return (0); 2758101099Srwatson} 2759101099Srwatson 2760101099Srwatsonstatic int 2761104530Srwatsonmac_biba_check_vnode_link(struct ucred *cred, struct vnode *dvp, 2762104530Srwatson struct label *dlabel, struct vnode *vp, struct label *label, 2763104530Srwatson struct componentname *cnp) 2764104530Srwatson{ 2765104530Srwatson struct mac_biba *subj, *obj; 2766104530Srwatson 2767104530Srwatson if (!mac_biba_enabled) 2768104530Srwatson return (0); 2769104530Srwatson 2770122524Srwatson subj = SLOT(cred->cr_label); 2771104530Srwatson obj = SLOT(dlabel); 2772104530Srwatson 2773132232Srwatson if (!mac_biba_dominate_effective(subj, obj)) 2774104530Srwatson return (EACCES); 2775104530Srwatson 2776104530Srwatson obj = SLOT(label); 2777104530Srwatson 2778132232Srwatson if (!mac_biba_dominate_effective(subj, obj)) 2779104530Srwatson return (EACCES); 2780104530Srwatson 2781104530Srwatson return (0); 2782104530Srwatson} 2783104530Srwatson 2784104530Srwatsonstatic int 2785119202Srwatsonmac_biba_check_vnode_listextattr(struct ucred *cred, struct vnode *vp, 2786119202Srwatson struct label *label, int attrnamespace) 2787119202Srwatson{ 2788119202Srwatson struct mac_biba *subj, *obj; 2789119202Srwatson 2790119202Srwatson if (!mac_biba_enabled) 2791119202Srwatson return (0); 2792119202Srwatson 2793122524Srwatson subj = SLOT(cred->cr_label); 2794119202Srwatson obj = SLOT(label); 2795119202Srwatson 2796132232Srwatson if (!mac_biba_dominate_effective(obj, subj)) 2797119202Srwatson return (EACCES); 2798119202Srwatson 2799119202Srwatson return (0); 2800119202Srwatson} 2801119202Srwatson 2802119202Srwatsonstatic int 2803103759Srwatsonmac_biba_check_vnode_lookup(struct ucred *cred, struct vnode *dvp, 2804101099Srwatson struct label *dlabel, struct componentname *cnp) 2805101099Srwatson{ 2806101099Srwatson struct mac_biba *subj, *obj; 2807103759Srwatson 2808101099Srwatson if (!mac_biba_enabled) 2809101099Srwatson return (0); 2810103759Srwatson 2811122524Srwatson subj = SLOT(cred->cr_label); 2812101099Srwatson obj = SLOT(dlabel); 2813103759Srwatson 2814132232Srwatson if (!mac_biba_dominate_effective(obj, subj)) 2815101099Srwatson return (EACCES); 2816101099Srwatson 2817103759Srwatson return (0); 2818101099Srwatson} 2819101099Srwatson 2820101099Srwatsonstatic int 2821104546Srwatsonmac_biba_check_vnode_mmap(struct ucred *cred, struct vnode *vp, 2822145076Scsjp struct label *label, int prot, int flags) 2823104546Srwatson{ 2824104546Srwatson struct mac_biba *subj, *obj; 2825104546Srwatson 2826104546Srwatson /* 2827104546Srwatson * Rely on the use of open()-time protections to handle 2828104546Srwatson * non-revocation cases. 2829104546Srwatson */ 2830105637Srwatson if (!mac_biba_enabled || !revocation_enabled) 2831104546Srwatson return (0); 2832104546Srwatson 2833122524Srwatson subj = SLOT(cred->cr_label); 2834104546Srwatson obj = SLOT(label); 2835104546Srwatson 2836104546Srwatson if (prot & (VM_PROT_READ | VM_PROT_EXECUTE)) { 2837132232Srwatson if (!mac_biba_dominate_effective(obj, subj)) 2838104546Srwatson return (EACCES); 2839104546Srwatson } 2840145076Scsjp if (((prot & VM_PROT_WRITE) != 0) && ((flags & MAP_SHARED) != 0)) { 2841132232Srwatson if (!mac_biba_dominate_effective(subj, obj)) 2842104546Srwatson return (EACCES); 2843104546Srwatson } 2844104546Srwatson 2845104569Srwatson return (0); 2846104546Srwatson} 2847104546Srwatson 2848104546Srwatsonstatic int 2849101099Srwatsonmac_biba_check_vnode_open(struct ucred *cred, struct vnode *vp, 2850106212Srwatson struct label *vnodelabel, int acc_mode) 2851101099Srwatson{ 2852101099Srwatson struct mac_biba *subj, *obj; 2853101099Srwatson 2854101099Srwatson if (!mac_biba_enabled) 2855101099Srwatson return (0); 2856101099Srwatson 2857122524Srwatson subj = SLOT(cred->cr_label); 2858101099Srwatson obj = SLOT(vnodelabel); 2859101099Srwatson 2860101099Srwatson /* XXX privilege override for admin? */ 2861101099Srwatson if (acc_mode & (VREAD | VEXEC | VSTAT)) { 2862132232Srwatson if (!mac_biba_dominate_effective(obj, subj)) 2863101099Srwatson return (EACCES); 2864101099Srwatson } 2865101099Srwatson if (acc_mode & (VWRITE | VAPPEND | VADMIN)) { 2866132232Srwatson if (!mac_biba_dominate_effective(subj, obj)) 2867101099Srwatson return (EACCES); 2868101099Srwatson } 2869101099Srwatson 2870101099Srwatson return (0); 2871101099Srwatson} 2872101099Srwatson 2873101099Srwatsonstatic int 2874102129Srwatsonmac_biba_check_vnode_poll(struct ucred *active_cred, struct ucred *file_cred, 2875102129Srwatson struct vnode *vp, struct label *label) 2876102112Srwatson{ 2877102112Srwatson struct mac_biba *subj, *obj; 2878102112Srwatson 2879105637Srwatson if (!mac_biba_enabled || !revocation_enabled) 2880102112Srwatson return (0); 2881102112Srwatson 2882122524Srwatson subj = SLOT(active_cred->cr_label); 2883102112Srwatson obj = SLOT(label); 2884102112Srwatson 2885132232Srwatson if (!mac_biba_dominate_effective(obj, subj)) 2886102112Srwatson return (EACCES); 2887102112Srwatson 2888102112Srwatson return (0); 2889102112Srwatson} 2890102112Srwatson 2891102112Srwatsonstatic int 2892102129Srwatsonmac_biba_check_vnode_read(struct ucred *active_cred, struct ucred *file_cred, 2893102129Srwatson struct vnode *vp, struct label *label) 2894102112Srwatson{ 2895102112Srwatson struct mac_biba *subj, *obj; 2896102112Srwatson 2897105637Srwatson if (!mac_biba_enabled || !revocation_enabled) 2898102112Srwatson return (0); 2899102112Srwatson 2900122524Srwatson subj = SLOT(active_cred->cr_label); 2901102112Srwatson obj = SLOT(label); 2902102112Srwatson 2903132232Srwatson if (!mac_biba_dominate_effective(obj, subj)) 2904102112Srwatson return (EACCES); 2905102112Srwatson 2906102112Srwatson return (0); 2907102112Srwatson} 2908102112Srwatson 2909102112Srwatsonstatic int 2910101099Srwatsonmac_biba_check_vnode_readdir(struct ucred *cred, struct vnode *dvp, 2911101099Srwatson struct label *dlabel) 2912101099Srwatson{ 2913101099Srwatson struct mac_biba *subj, *obj; 2914101099Srwatson 2915101099Srwatson if (!mac_biba_enabled) 2916101099Srwatson return (0); 2917101099Srwatson 2918122524Srwatson subj = SLOT(cred->cr_label); 2919101099Srwatson obj = SLOT(dlabel); 2920101099Srwatson 2921132232Srwatson if (!mac_biba_dominate_effective(obj, subj)) 2922101099Srwatson return (EACCES); 2923101099Srwatson 2924101099Srwatson return (0); 2925101099Srwatson} 2926101099Srwatson 2927101099Srwatsonstatic int 2928101099Srwatsonmac_biba_check_vnode_readlink(struct ucred *cred, struct vnode *vp, 2929101099Srwatson struct label *label) 2930101099Srwatson{ 2931101099Srwatson struct mac_biba *subj, *obj; 2932101099Srwatson 2933101099Srwatson if (!mac_biba_enabled) 2934101099Srwatson return (0); 2935101099Srwatson 2936122524Srwatson subj = SLOT(cred->cr_label); 2937101099Srwatson obj = SLOT(label); 2938101099Srwatson 2939132232Srwatson if (!mac_biba_dominate_effective(obj, subj)) 2940101099Srwatson return (EACCES); 2941101099Srwatson 2942101099Srwatson return (0); 2943101099Srwatson} 2944101099Srwatson 2945101099Srwatsonstatic int 2946101099Srwatsonmac_biba_check_vnode_relabel(struct ucred *cred, struct vnode *vp, 2947101099Srwatson struct label *vnodelabel, struct label *newlabel) 2948101099Srwatson{ 2949101099Srwatson struct mac_biba *old, *new, *subj; 2950105634Srwatson int error; 2951101099Srwatson 2952101099Srwatson old = SLOT(vnodelabel); 2953101099Srwatson new = SLOT(newlabel); 2954122524Srwatson subj = SLOT(cred->cr_label); 2955101099Srwatson 2956101099Srwatson /* 2957105634Srwatson * If there is a Biba label update for the vnode, it must be a 2958132232Srwatson * effective label. 2959101099Srwatson */ 2960132232Srwatson error = biba_atmostflags(new, MAC_BIBA_FLAG_EFFECTIVE); 2961105634Srwatson if (error) 2962105634Srwatson return (error); 2963101099Srwatson 2964101099Srwatson /* 2965105634Srwatson * To perform a relabel of the vnode (Biba label or not), Biba must 2966105634Srwatson * authorize the relabel. 2967101099Srwatson */ 2968132232Srwatson if (!mac_biba_effective_in_range(old, subj)) 2969101099Srwatson return (EPERM); 2970101099Srwatson 2971101099Srwatson /* 2972105634Srwatson * If the Biba label is to be changed, authorize as appropriate. 2973101099Srwatson */ 2974132232Srwatson if (new->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) { 2975105634Srwatson /* 2976105634Srwatson * To change the Biba label on a vnode, the new vnode label 2977105634Srwatson * must be in the subject range. 2978105634Srwatson */ 2979132232Srwatson if (!mac_biba_effective_in_range(new, subj)) 2980105634Srwatson return (EPERM); 2981101099Srwatson 2982105634Srwatson /* 2983105634Srwatson * To change the Biba label on the vnode to be EQUAL, 2984105634Srwatson * the subject must have appropriate privilege. 2985105634Srwatson */ 2986105634Srwatson if (mac_biba_contains_equal(new)) { 2987106090Srwatson error = mac_biba_subject_privileged(subj); 2988105634Srwatson if (error) 2989105634Srwatson return (error); 2990105634Srwatson } 2991105634Srwatson } 2992105634Srwatson 2993105634Srwatson return (0); 2994101099Srwatson} 2995101099Srwatson 2996101099Srwatsonstatic int 2997101099Srwatsonmac_biba_check_vnode_rename_from(struct ucred *cred, struct vnode *dvp, 2998101099Srwatson struct label *dlabel, struct vnode *vp, struct label *label, 2999101099Srwatson struct componentname *cnp) 3000101099Srwatson{ 3001101099Srwatson struct mac_biba *subj, *obj; 3002101099Srwatson 3003101099Srwatson if (!mac_biba_enabled) 3004101099Srwatson return (0); 3005101099Srwatson 3006122524Srwatson subj = SLOT(cred->cr_label); 3007101099Srwatson obj = SLOT(dlabel); 3008101099Srwatson 3009132232Srwatson if (!mac_biba_dominate_effective(subj, obj)) 3010101099Srwatson return (EACCES); 3011101099Srwatson 3012101099Srwatson obj = SLOT(label); 3013101099Srwatson 3014132232Srwatson if (!mac_biba_dominate_effective(subj, obj)) 3015101099Srwatson return (EACCES); 3016101099Srwatson 3017101099Srwatson return (0); 3018101099Srwatson} 3019101099Srwatson 3020101099Srwatsonstatic int 3021101099Srwatsonmac_biba_check_vnode_rename_to(struct ucred *cred, struct vnode *dvp, 3022101099Srwatson struct label *dlabel, struct vnode *vp, struct label *label, int samedir, 3023101099Srwatson struct componentname *cnp) 3024101099Srwatson{ 3025101099Srwatson struct mac_biba *subj, *obj; 3026101099Srwatson 3027101099Srwatson if (!mac_biba_enabled) 3028101099Srwatson return (0); 3029101099Srwatson 3030122524Srwatson subj = SLOT(cred->cr_label); 3031101099Srwatson obj = SLOT(dlabel); 3032101099Srwatson 3033132232Srwatson if (!mac_biba_dominate_effective(subj, obj)) 3034101099Srwatson return (EACCES); 3035101099Srwatson 3036101099Srwatson if (vp != NULL) { 3037101099Srwatson obj = SLOT(label); 3038101099Srwatson 3039132232Srwatson if (!mac_biba_dominate_effective(subj, obj)) 3040101099Srwatson return (EACCES); 3041101099Srwatson } 3042101099Srwatson 3043101099Srwatson return (0); 3044101099Srwatson} 3045101099Srwatson 3046101099Srwatsonstatic int 3047101099Srwatsonmac_biba_check_vnode_revoke(struct ucred *cred, struct vnode *vp, 3048101099Srwatson struct label *label) 3049101099Srwatson{ 3050101099Srwatson struct mac_biba *subj, *obj; 3051101099Srwatson 3052101099Srwatson if (!mac_biba_enabled) 3053101099Srwatson return (0); 3054101099Srwatson 3055122524Srwatson subj = SLOT(cred->cr_label); 3056101099Srwatson obj = SLOT(label); 3057101099Srwatson 3058132232Srwatson if (!mac_biba_dominate_effective(subj, obj)) 3059101099Srwatson return (EACCES); 3060101099Srwatson 3061101099Srwatson return (0); 3062101099Srwatson} 3063101099Srwatson 3064101099Srwatsonstatic int 3065101099Srwatsonmac_biba_check_vnode_setacl(struct ucred *cred, struct vnode *vp, 3066101099Srwatson struct label *label, acl_type_t type, struct acl *acl) 3067101099Srwatson{ 3068101099Srwatson struct mac_biba *subj, *obj; 3069101099Srwatson 3070101099Srwatson if (!mac_biba_enabled) 3071101099Srwatson return (0); 3072101099Srwatson 3073122524Srwatson subj = SLOT(cred->cr_label); 3074101099Srwatson obj = SLOT(label); 3075101099Srwatson 3076132232Srwatson if (!mac_biba_dominate_effective(subj, obj)) 3077101099Srwatson return (EACCES); 3078101099Srwatson 3079101099Srwatson return (0); 3080101099Srwatson} 3081101099Srwatson 3082101099Srwatsonstatic int 3083101099Srwatsonmac_biba_check_vnode_setextattr(struct ucred *cred, struct vnode *vp, 3084101099Srwatson struct label *vnodelabel, int attrnamespace, const char *name, 3085101099Srwatson struct uio *uio) 3086101099Srwatson{ 3087101099Srwatson struct mac_biba *subj, *obj; 3088101099Srwatson 3089101099Srwatson if (!mac_biba_enabled) 3090101099Srwatson return (0); 3091101099Srwatson 3092122524Srwatson subj = SLOT(cred->cr_label); 3093101099Srwatson obj = SLOT(vnodelabel); 3094101099Srwatson 3095132232Srwatson if (!mac_biba_dominate_effective(subj, obj)) 3096101099Srwatson return (EACCES); 3097101099Srwatson 3098101099Srwatson /* XXX: protect the MAC EA in a special way? */ 3099101099Srwatson 3100101099Srwatson return (0); 3101101099Srwatson} 3102101099Srwatson 3103101099Srwatsonstatic int 3104101099Srwatsonmac_biba_check_vnode_setflags(struct ucred *cred, struct vnode *vp, 3105101099Srwatson struct label *vnodelabel, u_long flags) 3106101099Srwatson{ 3107101099Srwatson struct mac_biba *subj, *obj; 3108101099Srwatson 3109101099Srwatson if (!mac_biba_enabled) 3110101099Srwatson return (0); 3111101099Srwatson 3112122524Srwatson subj = SLOT(cred->cr_label); 3113101099Srwatson obj = SLOT(vnodelabel); 3114101099Srwatson 3115132232Srwatson if (!mac_biba_dominate_effective(subj, obj)) 3116101099Srwatson return (EACCES); 3117101099Srwatson 3118101099Srwatson return (0); 3119101099Srwatson} 3120101099Srwatson 3121101099Srwatsonstatic int 3122101099Srwatsonmac_biba_check_vnode_setmode(struct ucred *cred, struct vnode *vp, 3123101099Srwatson struct label *vnodelabel, mode_t mode) 3124101099Srwatson{ 3125101099Srwatson struct mac_biba *subj, *obj; 3126101099Srwatson 3127101099Srwatson if (!mac_biba_enabled) 3128101099Srwatson return (0); 3129101099Srwatson 3130122524Srwatson subj = SLOT(cred->cr_label); 3131101099Srwatson obj = SLOT(vnodelabel); 3132101099Srwatson 3133132232Srwatson if (!mac_biba_dominate_effective(subj, obj)) 3134101099Srwatson return (EACCES); 3135101099Srwatson 3136101099Srwatson return (0); 3137101099Srwatson} 3138101099Srwatson 3139101099Srwatsonstatic int 3140101099Srwatsonmac_biba_check_vnode_setowner(struct ucred *cred, struct vnode *vp, 3141101099Srwatson struct label *vnodelabel, uid_t uid, gid_t gid) 3142101099Srwatson{ 3143101099Srwatson struct mac_biba *subj, *obj; 3144101099Srwatson 3145101099Srwatson if (!mac_biba_enabled) 3146101099Srwatson return (0); 3147101099Srwatson 3148122524Srwatson subj = SLOT(cred->cr_label); 3149101099Srwatson obj = SLOT(vnodelabel); 3150101099Srwatson 3151132232Srwatson if (!mac_biba_dominate_effective(subj, obj)) 3152101099Srwatson return (EACCES); 3153101099Srwatson 3154101099Srwatson return (0); 3155101099Srwatson} 3156101099Srwatson 3157101099Srwatsonstatic int 3158101099Srwatsonmac_biba_check_vnode_setutimes(struct ucred *cred, struct vnode *vp, 3159101099Srwatson struct label *vnodelabel, struct timespec atime, struct timespec mtime) 3160101099Srwatson{ 3161101099Srwatson struct mac_biba *subj, *obj; 3162101099Srwatson 3163101099Srwatson if (!mac_biba_enabled) 3164101099Srwatson return (0); 3165101099Srwatson 3166122524Srwatson subj = SLOT(cred->cr_label); 3167101099Srwatson obj = SLOT(vnodelabel); 3168101099Srwatson 3169132232Srwatson if (!mac_biba_dominate_effective(subj, obj)) 3170101099Srwatson return (EACCES); 3171101099Srwatson 3172101099Srwatson return (0); 3173101099Srwatson} 3174101099Srwatson 3175101099Srwatsonstatic int 3176102129Srwatsonmac_biba_check_vnode_stat(struct ucred *active_cred, struct ucred *file_cred, 3177102129Srwatson struct vnode *vp, struct label *vnodelabel) 3178101099Srwatson{ 3179101099Srwatson struct mac_biba *subj, *obj; 3180101099Srwatson 3181101099Srwatson if (!mac_biba_enabled) 3182101099Srwatson return (0); 3183101099Srwatson 3184122524Srwatson subj = SLOT(active_cred->cr_label); 3185101099Srwatson obj = SLOT(vnodelabel); 3186101099Srwatson 3187132232Srwatson if (!mac_biba_dominate_effective(obj, subj)) 3188101099Srwatson return (EACCES); 3189101099Srwatson 3190101099Srwatson return (0); 3191101099Srwatson} 3192101099Srwatson 3193102112Srwatsonstatic int 3194102129Srwatsonmac_biba_check_vnode_write(struct ucred *active_cred, 3195102129Srwatson struct ucred *file_cred, struct vnode *vp, struct label *label) 3196102112Srwatson{ 3197102112Srwatson struct mac_biba *subj, *obj; 3198102112Srwatson 3199105637Srwatson if (!mac_biba_enabled || !revocation_enabled) 3200102112Srwatson return (0); 3201102112Srwatson 3202122524Srwatson subj = SLOT(active_cred->cr_label); 3203102112Srwatson obj = SLOT(label); 3204102112Srwatson 3205132232Srwatson if (!mac_biba_dominate_effective(subj, obj)) 3206102112Srwatson return (EACCES); 3207102112Srwatson 3208102112Srwatson return (0); 3209102112Srwatson} 3210102112Srwatson 3211161026Srwatsonstatic void 3212160243Scsjpmac_biba_associate_nfsd_label(struct ucred *cred) 3213160243Scsjp{ 3214160243Scsjp struct mac_biba *label; 3215160243Scsjp 3216160243Scsjp label = SLOT(cred->cr_label); 3217160243Scsjp mac_biba_set_effective(label, MAC_BIBA_TYPE_LOW, 0, NULL); 3218160243Scsjp mac_biba_set_range(label, MAC_BIBA_TYPE_LOW, 0, NULL, 3219160243Scsjp MAC_BIBA_TYPE_HIGH, 0, NULL); 3220160243Scsjp} 3221160243Scsjp 3222165150Scsjpstatic void 3223165150Scsjpmac_biba_init_syncache_from_inpcb(struct label *label, struct inpcb *inp) 3224165150Scsjp{ 3225165150Scsjp struct mac_biba *source, *dest; 3226165150Scsjp 3227165150Scsjp source = SLOT(inp->inp_label); 3228165150Scsjp dest = SLOT(label); 3229165150Scsjp mac_biba_copy_effective(source, dest); 3230165150Scsjp} 3231165150Scsjp 3232165150Scsjpstatic void 3233165150Scsjpmac_biba_create_mbuf_from_syncache(struct label *sc_label, struct mbuf *m, 3234165150Scsjp struct label *mbuf_label) 3235165150Scsjp{ 3236165150Scsjp struct mac_biba *source, *dest; 3237165150Scsjp 3238165150Scsjp source = SLOT(sc_label); 3239165150Scsjp dest = SLOT(mbuf_label); 3240165150Scsjp mac_biba_copy_effective(source, dest); 3241165150Scsjp} 3242165150Scsjp 3243106217Srwatsonstatic struct mac_policy_ops mac_biba_ops = 3244101099Srwatson{ 3245106217Srwatson .mpo_init = mac_biba_init, 3246106217Srwatson .mpo_init_bpfdesc_label = mac_biba_init_label, 3247106217Srwatson .mpo_init_cred_label = mac_biba_init_label, 3248106217Srwatson .mpo_init_devfsdirent_label = mac_biba_init_label, 3249106217Srwatson .mpo_init_ifnet_label = mac_biba_init_label, 3250122875Srwatson .mpo_init_inpcb_label = mac_biba_init_label_waitcheck, 3251165150Scsjp .mpo_init_syncache_label = mac_biba_init_label_waitcheck, 3252140628Srwatson .mpo_init_sysv_msgmsg_label = mac_biba_init_label, 3253140628Srwatson .mpo_init_sysv_msgqueue_label = mac_biba_init_label, 3254147091Srwatson .mpo_init_sysv_sem_label = mac_biba_init_label, 3255140628Srwatson .mpo_init_sysv_shm_label = mac_biba_init_label, 3256112675Srwatson .mpo_init_ipq_label = mac_biba_init_label_waitcheck, 3257106217Srwatson .mpo_init_mbuf_label = mac_biba_init_label_waitcheck, 3258106217Srwatson .mpo_init_mount_label = mac_biba_init_label, 3259106217Srwatson .mpo_init_pipe_label = mac_biba_init_label, 3260145855Srwatson .mpo_init_posix_sem_label = mac_biba_init_label, 3261106217Srwatson .mpo_init_socket_label = mac_biba_init_label_waitcheck, 3262106217Srwatson .mpo_init_socket_peer_label = mac_biba_init_label_waitcheck, 3263165150Scsjp .mpo_init_syncache_from_inpcb = mac_biba_init_syncache_from_inpcb, 3264106217Srwatson .mpo_init_vnode_label = mac_biba_init_label, 3265106217Srwatson .mpo_destroy_bpfdesc_label = mac_biba_destroy_label, 3266106217Srwatson .mpo_destroy_cred_label = mac_biba_destroy_label, 3267106217Srwatson .mpo_destroy_devfsdirent_label = mac_biba_destroy_label, 3268106217Srwatson .mpo_destroy_ifnet_label = mac_biba_destroy_label, 3269122875Srwatson .mpo_destroy_inpcb_label = mac_biba_destroy_label, 3270165150Scsjp .mpo_destroy_syncache_label = mac_biba_destroy_label, 3271140628Srwatson .mpo_destroy_sysv_msgmsg_label = mac_biba_destroy_label, 3272140628Srwatson .mpo_destroy_sysv_msgqueue_label = mac_biba_destroy_label, 3273147091Srwatson .mpo_destroy_sysv_sem_label = mac_biba_destroy_label, 3274140628Srwatson .mpo_destroy_sysv_shm_label = mac_biba_destroy_label, 3275106217Srwatson .mpo_destroy_ipq_label = mac_biba_destroy_label, 3276106217Srwatson .mpo_destroy_mbuf_label = mac_biba_destroy_label, 3277106217Srwatson .mpo_destroy_mount_label = mac_biba_destroy_label, 3278106217Srwatson .mpo_destroy_pipe_label = mac_biba_destroy_label, 3279145855Srwatson .mpo_destroy_posix_sem_label = mac_biba_destroy_label, 3280106217Srwatson .mpo_destroy_socket_label = mac_biba_destroy_label, 3281106217Srwatson .mpo_destroy_socket_peer_label = mac_biba_destroy_label, 3282106217Srwatson .mpo_destroy_vnode_label = mac_biba_destroy_label, 3283123173Srwatson .mpo_copy_cred_label = mac_biba_copy_label, 3284131025Srwatson .mpo_copy_ifnet_label = mac_biba_copy_label, 3285115707Srwatson .mpo_copy_mbuf_label = mac_biba_copy_label, 3286106217Srwatson .mpo_copy_pipe_label = mac_biba_copy_label, 3287122820Srwatson .mpo_copy_socket_label = mac_biba_copy_label, 3288106217Srwatson .mpo_copy_vnode_label = mac_biba_copy_label, 3289106217Srwatson .mpo_externalize_cred_label = mac_biba_externalize_label, 3290106217Srwatson .mpo_externalize_ifnet_label = mac_biba_externalize_label, 3291106217Srwatson .mpo_externalize_pipe_label = mac_biba_externalize_label, 3292106217Srwatson .mpo_externalize_socket_label = mac_biba_externalize_label, 3293106217Srwatson .mpo_externalize_socket_peer_label = mac_biba_externalize_label, 3294106217Srwatson .mpo_externalize_vnode_label = mac_biba_externalize_label, 3295106217Srwatson .mpo_internalize_cred_label = mac_biba_internalize_label, 3296106217Srwatson .mpo_internalize_ifnet_label = mac_biba_internalize_label, 3297106217Srwatson .mpo_internalize_pipe_label = mac_biba_internalize_label, 3298106217Srwatson .mpo_internalize_socket_label = mac_biba_internalize_label, 3299106217Srwatson .mpo_internalize_vnode_label = mac_biba_internalize_label, 3300106217Srwatson .mpo_create_devfs_device = mac_biba_create_devfs_device, 3301106217Srwatson .mpo_create_devfs_directory = mac_biba_create_devfs_directory, 3302106217Srwatson .mpo_create_devfs_symlink = mac_biba_create_devfs_symlink, 3303106217Srwatson .mpo_create_mount = mac_biba_create_mount, 3304106217Srwatson .mpo_relabel_vnode = mac_biba_relabel_vnode, 3305106217Srwatson .mpo_update_devfsdirent = mac_biba_update_devfsdirent, 3306106217Srwatson .mpo_associate_vnode_devfs = mac_biba_associate_vnode_devfs, 3307106217Srwatson .mpo_associate_vnode_extattr = mac_biba_associate_vnode_extattr, 3308106217Srwatson .mpo_associate_vnode_singlelabel = mac_biba_associate_vnode_singlelabel, 3309106217Srwatson .mpo_create_vnode_extattr = mac_biba_create_vnode_extattr, 3310106217Srwatson .mpo_setlabel_vnode_extattr = mac_biba_setlabel_vnode_extattr, 3311106217Srwatson .mpo_create_mbuf_from_socket = mac_biba_create_mbuf_from_socket, 3312165150Scsjp .mpo_create_mbuf_from_syncache = mac_biba_create_mbuf_from_syncache, 3313106217Srwatson .mpo_create_pipe = mac_biba_create_pipe, 3314145855Srwatson .mpo_create_posix_sem = mac_biba_create_posix_sem, 3315106217Srwatson .mpo_create_socket = mac_biba_create_socket, 3316106217Srwatson .mpo_create_socket_from_socket = mac_biba_create_socket_from_socket, 3317106217Srwatson .mpo_relabel_pipe = mac_biba_relabel_pipe, 3318106217Srwatson .mpo_relabel_socket = mac_biba_relabel_socket, 3319106217Srwatson .mpo_set_socket_peer_from_mbuf = mac_biba_set_socket_peer_from_mbuf, 3320106217Srwatson .mpo_set_socket_peer_from_socket = mac_biba_set_socket_peer_from_socket, 3321106217Srwatson .mpo_create_bpfdesc = mac_biba_create_bpfdesc, 3322106217Srwatson .mpo_create_datagram_from_ipq = mac_biba_create_datagram_from_ipq, 3323106217Srwatson .mpo_create_fragment = mac_biba_create_fragment, 3324106217Srwatson .mpo_create_ifnet = mac_biba_create_ifnet, 3325122875Srwatson .mpo_create_inpcb_from_socket = mac_biba_create_inpcb_from_socket, 3326140628Srwatson .mpo_create_sysv_msgmsg = mac_biba_create_sysv_msgmsg, 3327140628Srwatson .mpo_create_sysv_msgqueue = mac_biba_create_sysv_msgqueue, 3328147091Srwatson .mpo_create_sysv_sem = mac_biba_create_sysv_sem, 3329140628Srwatson .mpo_create_sysv_shm = mac_biba_create_sysv_shm, 3330106217Srwatson .mpo_create_ipq = mac_biba_create_ipq, 3331123607Srwatson .mpo_create_mbuf_from_inpcb = mac_biba_create_mbuf_from_inpcb, 3332106217Srwatson .mpo_create_mbuf_linklayer = mac_biba_create_mbuf_linklayer, 3333106217Srwatson .mpo_create_mbuf_from_bpfdesc = mac_biba_create_mbuf_from_bpfdesc, 3334106217Srwatson .mpo_create_mbuf_from_ifnet = mac_biba_create_mbuf_from_ifnet, 3335106217Srwatson .mpo_create_mbuf_multicast_encap = mac_biba_create_mbuf_multicast_encap, 3336106217Srwatson .mpo_create_mbuf_netlayer = mac_biba_create_mbuf_netlayer, 3337106217Srwatson .mpo_fragment_match = mac_biba_fragment_match, 3338106217Srwatson .mpo_relabel_ifnet = mac_biba_relabel_ifnet, 3339106217Srwatson .mpo_update_ipq = mac_biba_update_ipq, 3340122875Srwatson .mpo_inpcb_sosetlabel = mac_biba_inpcb_sosetlabel, 3341106217Srwatson .mpo_create_proc0 = mac_biba_create_proc0, 3342106217Srwatson .mpo_create_proc1 = mac_biba_create_proc1, 3343106217Srwatson .mpo_relabel_cred = mac_biba_relabel_cred, 3344140628Srwatson .mpo_cleanup_sysv_msgmsg = mac_biba_cleanup_sysv_msgmsg, 3345140628Srwatson .mpo_cleanup_sysv_msgqueue = mac_biba_cleanup_sysv_msgqueue, 3346147091Srwatson .mpo_cleanup_sysv_sem = mac_biba_cleanup_sysv_sem, 3347140628Srwatson .mpo_cleanup_sysv_shm = mac_biba_cleanup_sysv_shm, 3348106217Srwatson .mpo_check_bpfdesc_receive = mac_biba_check_bpfdesc_receive, 3349106217Srwatson .mpo_check_cred_relabel = mac_biba_check_cred_relabel, 3350106217Srwatson .mpo_check_cred_visible = mac_biba_check_cred_visible, 3351106217Srwatson .mpo_check_ifnet_relabel = mac_biba_check_ifnet_relabel, 3352106217Srwatson .mpo_check_ifnet_transmit = mac_biba_check_ifnet_transmit, 3353122875Srwatson .mpo_check_inpcb_deliver = mac_biba_check_inpcb_deliver, 3354140628Srwatson .mpo_check_sysv_msgrcv = mac_biba_check_sysv_msgrcv, 3355140628Srwatson .mpo_check_sysv_msgrmid = mac_biba_check_sysv_msgrmid, 3356140628Srwatson .mpo_check_sysv_msqget = mac_biba_check_sysv_msqget, 3357140628Srwatson .mpo_check_sysv_msqsnd = mac_biba_check_sysv_msqsnd, 3358140628Srwatson .mpo_check_sysv_msqrcv = mac_biba_check_sysv_msqrcv, 3359140628Srwatson .mpo_check_sysv_msqctl = mac_biba_check_sysv_msqctl, 3360140628Srwatson .mpo_check_sysv_semctl = mac_biba_check_sysv_semctl, 3361140628Srwatson .mpo_check_sysv_semget = mac_biba_check_sysv_semget, 3362140628Srwatson .mpo_check_sysv_semop = mac_biba_check_sysv_semop, 3363140628Srwatson .mpo_check_sysv_shmat = mac_biba_check_sysv_shmat, 3364140628Srwatson .mpo_check_sysv_shmctl = mac_biba_check_sysv_shmctl, 3365140628Srwatson .mpo_check_sysv_shmget = mac_biba_check_sysv_shmget, 3366110354Srwatson .mpo_check_kld_load = mac_biba_check_kld_load, 3367106217Srwatson .mpo_check_mount_stat = mac_biba_check_mount_stat, 3368106217Srwatson .mpo_check_pipe_ioctl = mac_biba_check_pipe_ioctl, 3369106217Srwatson .mpo_check_pipe_poll = mac_biba_check_pipe_poll, 3370106217Srwatson .mpo_check_pipe_read = mac_biba_check_pipe_read, 3371106217Srwatson .mpo_check_pipe_relabel = mac_biba_check_pipe_relabel, 3372106217Srwatson .mpo_check_pipe_stat = mac_biba_check_pipe_stat, 3373106217Srwatson .mpo_check_pipe_write = mac_biba_check_pipe_write, 3374145855Srwatson .mpo_check_posix_sem_destroy = mac_biba_check_posix_sem_write, 3375145855Srwatson .mpo_check_posix_sem_getvalue = mac_biba_check_posix_sem_rdonly, 3376145855Srwatson .mpo_check_posix_sem_open = mac_biba_check_posix_sem_write, 3377145855Srwatson .mpo_check_posix_sem_post = mac_biba_check_posix_sem_write, 3378145855Srwatson .mpo_check_posix_sem_unlink = mac_biba_check_posix_sem_write, 3379145855Srwatson .mpo_check_posix_sem_wait = mac_biba_check_posix_sem_write, 3380106217Srwatson .mpo_check_proc_debug = mac_biba_check_proc_debug, 3381106217Srwatson .mpo_check_proc_sched = mac_biba_check_proc_sched, 3382106217Srwatson .mpo_check_proc_signal = mac_biba_check_proc_signal, 3383106217Srwatson .mpo_check_socket_deliver = mac_biba_check_socket_deliver, 3384106217Srwatson .mpo_check_socket_relabel = mac_biba_check_socket_relabel, 3385106217Srwatson .mpo_check_socket_visible = mac_biba_check_socket_visible, 3386106418Srwatson .mpo_check_system_acct = mac_biba_check_system_acct, 3387168933Srwatson .mpo_check_system_auditctl = mac_biba_check_system_auditctl, 3388168933Srwatson .mpo_check_system_auditon = mac_biba_check_system_auditon, 3389106217Srwatson .mpo_check_system_swapon = mac_biba_check_system_swapon, 3390112574Srwatson .mpo_check_system_swapoff = mac_biba_check_system_swapoff, 3391106217Srwatson .mpo_check_system_sysctl = mac_biba_check_system_sysctl, 3392106217Srwatson .mpo_check_vnode_access = mac_biba_check_vnode_open, 3393106217Srwatson .mpo_check_vnode_chdir = mac_biba_check_vnode_chdir, 3394106217Srwatson .mpo_check_vnode_chroot = mac_biba_check_vnode_chroot, 3395106217Srwatson .mpo_check_vnode_create = mac_biba_check_vnode_create, 3396106217Srwatson .mpo_check_vnode_delete = mac_biba_check_vnode_delete, 3397106217Srwatson .mpo_check_vnode_deleteacl = mac_biba_check_vnode_deleteacl, 3398119202Srwatson .mpo_check_vnode_deleteextattr = mac_biba_check_vnode_deleteextattr, 3399106217Srwatson .mpo_check_vnode_exec = mac_biba_check_vnode_exec, 3400106217Srwatson .mpo_check_vnode_getacl = mac_biba_check_vnode_getacl, 3401106217Srwatson .mpo_check_vnode_getextattr = mac_biba_check_vnode_getextattr, 3402106217Srwatson .mpo_check_vnode_link = mac_biba_check_vnode_link, 3403119202Srwatson .mpo_check_vnode_listextattr = mac_biba_check_vnode_listextattr, 3404106217Srwatson .mpo_check_vnode_lookup = mac_biba_check_vnode_lookup, 3405106217Srwatson .mpo_check_vnode_mmap = mac_biba_check_vnode_mmap, 3406106217Srwatson .mpo_check_vnode_open = mac_biba_check_vnode_open, 3407106217Srwatson .mpo_check_vnode_poll = mac_biba_check_vnode_poll, 3408106217Srwatson .mpo_check_vnode_read = mac_biba_check_vnode_read, 3409106217Srwatson .mpo_check_vnode_readdir = mac_biba_check_vnode_readdir, 3410106217Srwatson .mpo_check_vnode_readlink = mac_biba_check_vnode_readlink, 3411106217Srwatson .mpo_check_vnode_relabel = mac_biba_check_vnode_relabel, 3412106217Srwatson .mpo_check_vnode_rename_from = mac_biba_check_vnode_rename_from, 3413106217Srwatson .mpo_check_vnode_rename_to = mac_biba_check_vnode_rename_to, 3414106217Srwatson .mpo_check_vnode_revoke = mac_biba_check_vnode_revoke, 3415106217Srwatson .mpo_check_vnode_setacl = mac_biba_check_vnode_setacl, 3416106217Srwatson .mpo_check_vnode_setextattr = mac_biba_check_vnode_setextattr, 3417106217Srwatson .mpo_check_vnode_setflags = mac_biba_check_vnode_setflags, 3418106217Srwatson .mpo_check_vnode_setmode = mac_biba_check_vnode_setmode, 3419106217Srwatson .mpo_check_vnode_setowner = mac_biba_check_vnode_setowner, 3420106217Srwatson .mpo_check_vnode_setutimes = mac_biba_check_vnode_setutimes, 3421106217Srwatson .mpo_check_vnode_stat = mac_biba_check_vnode_stat, 3422106217Srwatson .mpo_check_vnode_write = mac_biba_check_vnode_write, 3423160243Scsjp .mpo_associate_nfsd_label = mac_biba_associate_nfsd_label, 3424162238Scsjp .mpo_create_mbuf_from_firewall = mac_biba_create_mbuf_from_firewall, 3425168951Srwatson .mpo_priv_check = mac_biba_priv_check, 3426101099Srwatson}; 3427101099Srwatson 3428112717SrwatsonMAC_POLICY_SET(&mac_biba_ops, mac_biba, "TrustedBSD MAC/Biba", 3429113531Srwatson MPC_LOADTIME_FLAG_NOTLATE | MPC_LOADTIME_FLAG_LABELMBUFS, &mac_biba_slot); 3430