mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/1] nsproxy: fix credential leak in prepare_nsset() on copy_fs_struct() failure
@ 2026-03-01 10:45 Michal Grzedzicki
  0 siblings, 0 replies; only message in thread
From: Michal Grzedzicki @ 2026-03-01 10:45 UTC (permalink / raw)
  To: linux-kernel
  Cc: mge, brauner, jsavitz, lorenzo.stoakes, jlayton, arnd, schuster.simon

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-03-01 10:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-01 10:45 [PATCH 1/1] nsproxy: fix credential leak in prepare_nsset() on copy_fs_struct() failure Michal Grzedzicki

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®