Skip to contentSkip to conversation

cgroup: Don't expose dead tasks in cgroup

PATCH Applied Sebastian Andrzej Siewior 2 participants 2 messages Mar 6

Subsystems (2)
lore
Share & tools
lore

Sebastian Andrzej Siewior

author maintainer
#0 lore raw

PATCH v2 1/1 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 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 constrains.

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

Fixes 9311e6c29b348 ("cgroup: Fix sleeping from invalid context warning on PREEMPT_RT")

---
v1…v2: https://lore.kernel.org/all/[email protected]/
- Close the race window filtering out PF_EXITING tasks instead.
- Document the possible race window after it has been verified.

 kernel/cgroup/cgroup.c | 6 ++++++
 1 file changed, 6 insertions(+)
kernel/cgroup/cgroup.c +6 -0
index c22cda7766d84..eef01b80ec933 100644
@@ -5108,6 +5108,12 @@ static void css_task_iter_advance(struct css_task_iter *it)
 		return;
 
 	task = list_entry(it->task_pos, struct task_struct, cg_list);
+	/*
+	 * Hide task which are exitting 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 */
Signature · 1 line
2.53.0
maintainer Applied
#1 lore raw

Applied to cgroup/for-7.0-fixes with the following fixes.

- s/removed the cgroup/removed from the cgroup/
- s/constrains/constraints/
- Fixes tag SHA trimmed to 12 chars
- s/exitting/exiting/ and s/task which are/tasks that are/ in comment
- Added Cc: stable

Thanks.

--
tejun