mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] fs/namespace: fix reference leak in grab_requested_mnt_ns
@ 2025-11-22  7:19 Andrei Vagin
  2025-11-25  8:35 ` Christian Brauner
  0 siblings, 1 reply; 2+ messages in thread
From: Andrei Vagin @ 2025-11-22  7:19 UTC (permalink / raw)
  To: Christian Brauner; +Cc: linux-kernel, linux-fsdevel, Andrei Vagin

lookup_mnt_ns() already takes a reference on mnt_ns.
grab_requested_mnt_ns() doesn't need to take an extra reference.

Fixes: 78f0e33cd6c93 ("fs/namespace: correctly handle errors returned by grab_requested_mnt_ns")
Signed-off-by: Andrei Vagin <avagin@google.com>
---
 fs/namespace.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/fs/namespace.c b/fs/namespace.c
index 2bad25709b2c..4272349650b1 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -5746,6 +5746,8 @@ static struct mnt_namespace *grab_requested_mnt_ns(const struct mnt_id_req *kreq
 
 	if (kreq->mnt_ns_id) {
 		mnt_ns = lookup_mnt_ns(kreq->mnt_ns_id);
+		if (!mnt_ns)
+			return ERR_PTR(-ENOENT);
 	} else if (kreq->mnt_ns_fd) {
 		struct ns_common *ns;
 
@@ -5761,13 +5763,12 @@ static struct mnt_namespace *grab_requested_mnt_ns(const struct mnt_id_req *kreq
 			return ERR_PTR(-EINVAL);
 
 		mnt_ns = to_mnt_ns(ns);
+		refcount_inc(&mnt_ns->passive);
 	} else {
 		mnt_ns = current->nsproxy->mnt_ns;
+		refcount_inc(&mnt_ns->passive);
 	}
-	if (!mnt_ns)
-		return ERR_PTR(-ENOENT);
 
-	refcount_inc(&mnt_ns->passive);
 	return mnt_ns;
 }
 
-- 
2.52.0.487.g5c8c507ade-goog


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

* Re: [PATCH] fs/namespace: fix reference leak in grab_requested_mnt_ns
  2025-11-22  7:19 [PATCH] fs/namespace: fix reference leak in grab_requested_mnt_ns Andrei Vagin
@ 2025-11-25  8:35 ` Christian Brauner
  0 siblings, 0 replies; 2+ messages in thread
From: Christian Brauner @ 2025-11-25  8:35 UTC (permalink / raw)
  To: Andrei Vagin; +Cc: Christian Brauner, linux-kernel, linux-fsdevel

On Sat, 22 Nov 2025 07:19:53 +0000, Andrei Vagin wrote:
> lookup_mnt_ns() already takes a reference on mnt_ns.
> grab_requested_mnt_ns() doesn't need to take an extra reference.
> 
> 

Applied to the vfs.fixes branch of the vfs/vfs.git tree.
Patches in the vfs.fixes branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.fixes

[1/1] fs/namespace: fix reference leak in grab_requested_mnt_ns
      https://git.kernel.org/vfs/vfs/c/7b6dcd9bfd86

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

end of thread, other threads:[~2025-11-25  8:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-22  7:19 [PATCH] fs/namespace: fix reference leak in grab_requested_mnt_ns Andrei Vagin
2025-11-25  8:35 ` Christian Brauner

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®