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