Re: [PATCH v2 10/11] cgroup: don't hold cgroup_mutex for cgroup.kill
From: Andrew Morton
Date: Tue Dec 01 2026 - 12:56:08 EST
On Mon, 30 Nov 2026 09:34:24 -0800 Shakeel Butt <shakeel.butt@xxxxxxxxx> wrote:
> It is often used when the system is already in trouble, so it should not
> wait for other cgroup operations, and they should not wait for it.
>
> cgroup_mutex kept the cgroup and its subtree stable, and blocked
> migrations, CLONE_INTO_CGROUP forks and switches to threaded during the
> kill. Replace it:
From: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Subject: cgroup: refuse cgroup.kill below a threaded ancestor
Date: Tue, 01 Dec 2026 01:35:32 -0800
A non-threaded cgroup below a threaded ancestor has type "domain
invalid". Its threaded descendants can accept a thread from a process
in the ancestor's domain. cgroup.kill rejects a threaded target but
accepts the intermediate domain-invalid cgroup, then sends SIGKILL to
the entire process, including threads outside the target subtree.
This fixes Shakeel Butt's "cgroup: don't hold cgroup_mutex for cgroup.kill"
patch.
Check the ancestor CGRP_THREADED flags under css_set_lock before starting
the kill. A concurrent switch to threaded is excluded by the active
kill check in the preceding fix. Retain ENODEV precedence for a removed
cgroup and return EOPNOTSUPP for this unsupported kill.
In a KASAN/lockdep guest, one thread of a two-thread process entered a
threaded descendant. cgroup.kill on the intervening domain-invalid
cgroup returned success and killed the entire outside process.
Link: https://lore.kernel.org/r/20261130173425.4117363-11-shakeel.butt@xxxxxxxxx
Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Cc: Tejun Heo <tj@xxxxxxxxxx>
Cc: Johannes Weiner <hannes@xxxxxxxxxxx>
Cc: Michal Koutný <mkoutny@xxxxxxxx>
kernel/cgroup/cgroup.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
--- a/kernel/cgroup/cgroup.c~cgroup-dont-hold-cgroup_mutex-for-cgroupkill-fix-2
+++ a/kernel/cgroup/cgroup.c
@@ -4512,13 +4512,20 @@ static int cgroup_kill(struct cgroup *cg
{
struct cgroup_kill_ctx kill = { .cgrp = cgrp };
struct cgroup_subsys_state *css;
- int ret = 0;
+ int i, ret = 0;
spin_lock_irq(&css_set_lock);
if (cgroup_is_dead(cgrp))
ret = -ENODEV;
else if (test_bit(CGRP_THREADED, &cgrp->flags))
ret = -EOPNOTSUPP;
+ else
+ for (i = cgrp->level - 1; i > 0; i--)
+ if (test_bit(CGRP_THREADED,
+ &cgrp->ancestors[i]->flags)) {
+ ret = -EOPNOTSUPP;
+ break;
+ }
/* an empty subtree has nothing to kill, see above */
if (ret || !cgroup_is_populated(cgrp)) {
spin_unlock_irq(&css_set_lock);
_