Skip to content

Commit ccf1dab

Browse files
WOnder93pcmoore
authored andcommitted
selinux: fix handling of empty opts in selinux_fs_context_submount()
selinux_set_mnt_opts() relies on the fact that the mount options pointer is always NULL when all options are unset (specifically in its !selinux_initialized() branch. However, the new selinux_fs_context_submount() hook breaks this rule by allocating a new structure even if no options are set. That causes any submount created before a SELinux policy is loaded to be rejected in selinux_set_mnt_opts(). Fix this by making selinux_fs_context_submount() leave fc->security set to NULL when there are no options to be copied from the reference superblock. Cc: <[email protected]> Reported-by: Adam Williamson <[email protected]> Link: https://bugzilla.redhat.com/show_bug.cgi?id=2236345 Fixes: d80a8f1 ("vfs, security: Fix automount superblock LSM init problem, preventing NFS sb sharing") Signed-off-by: Ondrej Mosnacek <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 0bb80ec commit ccf1dab

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

security/selinux/hooks.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2775,14 +2775,20 @@ static int selinux_umount(struct vfsmount *mnt, int flags)
27752775
static int selinux_fs_context_submount(struct fs_context *fc,
27762776
struct super_block *reference)
27772777
{
2778-
const struct superblock_security_struct *sbsec;
2778+
const struct superblock_security_struct *sbsec = selinux_superblock(reference);
27792779
struct selinux_mnt_opts *opts;
27802780

2781+
/*
2782+
* Ensure that fc->security remains NULL when no options are set
2783+
* as expected by selinux_set_mnt_opts().
2784+
*/
2785+
if (!(sbsec->flags & (FSCONTEXT_MNT|CONTEXT_MNT|DEFCONTEXT_MNT)))
2786+
return 0;
2787+
27812788
opts = kzalloc(sizeof(*opts), GFP_KERNEL);
27822789
if (!opts)
27832790
return -ENOMEM;
27842791

2785-
sbsec = selinux_superblock(reference);
27862792
if (sbsec->flags & FSCONTEXT_MNT)
27872793
opts->fscontext_sid = sbsec->sid;
27882794
if (sbsec->flags & CONTEXT_MNT)

0 commit comments

Comments
 (0)