145916cd2Sjpk /* 245916cd2Sjpk * CDDL HEADER START 345916cd2Sjpk * 445916cd2Sjpk * The contents of this file are subject to the terms of the 545916cd2Sjpk * Common Development and Distribution License (the "License"). 645916cd2Sjpk * You may not use this file except in compliance with the License. 745916cd2Sjpk * 845916cd2Sjpk * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 945916cd2Sjpk * or http://www.opensolaris.org/os/licensing. 1045916cd2Sjpk * See the License for the specific language governing permissions 1145916cd2Sjpk * and limitations under the License. 1245916cd2Sjpk * 1345916cd2Sjpk * When distributing Covered Code, include this CDDL HEADER in each 1445916cd2Sjpk * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 1545916cd2Sjpk * If applicable, add the following below this CDDL HEADER, with the 1645916cd2Sjpk * fields enclosed by brackets "[]" replaced with your own identifying 1745916cd2Sjpk * information: Portions Copyright [yyyy] [name of copyright owner] 1845916cd2Sjpk * 1945916cd2Sjpk * CDDL HEADER END 2045916cd2Sjpk */ 2145916cd2Sjpk /* 22*80feccabSjarrett * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 2345916cd2Sjpk * Use is subject to license terms. 2445916cd2Sjpk */ 2545916cd2Sjpk 2645916cd2Sjpk #pragma ident "%Z%%M% %I% %E% SMI" 2745916cd2Sjpk 2845916cd2Sjpk /* 2945916cd2Sjpk * bl.c - Binary label operations for kernel and user. 3045916cd2Sjpk * 3145916cd2Sjpk * These routines initialize, compare, set and extract portions 3245916cd2Sjpk * of binary labels. 3345916cd2Sjpk */ 3445916cd2Sjpk 3545916cd2Sjpk #include <sys/tsol/label.h> 3645916cd2Sjpk #include <sys/tsol/label_macro.h> 3745916cd2Sjpk 3845916cd2Sjpk 3945916cd2Sjpk /* 4045916cd2Sjpk * bltype - Check the type of a label structure. 4145916cd2Sjpk * 4245916cd2Sjpk * Entry label = Address of the label to check. 4345916cd2Sjpk * type = Label type to check: 4445916cd2Sjpk * SUN_SL_ID = Sensitivity Label, 4545916cd2Sjpk * SUN_SL_UN = Undefined Sensitivity Label structure, 4645916cd2Sjpk * SUN_IL_ID = Information Label, 4745916cd2Sjpk * SUN_IL_UN = Undefined Information Label structure, 4845916cd2Sjpk * SUN_CLR_ID = Clearance, or 4945916cd2Sjpk * SUN_CLR_UN = Undefined Clearance structure. 5045916cd2Sjpk * 5145916cd2Sjpk * Exit None. 5245916cd2Sjpk * 5345916cd2Sjpk * Returns True if the label is the type requested, 5445916cd2Sjpk * otherwise false. 5545916cd2Sjpk * 5645916cd2Sjpk * Calls BLTYPE. 5745916cd2Sjpk */ 5845916cd2Sjpk 5945916cd2Sjpk int 6045916cd2Sjpk bltype(const void *label, uint8_t type) 6145916cd2Sjpk { 6245916cd2Sjpk 6345916cd2Sjpk return (BLTYPE(label, type)); 6445916cd2Sjpk } 6545916cd2Sjpk 6645916cd2Sjpk 6745916cd2Sjpk /* 6845916cd2Sjpk * blequal - Compare two labels for Classification and Compartments set 6945916cd2Sjpk * equality. 7045916cd2Sjpk * 7145916cd2Sjpk * Entry label1, label2 = label levels to compare. 7245916cd2Sjpk * 7345916cd2Sjpk * Exit None. 7445916cd2Sjpk * 7545916cd2Sjpk * Returns True if labels equal, 7645916cd2Sjpk * otherwise false. 7745916cd2Sjpk * 7845916cd2Sjpk * Calls BLEQUAL. 7945916cd2Sjpk */ 8045916cd2Sjpk 8145916cd2Sjpk int 8245916cd2Sjpk blequal(const m_label_t *label1, const m_label_t *label2) 8345916cd2Sjpk { 8445916cd2Sjpk 8545916cd2Sjpk return (BLEQUAL(label1, label2)); 8645916cd2Sjpk } 8745916cd2Sjpk 8845916cd2Sjpk 8945916cd2Sjpk /* 9045916cd2Sjpk * bldominates - Compare two labels for Classification and Compartments 9145916cd2Sjpk * sets dominance. 9245916cd2Sjpk * 9345916cd2Sjpk * Entry label1, label2 = labels levels to compare. 9445916cd2Sjpk * 9545916cd2Sjpk * Exit None. 9645916cd2Sjpk * 9745916cd2Sjpk * Returns True if label1 dominates label2, 9845916cd2Sjpk * otherwise false. 9945916cd2Sjpk * 10045916cd2Sjpk * Calls BLDOMINATES. 10145916cd2Sjpk */ 10245916cd2Sjpk 10345916cd2Sjpk int 10445916cd2Sjpk bldominates(const m_label_t *label1, const m_label_t *label2) 10545916cd2Sjpk { 10645916cd2Sjpk 10745916cd2Sjpk return (BLDOMINATES(label1, label2)); 10845916cd2Sjpk } 10945916cd2Sjpk 11045916cd2Sjpk 11145916cd2Sjpk /* 11245916cd2Sjpk * blstrictdom - Compare two labels for Classification and Compartments 11345916cd2Sjpk * sets strict dominance. 11445916cd2Sjpk * 11545916cd2Sjpk * Entry label1, label2 = labels levels to compare. 11645916cd2Sjpk * 11745916cd2Sjpk * Exit None. 11845916cd2Sjpk * 11945916cd2Sjpk * Returns True if label1 dominates and is not equal to label2, 12045916cd2Sjpk * otherwise false. 12145916cd2Sjpk * 12245916cd2Sjpk * Calls BLSTRICTDOM. 12345916cd2Sjpk */ 12445916cd2Sjpk 12545916cd2Sjpk int 12645916cd2Sjpk blstrictdom(const m_label_t *label1, const m_label_t *label2) 12745916cd2Sjpk { 12845916cd2Sjpk 12945916cd2Sjpk return (BLSTRICTDOM(label1, label2)); 13045916cd2Sjpk } 13145916cd2Sjpk 13245916cd2Sjpk 13345916cd2Sjpk /* 13445916cd2Sjpk * blinrange - Compare a label's classification and compartments set to 13545916cd2Sjpk * be within a lower and upper bound (range). 13645916cd2Sjpk * 13745916cd2Sjpk * Entry label = label level to compare. 13845916cd2Sjpk * range = level range to compare against. 13945916cd2Sjpk * 14045916cd2Sjpk * Exit None. 14145916cd2Sjpk * 14245916cd2Sjpk * Returns True if label is within the range, 14345916cd2Sjpk * otherwise false. 14445916cd2Sjpk * 14545916cd2Sjpk * Calls BLINRANGE. 14645916cd2Sjpk */ 14745916cd2Sjpk 14845916cd2Sjpk int 14945916cd2Sjpk blinrange(const m_label_t *label, const m_range_t *range) 15045916cd2Sjpk { 15145916cd2Sjpk return (BLDOMINATES((label), ((range)->lower_bound)) && 15245916cd2Sjpk BLDOMINATES(((range)->upper_bound), (label))); 15345916cd2Sjpk } 15445916cd2Sjpk 15545916cd2Sjpk /* 15645916cd2Sjpk * This is the TS8 version which is used in the kernel 15745916cd2Sjpk */ 15845916cd2Sjpk 15945916cd2Sjpk int 16045916cd2Sjpk _blinrange(const m_label_t *label, const brange_t *range) 16145916cd2Sjpk { 16245916cd2Sjpk return (BLINRANGE(label, range)); 16345916cd2Sjpk } 16445916cd2Sjpk 16545916cd2Sjpk #ifdef _KERNEL 16645916cd2Sjpk /* 16745916cd2Sjpk * blinlset - Check if the label belongs to the set 16845916cd2Sjpk * 16945916cd2Sjpk * Entry label = label level to compare. 17045916cd2Sjpk * lset = label set to compare against. 17145916cd2Sjpk * 17245916cd2Sjpk * Exit None. 17345916cd2Sjpk * 17445916cd2Sjpk * Returns True if label is an element of the set, 17545916cd2Sjpk * otherwise false. 17645916cd2Sjpk * 17745916cd2Sjpk */ 17845916cd2Sjpk 17945916cd2Sjpk int 18045916cd2Sjpk blinlset(const m_label_t *label, const blset_t lset) 18145916cd2Sjpk { 18245916cd2Sjpk int i; 18345916cd2Sjpk 184*80feccabSjarrett for (i = 0; i < NSLS_MAX; i++) { 185*80feccabSjarrett if (!BLTYPE(&lset[i], SUN_SL_ID)) 186*80feccabSjarrett return (B_FALSE); 18745916cd2Sjpk if (BLEQUAL(label, &lset[i])) 18845916cd2Sjpk return (B_TRUE); 189*80feccabSjarrett } 19045916cd2Sjpk return (B_FALSE); 19145916cd2Sjpk } 19245916cd2Sjpk #endif /* _KERNEL */ 19345916cd2Sjpk 19445916cd2Sjpk 19545916cd2Sjpk /* 19645916cd2Sjpk * blmaximum - Least Upper Bound of two levels. 19745916cd2Sjpk * 19845916cd2Sjpk * Entry label1, label2 = levels to bound. 19945916cd2Sjpk * 20045916cd2Sjpk * Exit label1 replaced by the LUB of label1 and label2. 20145916cd2Sjpk * 20245916cd2Sjpk * Returns None. 20345916cd2Sjpk * 20445916cd2Sjpk * Calls BLMAXIMUM. 20545916cd2Sjpk */ 20645916cd2Sjpk 20745916cd2Sjpk void 20845916cd2Sjpk blmaximum(m_label_t *label1, const m_label_t *label2) 20945916cd2Sjpk { 21045916cd2Sjpk 21145916cd2Sjpk BLMAXIMUM(label1, label2); 21245916cd2Sjpk } 21345916cd2Sjpk 21445916cd2Sjpk 21545916cd2Sjpk /* 21645916cd2Sjpk * blminimum - Greatest Lower Bound of two levels. 21745916cd2Sjpk * 21845916cd2Sjpk * Entry label1, label2 = levels to bound. 21945916cd2Sjpk * 22045916cd2Sjpk * Exit label1 replaced by the GLB of label1 and label2. 22145916cd2Sjpk * 22245916cd2Sjpk * Returns None. 22345916cd2Sjpk * 22445916cd2Sjpk * Calls BLMINIMUM. 22545916cd2Sjpk */ 22645916cd2Sjpk 22745916cd2Sjpk void 22845916cd2Sjpk blminimum(m_label_t *label1, const m_label_t *label2) 22945916cd2Sjpk { 23045916cd2Sjpk 23145916cd2Sjpk BLMINIMUM(label1, label2); 23245916cd2Sjpk } 23345916cd2Sjpk 23445916cd2Sjpk 23545916cd2Sjpk /* 23645916cd2Sjpk * bsllow - Initialize an admin_low Sensitivity Label. 23745916cd2Sjpk * 23845916cd2Sjpk * Entry label = Sensitivity Label structure to be initialized. 23945916cd2Sjpk * 24045916cd2Sjpk * Exit label = Initialized to the admin_low Sensitivity Label. 24145916cd2Sjpk * 24245916cd2Sjpk * Returns None. 24345916cd2Sjpk * 24445916cd2Sjpk * Calls BSLLOW. 24545916cd2Sjpk */ 24645916cd2Sjpk 24745916cd2Sjpk void 24845916cd2Sjpk bsllow(bslabel_t *label) 24945916cd2Sjpk { 25045916cd2Sjpk 25145916cd2Sjpk BSLLOW(label); 25245916cd2Sjpk } 25345916cd2Sjpk 25445916cd2Sjpk 25545916cd2Sjpk /* 25645916cd2Sjpk * bslhigh - Initialize an admin_high Sensitivity Label. 25745916cd2Sjpk * 25845916cd2Sjpk * Entry label = Sensitivity Label structure to be initialized. 25945916cd2Sjpk * 26045916cd2Sjpk * Exit label = Initialized to the admin_high Sensitivity Label. 26145916cd2Sjpk * 26245916cd2Sjpk * Returns None. 26345916cd2Sjpk * 26445916cd2Sjpk * Calls BSLHIGH. 26545916cd2Sjpk */ 26645916cd2Sjpk 26745916cd2Sjpk void 26845916cd2Sjpk bslhigh(bslabel_t *label) 26945916cd2Sjpk { 27045916cd2Sjpk 27145916cd2Sjpk BSLHIGH(label); 27245916cd2Sjpk } 27345916cd2Sjpk 27445916cd2Sjpk /* 27545916cd2Sjpk * bclearlow - Initialize an admin_low Clearance. 27645916cd2Sjpk * 27745916cd2Sjpk * Entry clearance = Clearnace structure to be initialized. 27845916cd2Sjpk * 27945916cd2Sjpk * Exit clearance = Initialized to the admin_low Clearance. 28045916cd2Sjpk * 28145916cd2Sjpk * Returns None. 28245916cd2Sjpk * 28345916cd2Sjpk * Calls BCLEARLOW. 28445916cd2Sjpk */ 28545916cd2Sjpk 28645916cd2Sjpk void 28745916cd2Sjpk bclearlow(bclear_t *clearance) 28845916cd2Sjpk { 28945916cd2Sjpk 29045916cd2Sjpk BCLEARLOW(clearance); 29145916cd2Sjpk } 29245916cd2Sjpk 29345916cd2Sjpk 29445916cd2Sjpk /* 29545916cd2Sjpk * bclearhigh - Initialize an admin_high Clearance. 29645916cd2Sjpk * 29745916cd2Sjpk * Entry clearance = Clearance structure to be initialized. 29845916cd2Sjpk * 29945916cd2Sjpk * Exit clearance = Initialized to the admin_high Clearance. 30045916cd2Sjpk * 30145916cd2Sjpk * Returns None. 30245916cd2Sjpk * 30345916cd2Sjpk * Calls BCLEARHIGH. 30445916cd2Sjpk */ 30545916cd2Sjpk 30645916cd2Sjpk void 30745916cd2Sjpk bclearhigh(bclear_t *clearance) 30845916cd2Sjpk { 30945916cd2Sjpk 31045916cd2Sjpk BCLEARHIGH(clearance); 31145916cd2Sjpk } 31245916cd2Sjpk 31345916cd2Sjpk /* 31445916cd2Sjpk * bslundef - Initialize an undefined Sensitivity Label. 31545916cd2Sjpk * 31645916cd2Sjpk * Entry label = Sensitivity Label structure to be initialized. 31745916cd2Sjpk * 31845916cd2Sjpk * Exit label = Initialized to undefined Sensitivity Label. 31945916cd2Sjpk * 32045916cd2Sjpk * Returns None. 32145916cd2Sjpk * 32245916cd2Sjpk * Calls BSLUNDEF. 32345916cd2Sjpk */ 32445916cd2Sjpk 32545916cd2Sjpk void 32645916cd2Sjpk bslundef(bslabel_t *label) 32745916cd2Sjpk { 32845916cd2Sjpk 32945916cd2Sjpk BSLUNDEF(label); 33045916cd2Sjpk } 33145916cd2Sjpk 33245916cd2Sjpk 33345916cd2Sjpk /* 33445916cd2Sjpk * bclearundef - Initialize an undefined Clearance. 33545916cd2Sjpk * 33645916cd2Sjpk * Entry clearance = Clearance structure to be initialized. 33745916cd2Sjpk * 33845916cd2Sjpk * Exit clearance = Initialized to undefined Clearance. 33945916cd2Sjpk * 34045916cd2Sjpk * Returns None. 34145916cd2Sjpk * 34245916cd2Sjpk * Calls BCLEARUNDEF. 34345916cd2Sjpk */ 34445916cd2Sjpk 34545916cd2Sjpk void 34645916cd2Sjpk bclearundef(bclear_t *clearance) 34745916cd2Sjpk { 34845916cd2Sjpk 34945916cd2Sjpk BCLEARUNDEF(clearance); 35045916cd2Sjpk } 35145916cd2Sjpk 35245916cd2Sjpk 35345916cd2Sjpk /* 35445916cd2Sjpk * setbltype - Set the type of a label structure. 35545916cd2Sjpk * 35645916cd2Sjpk * Entry label = Address of the label to set. 35745916cd2Sjpk * type = Label type to set: 35845916cd2Sjpk * SUN_SL_ID = Sensitivity Label, 35945916cd2Sjpk * SUN_SL_UN = Undefined Sensitivity Label structure, 36045916cd2Sjpk * SUN_IL_ID = Information Label, 36145916cd2Sjpk * SUN_IL_UN = Undefined Information Label structure, 36245916cd2Sjpk * SUN_CLR_ID = Clearance, or 36345916cd2Sjpk * SUN_CLR_UN = Undefined Clearance structure. 36445916cd2Sjpk * 36545916cd2Sjpk * Exit label = Type set to specified type. 36645916cd2Sjpk * 36745916cd2Sjpk * Returns None. 36845916cd2Sjpk * 36945916cd2Sjpk * Calls SETBLTYPE. 37045916cd2Sjpk */ 37145916cd2Sjpk 37245916cd2Sjpk void 37345916cd2Sjpk setbltype(void *label, uint8_t type) 37445916cd2Sjpk { 37545916cd2Sjpk 37645916cd2Sjpk SETBLTYPE(label, type); 37745916cd2Sjpk } 37845916cd2Sjpk 37945916cd2Sjpk /* 38045916cd2Sjpk * Returns B_TRUE if the label is invalid (initialized to all zeros). 38145916cd2Sjpk */ 38245916cd2Sjpk boolean_t 38345916cd2Sjpk bisinvalid(const void *label) 38445916cd2Sjpk { 38545916cd2Sjpk return (GETBLTYPE(label) == SUN_INVALID_ID); 38645916cd2Sjpk } 387