[PATCH 15/26] wait: Don't delay !ptrace_reparented leaders

From: Eric W. Biederman
Date: Tue Jun 06 2017 - 15:14:58 EST


When ptracing waitpid(pid) has two possible meanings.
- Wait for the task with tid == pid to exit
- Wait for the thread group with tgid == pid to exit

Linux resolves this ambiguity by prefering the thread group
interpretation if it is possible. As the exit of a thread group
containing a task is the superset of the exit of a task.

Delaying reaping of thread group leaders for ptraced children
is how the code implements this resolution.

For ptraced tasks that are not also children this ambiguity does
not exit. The only possible valid meaning of waitpid(pid) is
to wait for the task with tid == pid to exit. As such there is
no need to delay reaping ptraced tasks when the tasks are
not also children of the tracer.

Change this carefully as the real parent does need to delay reaping
of these tasks.

Signed-off-by: "Eric W. Biederman" <ebiederm@xxxxxxxxxxxx>
---
kernel/exit.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/exit.c b/kernel/exit.c
index dbf3fce00a1f..85b34eff8807 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -1144,7 +1144,8 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p)

/* If parent wants a zombie, don't release it now */
state = EXIT_ZOMBIE;
- if (do_notify_parent(p, p->exit_signal))
+ if (thread_group_empty(p) &&
+ do_notify_parent(p, p->exit_signal))
state = EXIT_DEAD;
p->exit_state = state;
write_unlock_irq(&tasklist_lock);
@@ -1366,8 +1367,7 @@ static int wait_consider_task(struct wait_opts *wo, int ptrace,
* ptracer detaches.
*/
if ((exit_state == EXIT_ZOMBIE) && ptrace &&
- (!thread_group_leader(p) ||
- (ptrace_reparented(p) && thread_group_empty(p))))
+ (!thread_group_leader(p) || ptrace_reparented(p)))
return wait_task_zombie(wo, p);

if (unlikely(exit_state == EXIT_TRACE)) {
--
2.10.1