Files
android_kernel_xiaomi_sm8450/include/linux
Oleg Nesterov abd50b39e7 wait: introduce EXIT_TRACE to avoid the racy EXIT_DEAD->EXIT_ZOMBIE transition
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 50b8d25748
"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.  This was fixed by
the previous commit, but it was the temporary hack.

1. Add the new exit_state, EXIT_TRACE. It means that the task is the
   traced zombie, debugger is going to detach and notify its natural
   parent.

   This new state is actually EXIT_ZOMBIE | EXIT_DEAD. This way we
   can avoid the changes in proc/kgdb code, get_task_state() still
   reports "X (dead)" in this case.

   Note: with or without this change userspace can see Z -> X -> Z
   transition. Not really bad, but probably makes sense to fix.

2. Change wait_task_zombie() to use EXIT_TRACE instead of EXIT_DEAD
   if we need to notify the ->real_parent.

3. Revert the previous hack in reparent_leader(), now that EXIT_DEAD
   is always the final state we can safely ignore such a task.

4. Change wait_consider_task() to check EXIT_TRACE separately and kill
   the racy and no longer needed ptrace_reparented() case.

   If ptrace == T an EXIT_TRACE thread should be simply ignored, the
   owner of this state is going to ptrace_unlink() this task. We can
   pretend that it was already removed from ->ptraced list.

   Otherwise we should skip this thread too but clear ->notask_error,
   we must be the natural parent and debugger is going to untrace and
   notify us. IOW, this doesn't differ from "EXIT_ZOMBIE && p->ptrace"
   even if the task was already untraced.

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>
2014-04-07 16:36:05 -07:00
..
2014-03-28 20:42:01 +01:00
2014-02-15 10:58:17 +00:00
2014-03-28 16:29:35 -04:00
2014-01-20 11:55:23 -08:00
2013-12-23 18:34:58 -08:00
2014-01-24 22:39:54 +01:00
2013-11-23 22:33:56 -08:00
2013-11-15 09:32:21 +09:00
2013-11-09 00:16:29 -05:00
2014-03-11 11:52:47 +01:00
2014-04-03 16:20:58 -07:00
2014-04-01 17:08:43 +02:00
2014-02-13 10:08:52 +05:30
2014-01-16 10:23:02 +10:30
2014-03-10 11:44:42 -04:00
2014-03-11 22:52:43 -04:00
2014-03-10 17:26:19 -07:00
2014-02-20 14:54:28 +01:00
2014-03-04 07:55:47 -08:00
2014-01-16 11:15:50 +01:00
2014-01-26 22:48:35 +01:00
2013-12-29 16:34:25 -05:00
2014-02-19 17:22:44 +01:00
2014-02-13 18:12:04 -08:00
2013-09-13 15:09:52 +02:00
2014-03-13 12:11:00 +10:30
2014-01-25 08:55:09 +01:00
2014-04-03 16:20:50 -07:00
2013-08-28 21:35:14 -07:00
2014-02-13 20:21:59 -08:00
2013-12-11 15:52:34 +01:00
2014-02-28 15:36:37 -08:00
2013-12-26 13:29:35 -05:00
2014-04-07 16:35:53 -07:00
2013-11-09 00:16:19 -05:00
2014-03-04 13:51:06 -05:00
2014-01-27 21:02:39 -08:00
2013-11-09 00:16:19 -05:00
2013-10-14 17:15:48 +02:00
2014-03-17 15:14:16 -04:00
2014-03-17 15:15:21 -04:00
2014-01-25 03:14:05 -05:00
2014-03-07 10:24:49 -05:00
2014-01-13 14:29:49 -08:00
2014-01-03 11:22:21 -08:00
2014-04-03 16:21:04 -07:00
2014-03-19 15:11:19 -06:00
2013-10-17 00:36:06 +02:00
2014-03-19 22:24:08 -04:00
2014-02-17 15:01:52 -08:00
2013-12-18 19:04:50 -08:00
2014-03-09 19:53:45 +01:00
2014-01-28 13:20:09 -08:00
2014-04-01 17:08:43 +02:00
2013-12-19 19:09:38 -05:00
2014-01-27 21:02:39 -08:00
2013-09-10 18:56:32 -04:00
2014-02-15 11:55:28 -08:00
2014-02-17 15:01:37 -08:00
2014-04-07 16:35:53 -07:00
2013-10-17 15:53:09 -04:00
2014-01-30 16:56:55 -08:00