From: Michal Grzedzicki <mge@meta.com>
To: <linux-kernel@vger.kernel.org>
Cc: <mge@meta.com>, <brauner@kernel.org>, <jsavitz@redhat.com>,
<lorenzo.stoakes@oracle.com>, <jlayton@kernel.org>,
<arnd@arndb.de>, <schuster.simon@siemens-energy.com>
Subject: [PATCH 1/1] nsproxy: fix credential leak in prepare_nsset() on copy_fs_struct() failure
Date: Sun, 1 Mar 2026 02:45:46 -0800 [thread overview]
Message-ID: <20260301104546.618068-1-mge@meta.com> (raw)
nsset->flags is only set on the success path, so when copy_fs_struct()
fails put_nsset() sees flags == 0 and skips put_cred() for the
credential allocated by prepare_creds().
Set nsset->flags before copy_fs_struct() so put_nsset() performs
correct cleanup. This is safe because put_nsset() already checks
nsset->fs and nsset->nsproxy for NULL independently.
Fixes: f2a8d52e0a4d ("nsproxy: add struct nsset")
Signed-off-by: Michal Grzedzicki <mge@meta.com>
---
kernel/nsproxy.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c
index 259c4b4f1eeb..39ec77a2acc2 100644
--- a/kernel/nsproxy.c
+++ b/kernel/nsproxy.c
@@ -353,6 +353,9 @@ static int prepare_nsset(unsigned flags, struct nsset *nsset)
if (IS_ERR(nsset->nsproxy))
return PTR_ERR(nsset->nsproxy);
+ /* Set flags early so put_nsset() can clean up properly on failure. */
+ nsset->flags = flags;
+
if (flags & CLONE_NEWUSER)
nsset->cred = prepare_creds();
else
@@ -368,8 +371,6 @@ static int prepare_nsset(unsigned flags, struct nsset *nsset)
if (!nsset->fs)
goto out;
}
-
- nsset->flags = flags;
return 0;
out:
--
2.47.3
reply other threads:[~2026-03-01 10:46 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260301104546.618068-1-mge@meta.com \
--to=mge@meta.com \
--cc=arnd@arndb.de \
--cc=brauner@kernel.org \
--cc=jlayton@kernel.org \
--cc=jsavitz@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=schuster.simon@siemens-energy.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®