[PATCH] cgroup: namespace: replace BUG_ON() in copy_cgroup_ns() with WARN_ON_ONCE()

From: Shaojie Sun

Date: Wed Sep 02 2026 - 06:29:32 EST


copy_cgroup_ns() uses BUG_ON() to guard against a NULL old_ns. The
condition cannot currently be triggered by any caller, and the sole
caller, create_new_namespaces(), already checks the return value with
IS_ERR() and unwinds correctly.

Replace the BUG_ON() with WARN_ON_ONCE() and return -EINVAL instead,
consistent with the policy of not killing the whole machine for a
recoverable programming error.

Signed-off-by: Shaojie Sun <sunshaojie@xxxxxxxxxx>
---
kernel/cgroup/namespace.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/cgroup/namespace.c b/kernel/cgroup/namespace.c
index ea4ee13936be..13930955c254 100644
--- a/kernel/cgroup/namespace.c
+++ b/kernel/cgroup/namespace.c
@@ -53,7 +53,8 @@ struct cgroup_namespace *copy_cgroup_ns(u64 flags,
struct ucounts *ucounts;
struct css_set *cset;

- BUG_ON(!old_ns);
+ if (WARN_ON_ONCE(!old_ns))
+ return ERR_PTR(-EINVAL);

if (!(flags & CLONE_NEWCGROUP)) {
get_cgroup_ns(old_ns);
--
2.50.1