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

From: Michal Koutný

Date: Wed Sep 02 2026 - 15:00:00 EST


Hi Shaojie.


On Wed, Sep 02, 2026 at 06:18:56PM +0800, Shaojie Sun <sunshaojie@xxxxxxxxxx> wrote:
> 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.

Do you plan to tackle other namespaces too? (Adding their guys to Cc:)

It'd be good to have some consistency across them if this is going to be
touched. (I see that some simply don't care whereas others have the same
BUG_ON(). I might personally prefer the former)

Regards,
Michal


>
> 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
>

Attachment: signature.asc
Description: PGP signature