1*45916cd2Sjpk /* 2*45916cd2Sjpk * CDDL HEADER START 3*45916cd2Sjpk * 4*45916cd2Sjpk * The contents of this file are subject to the terms of the 5*45916cd2Sjpk * Common Development and Distribution License (the "License"). 6*45916cd2Sjpk * You may not use this file except in compliance with the License. 7*45916cd2Sjpk * 8*45916cd2Sjpk * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*45916cd2Sjpk * or http://www.opensolaris.org/os/licensing. 10*45916cd2Sjpk * See the License for the specific language governing permissions 11*45916cd2Sjpk * and limitations under the License. 12*45916cd2Sjpk * 13*45916cd2Sjpk * When distributing Covered Code, include this CDDL HEADER in each 14*45916cd2Sjpk * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*45916cd2Sjpk * If applicable, add the following below this CDDL HEADER, with the 16*45916cd2Sjpk * fields enclosed by brackets "[]" replaced with your own identifying 17*45916cd2Sjpk * information: Portions Copyright [yyyy] [name of copyright owner] 18*45916cd2Sjpk * 19*45916cd2Sjpk * CDDL HEADER END 20*45916cd2Sjpk */ 21*45916cd2Sjpk /* 22*45916cd2Sjpk * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 23*45916cd2Sjpk * Use is subject to license terms. 24*45916cd2Sjpk */ 25*45916cd2Sjpk 26*45916cd2Sjpk #pragma ident "%Z%%M% %I% %E% SMI" 27*45916cd2Sjpk 28*45916cd2Sjpk /* 29*45916cd2Sjpk * bl.c - Binary label operations for kernel and user. 30*45916cd2Sjpk * 31*45916cd2Sjpk * These routines initialize, compare, set and extract portions 32*45916cd2Sjpk * of binary labels. 33*45916cd2Sjpk */ 34*45916cd2Sjpk 35*45916cd2Sjpk #include <sys/tsol/label.h> 36*45916cd2Sjpk #include <sys/tsol/label_macro.h> 37*45916cd2Sjpk 38*45916cd2Sjpk 39*45916cd2Sjpk /* 40*45916cd2Sjpk * bltype - Check the type of a label structure. 41*45916cd2Sjpk * 42*45916cd2Sjpk * Entry label = Address of the label to check. 43*45916cd2Sjpk * type = Label type to check: 44*45916cd2Sjpk * SUN_SL_ID = Sensitivity Label, 45*45916cd2Sjpk * SUN_SL_UN = Undefined Sensitivity Label structure, 46*45916cd2Sjpk * SUN_IL_ID = Information Label, 47*45916cd2Sjpk * SUN_IL_UN = Undefined Information Label structure, 48*45916cd2Sjpk * SUN_CLR_ID = Clearance, or 49*45916cd2Sjpk * SUN_CLR_UN = Undefined Clearance structure. 50*45916cd2Sjpk * 51*45916cd2Sjpk * Exit None. 52*45916cd2Sjpk * 53*45916cd2Sjpk * Returns True if the label is the type requested, 54*45916cd2Sjpk * otherwise false. 55*45916cd2Sjpk * 56*45916cd2Sjpk * Calls BLTYPE. 57*45916cd2Sjpk */ 58*45916cd2Sjpk 59*45916cd2Sjpk int 60*45916cd2Sjpk bltype(const void *label, uint8_t type) 61*45916cd2Sjpk { 62*45916cd2Sjpk 63*45916cd2Sjpk return (BLTYPE(label, type)); 64*45916cd2Sjpk } 65*45916cd2Sjpk 66*45916cd2Sjpk 67*45916cd2Sjpk /* 68*45916cd2Sjpk * blequal - Compare two labels for Classification and Compartments set 69*45916cd2Sjpk * equality. 70*45916cd2Sjpk * 71*45916cd2Sjpk * Entry label1, label2 = label levels to compare. 72*45916cd2Sjpk * 73*45916cd2Sjpk * Exit None. 74*45916cd2Sjpk * 75*45916cd2Sjpk * Returns True if labels equal, 76*45916cd2Sjpk * otherwise false. 77*45916cd2Sjpk * 78*45916cd2Sjpk * Calls BLEQUAL. 79*45916cd2Sjpk */ 80*45916cd2Sjpk 81*45916cd2Sjpk int 82*45916cd2Sjpk blequal(const m_label_t *label1, const m_label_t *label2) 83*45916cd2Sjpk { 84*45916cd2Sjpk 85*45916cd2Sjpk return (BLEQUAL(label1, label2)); 86*45916cd2Sjpk } 87*45916cd2Sjpk 88*45916cd2Sjpk 89*45916cd2Sjpk /* 90*45916cd2Sjpk * bldominates - Compare two labels for Classification and Compartments 91*45916cd2Sjpk * sets dominance. 92*45916cd2Sjpk * 93*45916cd2Sjpk * Entry label1, label2 = labels levels to compare. 94*45916cd2Sjpk * 95*45916cd2Sjpk * Exit None. 96*45916cd2Sjpk * 97*45916cd2Sjpk * Returns True if label1 dominates label2, 98*45916cd2Sjpk * otherwise false. 99*45916cd2Sjpk * 100*45916cd2Sjpk * Calls BLDOMINATES. 101*45916cd2Sjpk */ 102*45916cd2Sjpk 103*45916cd2Sjpk int 104*45916cd2Sjpk bldominates(const m_label_t *label1, const m_label_t *label2) 105*45916cd2Sjpk { 106*45916cd2Sjpk 107*45916cd2Sjpk return (BLDOMINATES(label1, label2)); 108*45916cd2Sjpk } 109*45916cd2Sjpk 110*45916cd2Sjpk 111*45916cd2Sjpk /* 112*45916cd2Sjpk * blstrictdom - Compare two labels for Classification and Compartments 113*45916cd2Sjpk * sets strict dominance. 114*45916cd2Sjpk * 115*45916cd2Sjpk * Entry label1, label2 = labels levels to compare. 116*45916cd2Sjpk * 117*45916cd2Sjpk * Exit None. 118*45916cd2Sjpk * 119*45916cd2Sjpk * Returns True if label1 dominates and is not equal to label2, 120*45916cd2Sjpk * otherwise false. 121*45916cd2Sjpk * 122*45916cd2Sjpk * Calls BLSTRICTDOM. 123*45916cd2Sjpk */ 124*45916cd2Sjpk 125*45916cd2Sjpk int 126*45916cd2Sjpk blstrictdom(const m_label_t *label1, const m_label_t *label2) 127*45916cd2Sjpk { 128*45916cd2Sjpk 129*45916cd2Sjpk return (BLSTRICTDOM(label1, label2)); 130*45916cd2Sjpk } 131*45916cd2Sjpk 132*45916cd2Sjpk 133*45916cd2Sjpk /* 134*45916cd2Sjpk * blinrange - Compare a label's classification and compartments set to 135*45916cd2Sjpk * be within a lower and upper bound (range). 136*45916cd2Sjpk * 137*45916cd2Sjpk * Entry label = label level to compare. 138*45916cd2Sjpk * range = level range to compare against. 139*45916cd2Sjpk * 140*45916cd2Sjpk * Exit None. 141*45916cd2Sjpk * 142*45916cd2Sjpk * Returns True if label is within the range, 143*45916cd2Sjpk * otherwise false. 144*45916cd2Sjpk * 145*45916cd2Sjpk * Calls BLINRANGE. 146*45916cd2Sjpk */ 147*45916cd2Sjpk 148*45916cd2Sjpk int 149*45916cd2Sjpk blinrange(const m_label_t *label, const m_range_t *range) 150*45916cd2Sjpk { 151*45916cd2Sjpk return (BLDOMINATES((label), ((range)->lower_bound)) && 152*45916cd2Sjpk BLDOMINATES(((range)->upper_bound), (label))); 153*45916cd2Sjpk } 154*45916cd2Sjpk 155*45916cd2Sjpk /* 156*45916cd2Sjpk * This is the TS8 version which is used in the kernel 157*45916cd2Sjpk */ 158*45916cd2Sjpk 159*45916cd2Sjpk int 160*45916cd2Sjpk _blinrange(const m_label_t *label, const brange_t *range) 161*45916cd2Sjpk { 162*45916cd2Sjpk return (BLINRANGE(label, range)); 163*45916cd2Sjpk } 164*45916cd2Sjpk 165*45916cd2Sjpk #ifdef _KERNEL 166*45916cd2Sjpk /* 167*45916cd2Sjpk * blinlset - Check if the label belongs to the set 168*45916cd2Sjpk * 169*45916cd2Sjpk * Entry label = label level to compare. 170*45916cd2Sjpk * lset = label set to compare against. 171*45916cd2Sjpk * 172*45916cd2Sjpk * Exit None. 173*45916cd2Sjpk * 174*45916cd2Sjpk * Returns True if label is an element of the set, 175*45916cd2Sjpk * otherwise false. 176*45916cd2Sjpk * 177*45916cd2Sjpk */ 178*45916cd2Sjpk 179*45916cd2Sjpk int 180*45916cd2Sjpk blinlset(const m_label_t *label, const blset_t lset) 181*45916cd2Sjpk { 182*45916cd2Sjpk int i; 183*45916cd2Sjpk 184*45916cd2Sjpk for (i = 0; i < NSLS_MAX; i++) 185*45916cd2Sjpk if (BLEQUAL(label, &lset[i])) 186*45916cd2Sjpk return (B_TRUE); 187*45916cd2Sjpk return (B_FALSE); 188*45916cd2Sjpk } 189*45916cd2Sjpk #endif /* _KERNEL */ 190*45916cd2Sjpk 191*45916cd2Sjpk 192*45916cd2Sjpk /* 193*45916cd2Sjpk * blmaximum - Least Upper Bound of two levels. 194*45916cd2Sjpk * 195*45916cd2Sjpk * Entry label1, label2 = levels to bound. 196*45916cd2Sjpk * 197*45916cd2Sjpk * Exit label1 replaced by the LUB of label1 and label2. 198*45916cd2Sjpk * 199*45916cd2Sjpk * Returns None. 200*45916cd2Sjpk * 201*45916cd2Sjpk * Calls BLMAXIMUM. 202*45916cd2Sjpk */ 203*45916cd2Sjpk 204*45916cd2Sjpk void 205*45916cd2Sjpk blmaximum(m_label_t *label1, const m_label_t *label2) 206*45916cd2Sjpk { 207*45916cd2Sjpk 208*45916cd2Sjpk BLMAXIMUM(label1, label2); 209*45916cd2Sjpk } 210*45916cd2Sjpk 211*45916cd2Sjpk 212*45916cd2Sjpk /* 213*45916cd2Sjpk * blminimum - Greatest Lower Bound of two levels. 214*45916cd2Sjpk * 215*45916cd2Sjpk * Entry label1, label2 = levels to bound. 216*45916cd2Sjpk * 217*45916cd2Sjpk * Exit label1 replaced by the GLB of label1 and label2. 218*45916cd2Sjpk * 219*45916cd2Sjpk * Returns None. 220*45916cd2Sjpk * 221*45916cd2Sjpk * Calls BLMINIMUM. 222*45916cd2Sjpk */ 223*45916cd2Sjpk 224*45916cd2Sjpk void 225*45916cd2Sjpk blminimum(m_label_t *label1, const m_label_t *label2) 226*45916cd2Sjpk { 227*45916cd2Sjpk 228*45916cd2Sjpk BLMINIMUM(label1, label2); 229*45916cd2Sjpk } 230*45916cd2Sjpk 231*45916cd2Sjpk 232*45916cd2Sjpk /* 233*45916cd2Sjpk * bsllow - Initialize an admin_low Sensitivity Label. 234*45916cd2Sjpk * 235*45916cd2Sjpk * Entry label = Sensitivity Label structure to be initialized. 236*45916cd2Sjpk * 237*45916cd2Sjpk * Exit label = Initialized to the admin_low Sensitivity Label. 238*45916cd2Sjpk * 239*45916cd2Sjpk * Returns None. 240*45916cd2Sjpk * 241*45916cd2Sjpk * Calls BSLLOW. 242*45916cd2Sjpk */ 243*45916cd2Sjpk 244*45916cd2Sjpk void 245*45916cd2Sjpk bsllow(bslabel_t *label) 246*45916cd2Sjpk { 247*45916cd2Sjpk 248*45916cd2Sjpk BSLLOW(label); 249*45916cd2Sjpk } 250*45916cd2Sjpk 251*45916cd2Sjpk 252*45916cd2Sjpk /* 253*45916cd2Sjpk * bslhigh - Initialize an admin_high Sensitivity Label. 254*45916cd2Sjpk * 255*45916cd2Sjpk * Entry label = Sensitivity Label structure to be initialized. 256*45916cd2Sjpk * 257*45916cd2Sjpk * Exit label = Initialized to the admin_high Sensitivity Label. 258*45916cd2Sjpk * 259*45916cd2Sjpk * Returns None. 260*45916cd2Sjpk * 261*45916cd2Sjpk * Calls BSLHIGH. 262*45916cd2Sjpk */ 263*45916cd2Sjpk 264*45916cd2Sjpk void 265*45916cd2Sjpk bslhigh(bslabel_t *label) 266*45916cd2Sjpk { 267*45916cd2Sjpk 268*45916cd2Sjpk BSLHIGH(label); 269*45916cd2Sjpk } 270*45916cd2Sjpk 271*45916cd2Sjpk /* 272*45916cd2Sjpk * bclearlow - Initialize an admin_low Clearance. 273*45916cd2Sjpk * 274*45916cd2Sjpk * Entry clearance = Clearnace structure to be initialized. 275*45916cd2Sjpk * 276*45916cd2Sjpk * Exit clearance = Initialized to the admin_low Clearance. 277*45916cd2Sjpk * 278*45916cd2Sjpk * Returns None. 279*45916cd2Sjpk * 280*45916cd2Sjpk * Calls BCLEARLOW. 281*45916cd2Sjpk */ 282*45916cd2Sjpk 283*45916cd2Sjpk void 284*45916cd2Sjpk bclearlow(bclear_t *clearance) 285*45916cd2Sjpk { 286*45916cd2Sjpk 287*45916cd2Sjpk BCLEARLOW(clearance); 288*45916cd2Sjpk } 289*45916cd2Sjpk 290*45916cd2Sjpk 291*45916cd2Sjpk /* 292*45916cd2Sjpk * bclearhigh - Initialize an admin_high Clearance. 293*45916cd2Sjpk * 294*45916cd2Sjpk * Entry clearance = Clearance structure to be initialized. 295*45916cd2Sjpk * 296*45916cd2Sjpk * Exit clearance = Initialized to the admin_high Clearance. 297*45916cd2Sjpk * 298*45916cd2Sjpk * Returns None. 299*45916cd2Sjpk * 300*45916cd2Sjpk * Calls BCLEARHIGH. 301*45916cd2Sjpk */ 302*45916cd2Sjpk 303*45916cd2Sjpk void 304*45916cd2Sjpk bclearhigh(bclear_t *clearance) 305*45916cd2Sjpk { 306*45916cd2Sjpk 307*45916cd2Sjpk BCLEARHIGH(clearance); 308*45916cd2Sjpk } 309*45916cd2Sjpk 310*45916cd2Sjpk /* 311*45916cd2Sjpk * bslundef - Initialize an undefined Sensitivity Label. 312*45916cd2Sjpk * 313*45916cd2Sjpk * Entry label = Sensitivity Label structure to be initialized. 314*45916cd2Sjpk * 315*45916cd2Sjpk * Exit label = Initialized to undefined Sensitivity Label. 316*45916cd2Sjpk * 317*45916cd2Sjpk * Returns None. 318*45916cd2Sjpk * 319*45916cd2Sjpk * Calls BSLUNDEF. 320*45916cd2Sjpk */ 321*45916cd2Sjpk 322*45916cd2Sjpk void 323*45916cd2Sjpk bslundef(bslabel_t *label) 324*45916cd2Sjpk { 325*45916cd2Sjpk 326*45916cd2Sjpk BSLUNDEF(label); 327*45916cd2Sjpk } 328*45916cd2Sjpk 329*45916cd2Sjpk 330*45916cd2Sjpk /* 331*45916cd2Sjpk * bclearundef - Initialize an undefined Clearance. 332*45916cd2Sjpk * 333*45916cd2Sjpk * Entry clearance = Clearance structure to be initialized. 334*45916cd2Sjpk * 335*45916cd2Sjpk * Exit clearance = Initialized to undefined Clearance. 336*45916cd2Sjpk * 337*45916cd2Sjpk * Returns None. 338*45916cd2Sjpk * 339*45916cd2Sjpk * Calls BCLEARUNDEF. 340*45916cd2Sjpk */ 341*45916cd2Sjpk 342*45916cd2Sjpk void 343*45916cd2Sjpk bclearundef(bclear_t *clearance) 344*45916cd2Sjpk { 345*45916cd2Sjpk 346*45916cd2Sjpk BCLEARUNDEF(clearance); 347*45916cd2Sjpk } 348*45916cd2Sjpk 349*45916cd2Sjpk 350*45916cd2Sjpk /* 351*45916cd2Sjpk * setbltype - Set the type of a label structure. 352*45916cd2Sjpk * 353*45916cd2Sjpk * Entry label = Address of the label to set. 354*45916cd2Sjpk * type = Label type to set: 355*45916cd2Sjpk * SUN_SL_ID = Sensitivity Label, 356*45916cd2Sjpk * SUN_SL_UN = Undefined Sensitivity Label structure, 357*45916cd2Sjpk * SUN_IL_ID = Information Label, 358*45916cd2Sjpk * SUN_IL_UN = Undefined Information Label structure, 359*45916cd2Sjpk * SUN_CLR_ID = Clearance, or 360*45916cd2Sjpk * SUN_CLR_UN = Undefined Clearance structure. 361*45916cd2Sjpk * 362*45916cd2Sjpk * Exit label = Type set to specified type. 363*45916cd2Sjpk * 364*45916cd2Sjpk * Returns None. 365*45916cd2Sjpk * 366*45916cd2Sjpk * Calls SETBLTYPE. 367*45916cd2Sjpk */ 368*45916cd2Sjpk 369*45916cd2Sjpk void 370*45916cd2Sjpk setbltype(void *label, uint8_t type) 371*45916cd2Sjpk { 372*45916cd2Sjpk 373*45916cd2Sjpk SETBLTYPE(label, type); 374*45916cd2Sjpk } 375*45916cd2Sjpk 376*45916cd2Sjpk /* 377*45916cd2Sjpk * Returns B_TRUE if the label is invalid (initialized to all zeros). 378*45916cd2Sjpk */ 379*45916cd2Sjpk boolean_t 380*45916cd2Sjpk bisinvalid(const void *label) 381*45916cd2Sjpk { 382*45916cd2Sjpk return (GETBLTYPE(label) == SUN_INVALID_ID); 383*45916cd2Sjpk } 384