Skip to content

Commit 37801a3

Browse files
cgzonespcmoore
authored andcommitted
selinux: avoid dereference of garbage after mount failure
In case kern_mount() fails and returns an error pointer return in the error branch instead of continuing and dereferencing the error pointer. While on it drop the never read static variable selinuxfs_mount. Cc: stable@vger.kernel.org Fixes: 0619f0f ("selinux: wrap selinuxfs state") Signed-off-by: Christian Göttsche <cgzones@googlemail.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 4cece76 commit 37801a3

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

security/selinux/selinuxfs.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,7 +2123,6 @@ static struct file_system_type sel_fs_type = {
21232123
.kill_sb = sel_kill_sb,
21242124
};
21252125

2126-
static struct vfsmount *selinuxfs_mount __ro_after_init;
21272126
struct path selinux_null __ro_after_init;
21282127

21292128
static int __init init_sel_fs(void)
@@ -2145,18 +2144,21 @@ static int __init init_sel_fs(void)
21452144
return err;
21462145
}
21472146

2148-
selinux_null.mnt = selinuxfs_mount = kern_mount(&sel_fs_type);
2149-
if (IS_ERR(selinuxfs_mount)) {
2147+
selinux_null.mnt = kern_mount(&sel_fs_type);
2148+
if (IS_ERR(selinux_null.mnt)) {
21502149
pr_err("selinuxfs: could not mount!\n");
2151-
err = PTR_ERR(selinuxfs_mount);
2152-
selinuxfs_mount = NULL;
2150+
err = PTR_ERR(selinux_null.mnt);
2151+
selinux_null.mnt = NULL;
2152+
return err;
21532153
}
2154+
21542155
selinux_null.dentry = d_hash_and_lookup(selinux_null.mnt->mnt_root,
21552156
&null_name);
21562157
if (IS_ERR(selinux_null.dentry)) {
21572158
pr_err("selinuxfs: could not lookup null!\n");
21582159
err = PTR_ERR(selinux_null.dentry);
21592160
selinux_null.dentry = NULL;
2161+
return err;
21602162
}
21612163

21622164
return err;

0 commit comments

Comments
 (0)