From: Joel Savitz <jsavitz@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Joel Savitz <jsavitz@redhat.com>,
Christian Brauner <brauner@kernel.org>,
Al Viro <viro@zeniv.linux.org.uk>
Subject: [PATCH] kernel/nsproxy: guard all put_*_ns() calls
Date: Wed, 7 May 2025 12:13:28 -0400 [thread overview]
Message-ID: <20250507161328.156909-1-jsavitz@redhat.com> (raw)
In free_nsproxy() and the error path of create_new_namespaces() all
calls to put_*_ns() are guarded by a null pointer check except for
put_cgroup_ns() and put_net(). When CONFIG_NET_NS or CONFIG_GROUP is
unset, either of these functions may be called with a NULL argument.
This may or may not be handled correctly, but at the very least it is
certainly quicker to just perform the null check in all cases.
Signed-off-by: Joel Savitz <jsavitz@redhat.com>
---
kernel/nsproxy.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c
index c9d97ed20122..2b12d2c5d2e0 100644
--- a/kernel/nsproxy.c
+++ b/kernel/nsproxy.c
@@ -124,9 +124,11 @@ static struct nsproxy *create_new_namespaces(unsigned long flags,
return new_nsp;
out_time:
- put_net(new_nsp->net_ns);
+ if (new_nsp->net_ns)
+ put_net(new_nsp->net_ns);
out_net:
- put_cgroup_ns(new_nsp->cgroup_ns);
+ if (new_nsp->cgroup_ns)
+ put_cgroup_ns(new_nsp->cgroup_ns);
out_cgroup:
if (new_nsp->pid_ns_for_children)
put_pid_ns(new_nsp->pid_ns_for_children);
@@ -201,8 +203,10 @@ void free_nsproxy(struct nsproxy *ns)
put_time_ns(ns->time_ns);
if (ns->time_ns_for_children)
put_time_ns(ns->time_ns_for_children);
- put_cgroup_ns(ns->cgroup_ns);
- put_net(ns->net_ns);
+ if (ns->cgroup_ns)
+ put_cgroup_ns(ns->cgroup_ns);
+ if (ns->net_ns)
+ put_net(ns->net_ns);
kmem_cache_free(nsproxy_cachep, ns);
}
--
2.45.2
next reply other threads:[~2025-05-07 16:13 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-07 16:13 Joel Savitz [this message]
2025-05-07 21:26 ` [PATCH] kernel/nsproxy: guard all put_*_ns() calls Al Viro
2025-05-08 18:55 ` Joel Savitz
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=20250507161328.156909-1-jsavitz@redhat.com \
--to=jsavitz@redhat.com \
--cc=brauner@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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