]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
cgroup: Don't expose dead tasks in cgroup
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>
Fri, 6 Mar 2026 19:22:35 +0000 (20:22 +0100)
committerTejun Heo <tj@kernel.org>
Fri, 6 Mar 2026 22:43:25 +0000 (12:43 -1000)
Once a task exits it has its state set to TASK_DEAD and then it is
removed from the cgroup it belonged to. The last step happens on the task
gets out of its last schedule() invocation and is delayed on PREEMPT_RT
due to locking constraints.

As a result it is possible to receive a pid via waitpid() of a task
which is still listed in cgroup.procs for the cgroup it belonged
to. This is something that systemd does not expect and as a result it
waits for its exit until a time out occurs.
This can also be reproduced on !PREEMPT_RT kernel with a significant
delay in do_exit() after exit_notify().

Hide the task from the output which have PF_EXITING set which is done
before the parent is notified. Keeping zombies with live threads
shouldn't break anything (suggested by Tejun).

Reported-by: Bert Karwatzki <spasswolf@web.de>
Closes: https://lore.kernel.org/all/20260219164648.3014-1-spasswolf@web.de/
Tested-by: Bert Karwatzki <spasswolf@web.de>
Fixes: 9311e6c29b34 ("cgroup: Fix sleeping from invalid context warning on PREEMPT_RT")
Cc: stable@vger.kernel.org # v6.19+
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Tejun Heo <tj@kernel.org>
kernel/cgroup/cgroup.c

index be1d71dda31790d7b97503ce043601e12706029e..01fc2a93f3ef229cfb4d5038df9cd2b42ce57439 100644 (file)
@@ -5109,6 +5109,12 @@ repeat:
                return;
 
        task = list_entry(it->task_pos, struct task_struct, cg_list);
+       /*
+        * Hide tasks that are exiting but not yet removed. Keep zombie
+        * leaders with live threads visible.
+        */
+       if ((task->flags & PF_EXITING) && !atomic_read(&task->signal->live))
+               goto repeat;
 
        if (it->flags & CSS_TASK_ITER_PROCS) {
                /* if PROCS, skip over tasks which aren't group leaders */