Skip to content

Commit a83d6dd

Browse files
WOnder93pcmoore
authored andcommitted
selinux: never allow relabeling on context mounts
In the SECURITY_FS_USE_MNTPOINT case we never want to allow relabeling files/directories, so we should never set the SBLABEL_MNT flag. The 'special handling' in selinux_is_sblabel_mnt() is only intended for when the behavior is set to SECURITY_FS_USE_GENFS. While there, make the logic in selinux_is_sblabel_mnt() more explicit and add a BUILD_BUG_ON() to make sure that introducing a new SECURITY_FS_USE_* forces a review of the logic. Fixes: d5f3a5f ("selinux: add security in-core xattr support for pstore and debugfs") Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com> Reviewed-by: Stephen Smalley <sds@tycho.nsa.gov> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent e46e01e commit a83d6dd

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

security/selinux/hooks.c

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -534,16 +534,10 @@ static int may_context_mount_inode_relabel(u32 sid,
534534
return rc;
535535
}
536536

537-
static int selinux_is_sblabel_mnt(struct super_block *sb)
537+
static int selinux_is_genfs_special_handling(struct super_block *sb)
538538
{
539-
struct superblock_security_struct *sbsec = sb->s_security;
540-
541-
return sbsec->behavior == SECURITY_FS_USE_XATTR ||
542-
sbsec->behavior == SECURITY_FS_USE_TRANS ||
543-
sbsec->behavior == SECURITY_FS_USE_TASK ||
544-
sbsec->behavior == SECURITY_FS_USE_NATIVE ||
545-
/* Special handling. Genfs but also in-core setxattr handler */
546-
!strcmp(sb->s_type->name, "sysfs") ||
539+
/* Special handling. Genfs but also in-core setxattr handler */
540+
return !strcmp(sb->s_type->name, "sysfs") ||
547541
!strcmp(sb->s_type->name, "pstore") ||
548542
!strcmp(sb->s_type->name, "debugfs") ||
549543
!strcmp(sb->s_type->name, "tracefs") ||
@@ -553,6 +547,34 @@ static int selinux_is_sblabel_mnt(struct super_block *sb)
553547
!strcmp(sb->s_type->name, "cgroup2")));
554548
}
555549

550+
static int selinux_is_sblabel_mnt(struct super_block *sb)
551+
{
552+
struct superblock_security_struct *sbsec = sb->s_security;
553+
554+
/*
555+
* IMPORTANT: Double-check logic in this function when adding a new
556+
* SECURITY_FS_USE_* definition!
557+
*/
558+
BUILD_BUG_ON(SECURITY_FS_USE_MAX != 7);
559+
560+
switch (sbsec->behavior) {
561+
case SECURITY_FS_USE_XATTR:
562+
case SECURITY_FS_USE_TRANS:
563+
case SECURITY_FS_USE_TASK:
564+
case SECURITY_FS_USE_NATIVE:
565+
return 1;
566+
567+
case SECURITY_FS_USE_GENFS:
568+
return selinux_is_genfs_special_handling(sb);
569+
570+
/* Never allow relabeling on context mounts */
571+
case SECURITY_FS_USE_MNTPOINT:
572+
case SECURITY_FS_USE_NONE:
573+
default:
574+
return 0;
575+
}
576+
}
577+
556578
static int sb_finish_set_opts(struct super_block *sb)
557579
{
558580
struct superblock_security_struct *sbsec = sb->s_security;

0 commit comments

Comments
 (0)