Skip to content

Commit 4d546f8

Browse files
committed
selinux: revert 102aefd
Revert "selinux: consider filesystem subtype in policies" This reverts commit 102aefd. Explanation from Eric Paris: SELinux policy can specify if it should use a filesystem's xattrs or not. In current policy we have a specification that fuse should not use xattrs but fuse.glusterfs should use xattrs. This patch has a bug in which non-glusterfs filesystems would match the rule saying fuse.glusterfs should use xattrs. If both fuse and the particular filesystem in question are not written to handle xattr calls during the mount command, they will deadlock. I have fixed the bug to do proper matching, however I believe a revert is still the correct solution. The reason I believe that is because the code still does not work. The s_subtype is not set until after the SELinux hook which attempts to match on the ".gluster" portion of the rule. So we cannot match on the rule in question. The code is useless. Signed-off-by: Paul Moore <[email protected]>
1 parent 598cdbc commit 4d546f8

File tree

2 files changed

+22
-60
lines changed

2 files changed

+22
-60
lines changed

security/selinux/hooks.c

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,6 @@
9696
#include "audit.h"
9797
#include "avc_ss.h"
9898

99-
#define SB_TYPE_FMT "%s%s%s"
100-
#define SB_SUBTYPE(sb) (sb->s_subtype && sb->s_subtype[0])
101-
#define SB_TYPE_ARGS(sb) sb->s_type->name, SB_SUBTYPE(sb) ? "." : "", SB_SUBTYPE(sb) ? sb->s_subtype : ""
102-
10399
extern struct security_operations *security_ops;
104100

105101
/* SECMARK reference count */
@@ -414,31 +410,31 @@ static int sb_finish_set_opts(struct super_block *sb)
414410
the first boot of the SELinux kernel before we have
415411
assigned xattr values to the filesystem. */
416412
if (!root_inode->i_op->getxattr) {
417-
printk(KERN_WARNING "SELinux: (dev %s, type "SB_TYPE_FMT") has no "
418-
"xattr support\n", sb->s_id, SB_TYPE_ARGS(sb));
413+
printk(KERN_WARNING "SELinux: (dev %s, type %s) has no "
414+
"xattr support\n", sb->s_id, sb->s_type->name);
419415
rc = -EOPNOTSUPP;
420416
goto out;
421417
}
422418
rc = root_inode->i_op->getxattr(root, XATTR_NAME_SELINUX, NULL, 0);
423419
if (rc < 0 && rc != -ENODATA) {
424420
if (rc == -EOPNOTSUPP)
425421
printk(KERN_WARNING "SELinux: (dev %s, type "
426-
SB_TYPE_FMT") has no security xattr handler\n",
427-
sb->s_id, SB_TYPE_ARGS(sb));
422+
"%s) has no security xattr handler\n",
423+
sb->s_id, sb->s_type->name);
428424
else
429425
printk(KERN_WARNING "SELinux: (dev %s, type "
430-
SB_TYPE_FMT") getxattr errno %d\n", sb->s_id,
431-
SB_TYPE_ARGS(sb), -rc);
426+
"%s) getxattr errno %d\n", sb->s_id,
427+
sb->s_type->name, -rc);
432428
goto out;
433429
}
434430
}
435431

