xref: /freebsd/sys/security/mac_mls/mac_mls.h (revision 95ee2897)
1 /*-
2  * Copyright (c) 1999-2002 Robert N. M. Watson
3  * Copyright (c) 2001-2004 Networks Associates Technology, Inc.
4  * All rights reserved.
5  *
6  * This software was developed by Robert Watson for the TrustedBSD Project.
7  *
8  * This software was developed for the FreeBSD Project in part by Network
9  * Associates Laboratories, the Security Research Division of Network
10  * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
11  * as part of the DARPA CHATS research program.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright
19  *    notice, this list of conditions and the following disclaimer in the
20  *    documentation and/or other materials provided with the distribution.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  */
34 /*
35  * Definitions for the TrustedBSD MLS confidentiality policy module.
36  */
37 #ifndef _SYS_SECURITY_MAC_MLS_H
38 #define	_SYS_SECURITY_MAC_MLS_H
39 
40 #define	MAC_MLS_EXTATTR_NAMESPACE	EXTATTR_NAMESPACE_SYSTEM
41 #define	MAC_MLS_EXTATTR_NAME		"mac_mls"
42 
43 #define	MAC_MLS_LABEL_NAME		"mls"
44 
45 #define	MAC_MLS_FLAG_EFFECTIVE	0x00000001	/* mm_effective initialized */
46 #define	MAC_MLS_FLAG_RANGE	0x00000002	/* mm_range* initialized */
47 #define	MAC_MLS_FLAGS_BOTH	(MAC_MLS_FLAG_EFFECTIVE | MAC_MLS_FLAG_RANGE)
48 
49 #define	MAC_MLS_TYPE_UNDEF	0	/* Undefined */
50 #define	MAC_MLS_TYPE_LEVEL	1	/* Hierarchal level with mm_level. */
51 #define	MAC_MLS_TYPE_LOW	2	/* Dominated by any
52 					 * MAC_MLS_TYPE_LABEL. */
53 #define	MAC_MLS_TYPE_HIGH	3	/* Dominates any
54 					 * MAC_MLS_TYPE_LABEL. */
55 #define	MAC_MLS_TYPE_EQUAL	4	/* Equivalent to any
56 					 * MAC_MLS_TYPE_LABEL. */
57 
58 /*
59  * Structures and constants associated with a Multi-Level Security policy.
60  * mac_mls represents an MLS label, with mm_type determining its properties,
61  * and mm_level represents the hierarchal sensitivity level if valid for the
62  * current mm_type.  If compartments are used, the same semantics apply as
63  * long as the suject is in every compartment the object is in.  LOW, EQUAL
64  * and HIGH cannot be in compartments.
65  */
66 
67 /*
68  * MLS compartments bit set size (in bits).
69  */
70 #define	MAC_MLS_MAX_COMPARTMENTS	256
71 
72 struct mac_mls_element {
73 	u_short	mme_type;
74 	u_short	mme_level;
75 	u_char	mme_compartments[MAC_MLS_MAX_COMPARTMENTS >> 3];
76 };
77 
78 /*
79  * MLS labels consist of two components: an effective label, and a label
80  * range.  Depending on the context, one or both may be used; the mb_flags
81  * field permits the provider to indicate what fields are intended for
82  * use.
83  */
84 struct mac_mls {
85 	int			mm_flags;
86 	struct mac_mls_element	mm_effective;
87 	struct mac_mls_element	mm_rangelow, mm_rangehigh;
88 };
89 
90 /*
91  * MLS compartments bit test/set macros.
92  * The range is 1 to MAC_MLS_MAX_COMPARTMENTS.
93  */
94 #define	MAC_MLS_BIT_TEST(b, w) \
95 	((w)[(((b) - 1) >> 3)] & (1 << (((b) - 1) & 7)))
96 #define	MAC_MLS_BIT_SET(b, w) \
97 	((w)[(((b) - 1) >> 3)] |= (1 << (((b) - 1) & 7)))
98 #define	MAC_MLS_BIT_SET_EMPTY(set)	mls_bit_set_empty(set)
99 
100 #endif /* !_SYS_SECURITY_MAC_MLS_H */
101