Skip to content

Commit 42345b6

Browse files
jbrindlepcmoore
authored andcommitted
selinux: default_range glblub implementation
A policy developer can now specify glblub as a default_range default and the computed transition will be the intersection of the mls range of the two contexts. The glb (greatest lower bound) lub (lowest upper bound) of a range is calculated as the greater of the low sensitivities and the lower of the high sensitivities and the and of each category bitmap. This can be used by MLS solution developers to compute a context that satisfies, for example, the range of a network interface and the range of a user logging in. Some examples are: User Permitted Range | Network Device Label | Computed Label ---------------------|----------------------|---------------- s0-s1:c0.c12 | s0 | s0 s0-s1:c0.c12 | s0-s1:c0.c1023 | s0-s1:c0.c12 s0-s4:c0.c512 | s1-s1:c0.c1023 | s1-s1:c0.c512 s0-s15:c0,c2 | s4-s6:c0.c128 | s4-s6:c0,c2 s0-s4 | s2-s6 | s2-s4 s0-s4 | s5-s8 | INVALID s5-s8 | s0-s4 | INVALID Signed-off-by: Joshua Brindle <[email protected]> [PM: subject lines and checkpatch.pl fixes] Signed-off-by: Paul Moore <[email protected]>
1 parent 3e3e24b commit 42345b6

File tree

7 files changed

+62
-1
lines changed

7 files changed

+62
-1
lines changed

security/selinux/include/security.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@
4040
#define POLICYDB_VERSION_CONSTRAINT_NAMES 29
4141
#define POLICYDB_VERSION_XPERMS_IOCTL 30
4242
#define POLICYDB_VERSION_INFINIBAND 31
43+
#define POLICYDB_VERSION_GLBLUB 32
4344

4445
/* Range of policy versions we understand*/
4546
#define POLICYDB_VERSION_MIN POLICYDB_VERSION_BASE
46-
#define POLICYDB_VERSION_MAX POLICYDB_VERSION_INFINIBAND
47+
#define POLICYDB_VERSION_MAX POLICYDB_VERSION_GLBLUB
4748

4849
/* Mask for just the mount related flags */
4950
#define SE_MNTMASK 0x0f

security/selinux/ss/context.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,38 @@ static inline int mls_context_cpy_high(struct context *dst, struct context *src)
9595
return rc;
9696
}
9797

98+
99+
static inline int mls_context_glblub(struct context *dst,
100+
struct context *c1, struct context *c2)
101+
{
102+
struct mls_range *dr = &dst->range, *r1 = &c1->range, *r2 = &c2->range;
103+
int rc = 0;
104+
105+
if (r1->level[1].sens < r2->level[0].sens ||
106+
r2->level[1].sens < r1->level[0].sens)
107+
/* These ranges have no common sensitivities */
108+
return -EINVAL;
109+
110+
/* Take the greatest of the low */
111+
dr->level[0].sens = max(r1->level[0].sens, r2->level[0].sens);
112+
113+
/* Take the least of the high */
114+
dr->level[1].sens = min(r1->level[1].sens, r2->level[1].sens);
115+
116+
rc = ebitmap_and(&dr->level[0].cat,
117+
&r1->level[0].cat, &r2->level[0].cat);
118+
if (rc)
119+
goto out;
120+
121+
rc = ebitmap_and(&dr->level[1].cat,
122+
&r1->level[1].cat, &r2->level[1].cat);
123+
if (rc)
124+
goto out;
125+
126+
out:
127+
return rc;
128+
}
129+
98130
static inline int mls_context_cmp(struct context *c1, struct context *c2)
99131
{
100132
return ((c1->range.level[0].sens == c2->range.level[0].sens) &&

security/selinux/ss/ebitmap.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,24 @@ int ebitmap_cpy(struct ebitmap *dst, struct ebitmap *src)
7777
return 0;
7878
}
7979

80+
int ebitmap_and(struct ebitmap *dst, struct ebitmap *e1, struct ebitmap *e2)
81+
{
82+
struct ebitmap_node *n;
83+
int bit, rc;
84+
85+
ebitmap_init(dst);
86+
87+
ebitmap_for_each_positive_bit(e1, n, bit) {
88+
if (ebitmap_get_bit(e2, bit)) {
89+
rc = ebitmap_set_bit(dst, bit, 1);
90+
if (rc < 0)
91+
return rc;
92+
}
93+
}
94+
return 0;
95+
}
96+
97+
8098
#ifdef CONFIG_NETLABEL
8199
/**
82100
* ebitmap_netlbl_export - Export an ebitmap into a NetLabel category bitmap

security/selinux/ss/ebitmap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ static inline void ebitmap_node_clr_bit(struct ebitmap_node *n,
124124

125125
int ebitmap_cmp(struct ebitmap *e1, struct ebitmap *e2);
126126
int ebitmap_cpy(struct ebitmap *dst, struct ebitmap *src);
127+
int ebitmap_and(struct ebitmap *dst, struct ebitmap *e1, struct ebitmap *e2);
127128
int ebitmap_contains(struct ebitmap *e1, struct ebitmap *e2, u32 last_e2bit);
128129
int ebitmap_get_bit(struct ebitmap *e, unsigned long bit);
129130
int ebitmap_set_bit(struct ebitmap *e, unsigned long bit, int value);

security/selinux/ss/mls.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,9 @@ int mls_compute_sid(struct policydb *p,
529529
return mls_context_cpy_high(newcontext, tcontext);
530530
case DEFAULT_TARGET_LOW_HIGH:
531531
return mls_context_cpy(newcontext, tcontext);
532+
case DEFAULT_GLBLUB:
533+
return mls_context_glblub(newcontext,
534+
scontext, tcontext);
532535
}
533536

534537
/* Fallthrough */

security/selinux/ss/policydb.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ static struct policydb_compat_info policydb_compat[] = {
160160
.sym_num = SYM_NUM,
161161
.ocon_num = OCON_NUM,
162162
},
163+
{
164+
.version = POLICYDB_VERSION_GLBLUB,
165+
.sym_num = SYM_NUM,
166+
.ocon_num = OCON_NUM,
167+
},
163168
};
164169

165170
static struct policydb_compat_info *policydb_lookup_compat(int version)

security/selinux/ss/policydb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ struct class_datum {
6969
#define DEFAULT_TARGET_LOW 4
7070
#define DEFAULT_TARGET_HIGH 5
7171
#define DEFAULT_TARGET_LOW_HIGH 6
72+
#define DEFAULT_GLBLUB 7
7273
char default_range;
7374
};
7475

0 commit comments

Comments
 (0)