436432
if (sbsec->behavior > ARRAY_SIZE(labeling_behaviors))
437-
printk(KERN_ERR "SELinux: initialized (dev %s, type "SB_TYPE_FMT"), unknown behavior\n",
438-
sb->s_id, SB_TYPE_ARGS(sb));
433+
printk(KERN_ERR "SELinux: initialized (dev %s, type %s), unknown behavior\n",
434+
sb->s_id, sb->s_type->name);
439435
else
440-
printk(KERN_DEBUG "SELinux: initialized (dev %s, type "SB_TYPE_FMT"), %s\n",
441-
sb->s_id, SB_TYPE_ARGS(sb),
436+
printk(KERN_DEBUG "SELinux: initialized (dev %s, type %s), %s\n",
437+
sb->s_id, sb->s_type->name,
442438
labeling_behaviors[sbsec->behavior-1]);
443439

444440
sbsec->flags |= SE_SBINITIALIZED;
@@ -601,6 +597,7 @@ static int selinux_set_mnt_opts(struct super_block *sb,
601597
const struct cred *cred = current_cred();
602598
int rc = 0, i;
603599
struct superblock_security_struct *sbsec = sb->s_security;
600+
const char *name = sb->s_type->name;
604601
struct inode *inode = sbsec->sb->s_root->d_inode;
605602
struct inode_security_struct *root_isec = inode->i_security;
606603
u32 fscontext_sid = 0, context_sid = 0, rootcontext_sid = 0;
@@ -659,8 +656,8 @@ static int selinux_set_mnt_opts(struct super_block *sb,
659656
strlen(mount_options[i]), &sid);
660657
if (rc) {
661658
printk(KERN_WARNING "SELinux: security_context_to_sid"
662-
"(%s) failed for (dev %s, type "SB_TYPE_FMT") errno=%d\n",
663-
mount_options[i], sb->s_id, SB_TYPE_ARGS(sb), rc);
659+
"(%s) failed for (dev %s, type %s) errno=%d\n",
660+
mount_options[i], sb->s_id, name, rc);
664661
goto out;
665662
}
666663
switch (flags[i]) {
@@ -807,8 +804,7 @@ static int selinux_set_mnt_opts(struct super_block *sb,
807804
out_double_mount:
808805
rc = -EINVAL;
809806
printk(KERN_WARNING "SELinux: mount invalid. Same superblock, different "
810-
"security settings for (dev %s, type "SB_TYPE_FMT")\n", sb->s_id,
811-
SB_TYPE_ARGS(sb));
807+
"security settings for (dev %s, type %s)\n", sb->s_id, name);
812808
goto out;
813809
}
814810

@@ -2481,8 +2477,8 @@ static int selinux_sb_remount(struct super_block *sb, void *data)
24812477
rc = security_context_to_sid(mount_options[i], len, &sid);
24822478
if (rc) {
24832479
printk(KERN_WARNING "SELinux: security_context_to_sid"
2484-
"(%s) failed for (dev %s, type "SB_TYPE_FMT") errno=%d\n",
2485-
mount_options[i], sb->s_id, SB_TYPE_ARGS(sb), rc);
2480+
"(%s) failed for (dev %s, type %s) errno=%d\n",
2481+
mount_options[i], sb->s_id, sb->s_type->name, rc);
24862482
goto out_free_opts;
24872483
}
24882484
rc = -EINVAL;
@@ -2520,8 +2516,8 @@ static int selinux_sb_remount(struct super_block *sb, void *data)
25202516
return rc;
25212517
out_bad_option:
25222518
printk(KERN_WARNING "SELinux: unable to change security options "
2523-
"during remount (dev %s, type "SB_TYPE_FMT")\n", sb->s_id,
2524-
SB_TYPE_ARGS(sb));
2519+
"during remount (dev %s, type=%s)\n", sb->s_id,
2520+
sb->s_type->name);
25252521
goto out_free_opts;
25262522
}
25272523

security/selinux/ss/services.c

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,50 +2344,16 @@ int security_fs_use(struct super_block *sb)
23442344
struct ocontext *c;
23452345
struct superblock_security_struct *sbsec = sb->s_security;
23462346
const char *fstype = sb->s_type->name;
2347-
const char *subtype = (sb->s_subtype && sb->s_subtype[0]) ? sb->s_subtype : NULL;
2348-
struct ocontext *base = NULL;
23492347

23502348
read_lock(&policy_rwlock);
23512349

2352-
for (c = policydb.ocontexts[OCON_FSUSE]; c; c = c->next) {
2353-
char *sub;
2354-
int baselen;
2355-
2356-
baselen = strlen(fstype);
2357-
2358-
/* if base does not match, this is not the one */
2359-
if (strncmp(fstype, c->u.name, baselen))
2360-
continue;
2361-
2362-
/* if there is no subtype, this is the one! */
2363-
if (!subtype)
2364-
break;
2365-
2366-
/* skip past the base in this entry */
2367-
sub = c->u.name + baselen;
2368-
2369-
/* entry is only a base. save it. keep looking for subtype */
2370-
if (sub[0] == '\0') {
2371-
base = c;
2372-
continue;
2373-
}
2374-
2375-
/* entry is not followed by a subtype, so it is not a match */
2376-
if (sub[0] != '.')
2377-
continue;
2378-
2379-
/* whew, we found a subtype of this fstype */
2380-
sub++; /* move past '.' */
2381-
2382-
/* exact match of fstype AND subtype */
2383-
if (!strcmp(subtype, sub))
2350+
c = policydb.ocontexts[OCON_FSUSE];
2351+
while (c) {
2352+
if (strcmp(fstype, c->u.name) == 0)
23842353
break;
2354+
c = c->next;
23852355
}
23862356

2387-
/* in case we had found an fstype match but no subtype match */
2388-
if (!c)
2389-
c = base;
2390-
23912357
if (c) {
23922358
sbsec->behavior = c->v.behavior;
23932359
if (!c->sid[0]) {

0 commit comments

Comments
 (0)