* [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
* Re: [PATCH] mm/secretmem: disable memfd_secret() if secretmem_init() fails
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
1 sibling, 1 reply; 4+ messages in thread
From: David Hildenbrand (Arm) @ 2026-12-02 12:44 UTC (permalink / raw)
To: Mike Rapoport, Andrew Morton; +Cc: linux-kernel, linux-mm, Sashiko
On 12/2/26 12:38, Mike Rapoport wrote:
> 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>
> ---
Unlikely to happen, so I guess no need for stable.
Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/secretmem: disable memfd_secret() if secretmem_init() fails
2026-12-02 12:44 ` David Hildenbrand (Arm)
@ 2026-12-02 16:00 ` Mike Rapoport
0 siblings, 0 replies; 4+ messages in thread
From: Mike Rapoport @ 2026-12-02 16:00 UTC (permalink / raw)
To: David Hildenbrand (Arm); +Cc: Andrew Morton, linux-kernel, linux-mm, Sashiko
On Wed, Dec 02, 2026 at 01:44:34PM +0100, David Hildenbrand (Arm) wrote:
> On 12/2/26 12:38, Mike Rapoport wrote:
> > 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>
> > ---
>
> Unlikely to happen, so I guess no need for stable.
Indeed
> Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>
>
> --
> Cheers,
>
> David
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 4+ messages in thread
* + mm-secretmem-disable-memfd_secret-if-secretmem_init-fails.patch added to mm-new branch
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 19:24 ` Andrew Morton
1 sibling, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2026-12-02 19:24 UTC (permalink / raw)
To: mm-commits, david, rppt, akpm
The patch titled
Subject: mm/secretmem: disable memfd_secret() if secretmem_init() fails
has been added to the -mm mm-new branch. Its filename is
mm-secretmem-disable-memfd_secret-if-secretmem_init-fails.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-secretmem-disable-memfd_secret-if-secretmem_init-fails.patch
This patch will later appear in the mm-new branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Note, mm-new is a provisional staging ground for work-in-progress
patches, and acceptance into mm-new is a notification for others take
notice and to finish up reviews. Please do not hesitate to respond to
review feedback and post updated versions to replace or incrementally
fixup patches in mm-new.
The mm-new branch of mm.git is not included in linux-next
If a few days of testing in mm-new is successful, the patch will me moved
into mm.git's mm-unstable branch, which is included in linux-next
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
Subject: mm/secretmem: disable memfd_secret() if secretmem_init() fails
Date: Wed, 02 Dec 2026 13:38:46 +0200
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.
Link: https://patch.msgid.link/20261202113847.1412019-1-rppt@kernel.org
Fixes: 4eb5bbde3ccb ("mm: fix dereferencing possible ERR_PTR")
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/bug/linux-ad411cd2-f343-445a-b61d-9fb3eb712762
Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>
mm/secretmem.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
--- a/mm/secretmem.c~mm-secretmem-disable-memfd_secret-if-secretmem_init-fails
+++ a/mm/secretmem.c
@@ -362,8 +362,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;
}
_
Patches currently in -mm which might be from rppt@kernel.org are
mm-cma-simplify-cma_declare_contiguous_multi.patch
mm-fake-numa-fix-leak-of-the-distance-table-copy-on-errors.patch
mm-secretmem-disable-memfd_secret-if-secretmem_init-fails.patch
hibernation-make-swsusp_page-helpers-static.patch
hibernation-ensure-secretmem-pages-dont-reach-a-snapshot.patch
hibernate-handle-potential-errors-in-hibernate_mapunmap_page.patch
hibernation-kfence-explicitly-map-unmap-kfence-pages.patch
hibernation-make-hibernation-unavailable-when-debug_pagealloc-is-on.patch
^ permalink raw reply [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.