Skip to content

Commit bab2898

Browse files
oleg-nesterovgregkh
authored andcommitted
wait: fix reparent_leader() vs EXIT_DEAD->EXIT_ZOMBIE race
commit dfccbb5 upstream. wait_task_zombie() first does EXIT_ZOMBIE->EXIT_DEAD transition and drops tasklist_lock. If this task is not the natural child and it is traced, we change its state back to EXIT_ZOMBIE for ->real_parent. The last transition is racy, this is even documented in 50b8d25 "ptrace: partially fix the do_wait(WEXITED) vs EXIT_DEAD->EXIT_ZOMBIE race". wait_consider_task() tries to detect this transition and clear ->notask_error but we can't rely on ptrace_reparented(), debugger can exit and do ptrace_unlink() before its sub-thread sets EXIT_ZOMBIE. And there is another problem which were missed before: this transition can also race with reparent_leader() which doesn't reset >exit_signal if EXIT_DEAD, assuming that this task must be reaped by someone else. So the tracee can be re-parented with ->exit_signal != SIGCHLD, and if /sbin/init doesn't use __WALL it becomes unreapable. Change reparent_leader() to update ->exit_signal even if EXIT_DEAD. Note: this is the simple temporary hack for -stable, it doesn't try to solve all problems, it will be reverted by the next changes. Signed-off-by: Oleg Nesterov <oleg@redhat.com> Reported-by: Jan Kratochvil <jan.kratochvil@redhat.com> Reported-by: Michal Schmidt <mschmidt@redhat.com> Tested-by: Michal Schmidt <mschmidt@redhat.com> Cc: Al Viro <viro@ZenIV.linux.org.uk> Cc: Lennart Poettering <lpoetter@redhat.com> Cc: Roland McGrath <roland@hack.frob.com> Cc: Tejun Heo <tj@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0829491 commit bab2898

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

‎kernel/exit.c‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -559,19 +559,26 @@ static void reparent_leader(struct task_struct *father, struct task_struct *p,
559559
struct list_head *dead)
560560
{
561561
list_move_tail(&p->sibling, &p->real_parent->children);
562-
563-
if (p->exit_state == EXIT_DEAD)
564-
return;
565562
/*
566563
* If this is a threaded reparent there is no need to
567564
* notify anyone anything has happened.
568565
*/
569566
if (same_thread_group(p->real_parent, father))
570567
return;
571568

572-
/* We don't want people slaying init. */
569+
/*
570+
* We don't want people slaying init.
571+
*
572+
* Note: we do this even if it is EXIT_DEAD, wait_task_zombie()
573+
* can change ->exit_state to EXIT_ZOMBIE. If this is the final
574+
* state, do_notify_parent() was already called and ->exit_signal
575+
* doesn't matter.
576+
*/
573577
p->exit_signal = SIGCHLD;
574578

579+
if (p->exit_state == EXIT_DEAD)
580+
return;
581+
575582
/* If it has exited notify the new parent about this child's death. */
576583
if (!p->ptrace &&
577584
p->exit_state == EXIT_ZOMBIE && thread_group_empty(p)) {

0 commit comments

Comments
 (0)