xref: /titanic_44/usr/src/uts/common/sys/tsol/label.h (revision 3289e1bdec732dbdf04517907516fd0d00f6a6f8)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_TSOL_LABEL_H
27 #define	_SYS_TSOL_LABEL_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/types.h>
32 #ifdef _KERNEL
33 #include <sys/cred.h>
34 #include <sys/vnode.h>
35 #include <sys/tsol/label_macro.h>
36 #endif /* _KERNEL */
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 /*
43  * types of label comparison
44  */
45 #define	EQUALITY_CHECK	0
46 #define	DOMINANCE_CHECK	1
47 
48 /* Binary Label Structure Definitions */
49 
50 typedef	struct _mac_label_impl	m_label_t;
51 
52 typedef m_label_t	blevel_t,		/* compatibility */
53 			bslabel_t,		/* Sensitivity Label */
54 			bclear_t;		/* Clearance */
55 
56 typedef struct _tsol_binary_level_lrange {	/* Level Range */
57 	m_label_t *lower_bound;
58 	m_label_t *upper_bound;
59 } m_range_t;
60 
61 typedef	m_range_t	blrange_t;
62 
63 typedef struct tsol_mlp_s {
64 	uchar_t mlp_ipp;
65 	uint16_t mlp_port;
66 	uint16_t mlp_port_upper;
67 } tsol_mlp_t;
68 
69 /* Procedure Interface Definitions available to user and kernel */
70 
71 extern int	bltype(const void *, uint8_t);
72 extern int	blequal(const m_label_t *, const m_label_t *);
73 extern int	bldominates(const m_label_t *, const m_label_t *);
74 extern int	blstrictdom(const m_label_t *, const m_label_t *);
75 extern int	blinrange(const m_label_t *, const m_range_t *);
76 extern void	blmaximum(m_label_t *, const m_label_t *);
77 extern void	blminimum(m_label_t *, const m_label_t *);
78 extern void	bsllow(m_label_t *);
79 extern void	bslhigh(m_label_t *);
80 extern void	bclearlow(m_label_t *);
81 extern void	bclearhigh(m_label_t *);
82 extern void	bslundef(m_label_t *);
83 extern void	bclearundef(m_label_t *);
84 extern void	setbltype(void *, uint8_t);
85 extern boolean_t	bisinvalid(const void *);
86 
87 #ifdef	_KERNEL
88 typedef struct tsol_mlp_entry_s {
89 	struct tsol_mlp_entry_s *mlpe_next, *mlpe_prev;
90 	zoneid_t mlpe_zoneid;
91 	tsol_mlp_t mlpe_mlp;
92 } tsol_mlp_entry_t;
93 
94 typedef struct tsol_mlp_list_s {
95 	krwlock_t mlpl_rwlock;
96 	tsol_mlp_entry_t *mlpl_first, *mlpl_last;
97 } tsol_mlp_list_t;
98 
99 typedef	struct ts_label_s {
100 	uint_t		tsl_ref;	/* Reference count */
101 	uint32_t	tsl_doi;	/* Domain of Interpretation */
102 	uint32_t	tsl_flags;	/* TSLF_* below */
103 	m_label_t	tsl_label;	/* Actual label */
104 } ts_label_t;
105 
106 #define	DEFAULT_DOI 1
107 
108 #define	TSLF_UNLABELED	0x00000001	/* source was unlabeled */
109 
110 #define	CR_SL(cr)	(label2bslabel(crgetlabel(cr)))
111 
112 extern ts_label_t	*l_admin_low;
113 extern ts_label_t	*l_admin_high;
114 extern uint32_t		default_doi;
115 extern int		sys_labeling;
116 
117 extern void		label_init(void);
118 extern ts_label_t	*labelalloc(const m_label_t *, uint32_t, int);
119 extern void		label_hold(ts_label_t *);
120 extern void		label_rele(ts_label_t *);
121 extern m_label_t	*label2bslabel(ts_label_t *);
122 extern uint32_t		label2doi(ts_label_t *);
123 extern boolean_t	label_equal(const ts_label_t *, const ts_label_t *);
124 extern cred_t 		*newcred_from_bslabel(m_label_t *, uint32_t, int);
125 extern cred_t 		*copycred_from_bslabel(cred_t *, m_label_t *,
126 			    uint32_t, int);
127 extern ts_label_t	*getflabel(vnode_t *);
128 extern int		getlabel(const char *, m_label_t *);
129 extern int		fgetlabel(int, m_label_t *);
130 extern int		_blinrange(const m_label_t *, const brange_t *);
131 extern int		blinlset(const m_label_t *, const blset_t);
132 extern ts_label_t	*nfs_getflabel(vnode_t *);
133 extern boolean_t	do_rfs_label_check(bslabel_t *, vnode_t *, int);
134 
135 /*
136  * The use of '!!' here prevents users from referencing this function-like
137  * macro as though it were an l-value, and in normal use is optimized away
138  * by the compiler.
139  */
140 #define	is_system_labeled()	(!!(sys_labeling > 0))
141 
142 #endif	/* _KERNEL */
143 
144 #ifdef	__cplusplus
145 }
146 #endif
147 
148 #endif	/* !_SYS_TSOL_LABEL_H */
149