Skip to content

Commit 7b6dcd9

Browse files
avaginbrauner
authored andcommitted
fs/namespace: fix reference leak in grab_requested_mnt_ns
lookup_mnt_ns() already takes a reference on mnt_ns. grab_requested_mnt_ns() doesn't need to take an extra reference. Fixes: 78f0e33 ("fs/namespace: correctly handle errors returned by grab_requested_mnt_ns") Signed-off-by: Andrei Vagin <avagin@google.com> Link: https://patch.msgid.link/20251122071953.3053755-1-avagin@google.com Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent ac3fd01 commit 7b6dcd9

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

fs/namespace.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5746,6 +5746,8 @@ static struct mnt_namespace *grab_requested_mnt_ns(const struct mnt_id_req *kreq
57465746

57475747
if (kreq->mnt_ns_id) {
57485748
mnt_ns = lookup_mnt_ns(kreq->mnt_ns_id);
5749+
if (!mnt_ns)
5750+
return ERR_PTR(-ENOENT);
57495751
} else if (kreq->mnt_ns_fd) {
57505752
struct ns_common *ns;
57515753

@@ -5761,13 +5763,12 @@ static struct mnt_namespace *grab_requested_mnt_ns(const struct mnt_id_req *kreq
57615763
return ERR_PTR(-EINVAL);
57625764

57635765
mnt_ns = to_mnt_ns(ns);
5766+
refcount_inc(&mnt_ns->passive);
57645767
} else {
57655768
mnt_ns = current->nsproxy->mnt_ns;
5769+
refcount_inc(&mnt_ns->passive);
57665770
}
5767-
if (!mnt_ns)
5768-
return ERR_PTR(-ENOENT);
57695771

5770-
refcount_inc(&mnt_ns->passive);
57715772
return mnt_ns;
57725773
}
57735774

0 commit comments

Comments
 (0)