Commit d66d2078 authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Greg Kroah-Hartman

wait: fix reparent_leader() vs EXIT_DEAD->EXIT_ZOMBIE race

commit dfccbb5e 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 50b8d257
"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: default avatarOleg Nesterov <oleg@redhat.com>
Reported-by: default avatarJan Kratochvil <jan.kratochvil@redhat.com>
Reported-by: default avatarMichal Schmidt <mschmidt@redhat.com>
Tested-by: default avatarMichal 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: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 371d9bb7
...@@ -761,9 +761,6 @@ static void reparent_leader(struct task_struct *father, struct task_struct *p, ...@@ -761,9 +761,6 @@ static void reparent_leader(struct task_struct *father, struct task_struct *p,
struct list_head *dead) struct list_head *dead)
{ {
list_move_tail(&p->sibling, &p->real_parent->children); list_move_tail(&p->sibling, &p->real_parent->children);
if (p->exit_state == EXIT_DEAD)
return;
/* /*
* If this is a threaded reparent there is no need to * If this is a threaded reparent there is no need to
* notify anyone anything has happened. * notify anyone anything has happened.
...@@ -771,9 +768,19 @@ static void reparent_leader(struct task_struct *father, struct task_struct *p, ...@@ -771,9 +768,19 @@ static void reparent_leader(struct task_struct *father, struct task_struct *p,
if (same_thread_group(p->real_parent, father)) if (same_thread_group(p->real_parent, father))
return; return;
/* We don't want people slaying init. */ /*
* We don't want people slaying init.
*
* Note: we do this even if it is EXIT_DEAD, wait_task_zombie()
* can change ->exit_state to EXIT_ZOMBIE. If this is the final
* state, do_notify_parent() was already called and ->exit_signal
* doesn't matter.
*/
p->exit_signal = SIGCHLD; p->exit_signal = SIGCHLD;
if (p->exit_state == EXIT_DEAD)
return;
/* If it has exited notify the new parent about this child's death. */ /* If it has exited notify the new parent about this child's death. */
if (!p->ptrace && if (!p->ptrace &&
p->exit_state == EXIT_ZOMBIE && thread_group_empty(p)) { p->exit_state == EXIT_ZOMBIE && thread_group_empty(p)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment