public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 6.1.y] selinux: avoid dereference of garbage after mount failure
@ 2025-05-12  1:44 jianqi.ren.cn
  2025-05-12 21:52 ` Sasha Levin
  2025-05-20 11:18 ` Greg KH
  0 siblings, 2 replies; 3+ messages in thread
From: jianqi.ren.cn @ 2025-05-12  1:44 UTC (permalink / raw)
  To: gregkh, stable
  Cc: paul, stephen.smalley.work, eparis, selinux, cgzones, patches,
	linux-kernel, jianqi.ren.cn

From: Christian Göttsche <cgzones@googlemail.com>

commit 37801a36b4d68892ce807264f784d818f8d0d39b 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: 0619f0f5e36f ("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: Jianqi Ren <jianqi.ren.cn@windriver.com>
Signed-off-by: He Zhe <zhe.he@windriver.com>
---
Verified the build test
---
 security/selinux/selinuxfs.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c
index ab804d4ea911..c236f3cd2dd7 100644
--- a/security/selinux/selinuxfs.c
+++ b/security/selinux/selinuxfs.c
@@ -2210,7 +2210,6 @@ static struct file_system_type sel_fs_type = {
 	.kill_sb	= sel_kill_sb,
 };
 
-static struct vfsmount *selinuxfs_mount __ro_after_init;
 struct path selinux_null __ro_after_init;
 
 static int __init init_sel_fs(void)
@@ -2232,18 +2231,21 @@ static int __init init_sel_fs(void)
 		return err;
 	}
 
-	selinux_null.mnt = selinuxfs_mount = kern_mount(&sel_fs_type);
-	if (IS_ERR(selinuxfs_mount)) {
+	selinux_null.mnt = kern_mount(&sel_fs_type);
+	if (IS_ERR(selinux_null.mnt)) {
 		pr_err("selinuxfs:  could not mount!\n");
-		err = PTR_ERR(selinuxfs_mount);
-		selinuxfs_mount = NULL;
+		err = PTR_ERR(selinux_null.mnt);
+		selinux_null.mnt = NULL;
+		return err;
 	}
+
 	selinux_null.dentry = d_hash_and_lookup(selinux_null.mnt->mnt_root,
 						&null_name);
 	if (IS_ERR(selinux_null.dentry)) {
 		pr_err("selinuxfs:  could not lookup null!\n");
 		err = PTR_ERR(selinux_null.dentry);
 		selinux_null.dentry = NULL;
+		return err;
 	}
 
 	return err;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 6.1.y] selinux: avoid dereference of garbage after mount failure
  2025-05-12  1:44 [PATCH 6.1.y] selinux: avoid dereference of garbage after mount failure jianqi.ren.cn
@ 2025-05-12 21:52 ` Sasha Levin
  2025-05-20 11:18 ` Greg KH
  1 sibling, 0 replies; 3+ messages in thread
From: Sasha Levin @ 2025-05-12 21:52 UTC (permalink / raw)
  To: stable, jianqi.ren.cn; +Cc: Sasha Levin

[ Sasha's backport helper bot ]

Hi,

Summary of potential issues:
❌ Build failures detected

The upstream commit SHA1 provided is correct: 37801a36b4d68892ce807264f784d818f8d0d39b

WARNING: Author mismatch between patch and upstream commit:
Backport author: <jianqi.ren.cn@windriver.com>
Commit author: Christian Göttsche<cgzones@googlemail.com>

Status in newer kernel trees:
6.14.y | Present (exact SHA1)
6.12.y | Present (exact SHA1)
6.6.y | Present (different SHA1: 477ed6789eb9)

Note: The patch differs from the upstream commit:
---
1:  37801a36b4d68 ! 1:  31f99abbcce21 selinux: avoid dereference of garbage after mount failure
    @@ Metadata
      ## Commit message ##
         selinux: avoid dereference of garbage after mount failure
     
    +    commit 37801a36b4d68892ce807264f784d818f8d0d39b upstream.
    +
         In case kern_mount() fails and returns an error pointer return in the
         error branch instead of continuing and dereferencing the error pointer.
     
    @@ Commit message
         Fixes: 0619f0f5e36f ("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: Jianqi Ren <jianqi.ren.cn@windriver.com>
    +    Signed-off-by: He Zhe <zhe.he@windriver.com>
     
      ## security/selinux/selinuxfs.c ##
     @@ security/selinux/selinuxfs.c: static struct file_system_type sel_fs_type = {
---

Results of testing on various branches:

| Branch                    | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| stable/linux-6.1.y        |  Success    |  Failed    |

Build Errors:
Build error for stable/linux-6.1.y:
    security/selinux/selinuxfs.c: In function 'exit_sel_fs':
    security/selinux/selinuxfs.c:2261:22: error: 'selinuxfs_mount' undeclared (first use in this function)
     2261 |         kern_unmount(selinuxfs_mount);
          |                      ^~~~~~~~~~~~~~~
    security/selinux/selinuxfs.c:2261:22: note: each undeclared identifier is reported only once for each function it appears in
    make[3]: *** [scripts/Makefile.build:250: security/selinux/selinuxfs.o] Error 1
    make[3]: Target 'security/selinux/' not remade because of errors.
    make[2]: *** [scripts/Makefile.build:503: security/selinux] Error 2
    make[2]: Target 'security/' not remade because of errors.
    make[1]: *** [scripts/Makefile.build:503: security] Error 2
    make[1]: Target './' not remade because of errors.
    make: *** [Makefile:2013: .] Error 2
    make: Target '__all' not remade because of errors.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 6.1.y] selinux: avoid dereference of garbage after mount failure
  2025-05-12  1:44 [PATCH 6.1.y] selinux: avoid dereference of garbage after mount failure jianqi.ren.cn
  2025-05-12 21:52 ` Sasha Levin
@ 2025-05-20 11:18 ` Greg KH
  1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2025-05-20 11:18 UTC (permalink / raw)
  To: jianqi.ren.cn
  Cc: stable, paul, stephen.smalley.work, eparis, selinux, cgzones,
	patches, linux-kernel

On Mon, May 12, 2025 at 09:44:00AM +0800, jianqi.ren.cn@windriver.com wrote:
> From: Christian Göttsche <cgzones@googlemail.com>
> 
> commit 37801a36b4d68892ce807264f784d818f8d0d39b 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: 0619f0f5e36f ("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: Jianqi Ren <jianqi.ren.cn@windriver.com>
> Signed-off-by: He Zhe <zhe.he@windriver.com>
> ---
> Verified the build test

No you did not :(


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-05-20 11:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-12  1:44 [PATCH 6.1.y] selinux: avoid dereference of garbage after mount failure jianqi.ren.cn
2025-05-12 21:52 ` Sasha Levin
2025-05-20 11:18 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox