Skip to content

Commit a72f73c

Browse files
Sebastian Andrzej Siewiorhtejun
authored andcommitted
cgroup: Don't expose dead tasks in cgroup
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 <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Tested-by: Bert Karwatzki <[email protected]> Fixes: 9311e6c ("cgroup: Fix sleeping from invalid context warning on PREEMPT_RT") Cc: [email protected] # v6.19+ Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent ca174c7 commit a72f73c

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

kernel/cgroup/cgroup.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5109,6 +5109,12 @@ static void css_task_iter_advance(struct css_task_iter *it)
51095109
return;
51105110

51115111
task = list_entry(it->task_pos, struct task_struct, cg_list);
5112+
/*
5113+
* Hide tasks that are exiting but not yet removed. Keep zombie
5114+
* leaders with live threads visible.
5115+
*/
5116+
if ((task->flags & PF_EXITING) && !atomic_read(&task->signal->live))
5117+
goto repeat;
51125118

51135119
if (it->flags & CSS_TASK_ITER_PROCS) {
51145120
/* if PROCS, skip over tasks which aren't group leaders */

0 commit comments

Comments
 (0)