All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/secretmem: disable memfd_secret() if secretmem_init() fails
@ 2026-12-02 11:38 Mike Rapoport
  2026-12-02 12:44 ` David Hildenbrand (Arm)
  2026-12-02 19:24 ` + mm-secretmem-disable-memfd_secret-if-secretmem_init-fails.patch added to mm-new branch Andrew Morton
  0 siblings, 2 replies; 4+ messages in thread
From: Mike Rapoport @ 2026-12-02 11:38 UTC (permalink / raw)
  To: Andrew Morton
  Cc: David Hildenbrand, Mike Rapoport, linux-kernel, linux-mm, Sashiko

From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>

If kern_mount() fails in secretmem_init(), secretmem_mnt holds an error
pointer, but secretmem_enable remains set. A later memfd_secret() call
then dereferences secretmem_mnt in secretmem_file_create() and oopses.

At fs_initcall time kern_mount() of a pseudo filesystem realistically
fails only when a memory allocation fails, so this is unlikely to happen
in practice.

Clear secretmem_enable when kern_mount() fails, so that memfd_secret()
returns -ENOSYS as if secretmem was disabled.

Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/bug/linux-ad411cd2-f343-445a-b61d-9fb3eb712762
Fixes: 4eb5bbde3ccb ("mm: fix dereferencing possible ERR_PTR")
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
 mm/secretmem.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/mm/secretmem.c b/mm/secretmem.c
index b3f79ad56790a..2eef8415d70f5 100644
--- a/mm/secretmem.c
+++ b/mm/secretmem.c
@@ -358,8 +358,10 @@ static int __init secretmem_init(void)
 		return 0;
 
 	secretmem_mnt = kern_mount(&secretmem_fs);
-	if (IS_ERR(secretmem_mnt))
+	if (IS_ERR(secretmem_mnt)) {
+		secretmem_enable = false;
 		return PTR_ERR(secretmem_mnt);
+	}
 
 	return 0;
 }

base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
-- 
2.53.0



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

end of thread, other threads:[~2026-12-02 19:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 11:38 [PATCH] mm/secretmem: disable memfd_secret() if secretmem_init() fails Mike Rapoport
2026-12-02 12:44 ` David Hildenbrand (Arm)
2026-12-02 16:00   ` Mike Rapoport
2026-12-02 19:24 ` + mm-secretmem-disable-memfd_secret-if-secretmem_init-fails.patch added to mm-new branch Andrew Morton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.