Skip to content

Commit 355b8ad

Browse files
cgzonesmehmetb0
authored andcommitted
selinux: avoid dereference of garbage after mount failure
commit 37801a3 upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> CVE-2024-35904 (cherry picked from commit 477ed6789eb9f3f4d3568bb977f90c863c12724e linux-6.6.y) Signed-off-by: Massimiliano Pellizzer <massimiliano.pellizzer@canonical.com> Acked-by: Manuel Diewald <manuel.diewald@canonical.com> Acked-by: Guoqing Jiang <guoqing.jiang@canonical.com> Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
1 parent 803f6c4 commit 355b8ad

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
@@ -2208,7 +2208,6 @@ static struct file_system_type sel_fs_type = {
22082208
.kill_sb = sel_kill_sb,
22092209
};
22102210

2211-
static struct vfsmount *selinuxfs_mount __ro_after_init;
22122211
struct path selinux_null __ro_after_init;
22132212

22142213
static int __init init_sel_fs(void)
@@ -2230,18 +2229,21 @@ static int __init init_sel_fs(void)
22302229
return err;
22312230
}
22322231

2233-
selinux_null.mnt = selinuxfs_mount = kern_mount(&sel_fs_type);
2234-
if (IS_ERR(selinuxfs_mount)) {
2232+
selinux_null.mnt = kern_mount(&sel_fs_type);
2233+
if (IS_ERR(selinux_null.mnt)) {
22352234
pr_err("selinuxfs: could not mount!\n");
2236-
err = PTR_ERR(selinuxfs_mount);
2237-
selinuxfs_mount = NULL;
2235+
err = PTR_ERR(selinux_null.mnt);
2236+
selinux_null.mnt = NULL;
2237+
return err;
22382238
}
2239+
22392240
selinux_null.dentry = d_hash_and_lookup(selinux_null.mnt->mnt_root,
22402241
&null_name);
22412242
if (IS_ERR(selinux_null.dentry)) {
22422243
pr_err("selinuxfs: could not lookup null!\n");
22432244
err = PTR_ERR(selinux_null.dentry);
22442245
selinux_null.dentry = NULL;
2246+
return err;
22452247
}
22462248

22472249
return err;

0 commit comments

Comments
 (0)