Skip to content

Commit ba75082

Browse files
committed
Merge tag 'selinux-pr-20191126' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux
Pull selinux updates from Paul Moore: "Only three SELinux patches for v5.5: - Remove the size limit on SELinux policies, the limitation was a lingering vestige and no longer necessary. - Allow file labeling before the policy is loaded. This should ease some of the burden when the policy is initially loaded (no need to relabel files), but it should also help enable some new system concepts which dynamically create the root filesystem in the initrd. - Add support for the "greatest lower bound" policy construct which is defined as the intersection of the MLS range of two SELinux labels" * tag 'selinux-pr-20191126' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux: selinux: default_range glblub implementation selinux: allow labeling before policy is loaded selinux: remove load size limit
2 parents 8a99117 + 42345b6 commit ba75082

File tree

9 files changed

+74
-5
lines changed

9 files changed

+74
-5
lines changed

security/selinux/hooks.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3144,6 +3144,9 @@ static int selinux_inode_setxattr(struct dentry *dentry, const char *name,
31443144
return dentry_has_perm(current_cred(), dentry, FILE__SETATTR);
31453145
}
31463146

3147+
if (!selinux_state.initialized)
3148+
return (inode_owner_or_capable(inode) ? 0 : -EPERM);
3149+
31473150
sbsec = inode->i_sb->s_security;
31483151
if (!(sbsec->flags & SBLABEL_MNT))
31493152
return -EOPNOTSUPP;
@@ -3227,6 +3230,15 @@ static void selinux_inode_post_setxattr(struct dentry *dentry, const char *name,
32273230
return;
32283231
}
32293232

3233+
if (!selinux_state.initialized) {
3234+
/* If we haven't even been initialized, then we can't validate
3235+
* against a policy, so leave the label as invalid. It may
3236+
* resolve to a valid label on the next revalidation try if
3237+
* we've since initialized.
3238+
*/
3239+
return;
3240+
}
3241+
32303242
rc = security_context_to_sid_force(&selinux_state, value, size,
32313243
&newsid);
32323244
if (rc) {

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/selinuxfs.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -548,10 +548,6 @@ static ssize_t sel_write_load(struct file *file, const char __user *buf,
548548
if (*ppos != 0)
549549
goto out;
550550

551-
length = -EFBIG;
552-
if (count > 64 * 1024 * 1024)
553-
goto out;
554-
555551
length = -ENOMEM;
556552
data = vmalloc(count);
557553
if (!data)

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)