Linux cgroups development
 help / color / mirror / Atom feed
* [PATCH] cgroup: namespace: replace BUG_ON() in copy_cgroup_ns() with WARN_ON_ONCE()
@ 2026-09-02 10:18 Shaojie Sun
  2026-09-02 18:56 ` Michal Koutný
  0 siblings, 1 reply; 13+ messages in thread
From: Shaojie Sun @ 2026-09-02 10:18 UTC (permalink / raw)
  To: Tejun Heo, Johannes Weiner, mkoutny; +Cc: cgroups, linux-kernel, Shaojie Sun

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@kylinos.cn>
---
 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


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

end of thread, other threads:[~2026-09-04 10:49 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-02 10:18 [PATCH] cgroup: namespace: replace BUG_ON() in copy_cgroup_ns() with WARN_ON_ONCE() Shaojie Sun
2026-09-02 18:56 ` Michal Koutný
2026-09-03  6:48   ` [PATCH v2 0/3] drop BUG_ON() NULL checks in namespace copy helpers Shaojie Sun
2026-09-03  6:48     ` [PATCH v2 1/3] cgroup: namespace: drop BUG_ON() in copy_cgroup_ns() Shaojie Sun
2026-09-03  9:28       ` Tao Cui
2026-09-03 16:47       ` Tejun Heo
2026-09-03  6:48     ` [PATCH v2 2/3] uts: drop BUG_ON() in copy_utsname() Shaojie Sun
2026-09-03  8:40       ` Bradley Morgan
2026-09-03  6:48     ` [PATCH v2 3/3] fs: namespace: drop BUG_ON() in copy_mnt_ns() Shaojie Sun
2026-09-03  9:29       ` Tao Cui
2026-09-03 10:43       ` Jan Kara
2026-09-03  8:02     ` [PATCH v2 0/3] drop BUG_ON() NULL checks in namespace copy helpers Shaojie Sun
2026-09-04 10:48     ` (subset) " Christian Brauner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox