Commit 4576145c authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Linus Torvalds

ptrace: fix possible zombie leak on PTRACE_DETACH

When ptrace_detach() takes tasklist, the tracee can be SIGKILL'ed.  If it
has already passed exit_notify() we can leak a zombie, because a) ptracing
disables the auto-reaping logic, and b) ->real_parent was not notified
about the child's death.

ptrace_detach() should follow the ptrace_exit's logic, change the code
accordingly.
Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
Cc: Jerome Marchand <jmarchan@redhat.com>
Cc: Roland McGrath <roland@redhat.com>
Tested-by: default avatarDenys Vlasenko <dvlasenk@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent b1b4c679
...@@ -94,6 +94,7 @@ extern void ptrace_notify(int exit_code); ...@@ -94,6 +94,7 @@ extern void ptrace_notify(int exit_code);
extern void __ptrace_link(struct task_struct *child, extern void __ptrace_link(struct task_struct *child,
struct task_struct *new_parent); struct task_struct *new_parent);
extern void __ptrace_unlink(struct task_struct *child); extern void __ptrace_unlink(struct task_struct *child);
extern int __ptrace_detach(struct task_struct *tracer, struct task_struct *p);
extern void ptrace_fork(struct task_struct *task, unsigned long clone_flags); extern void ptrace_fork(struct task_struct *task, unsigned long clone_flags);
#define PTRACE_MODE_READ 1 #define PTRACE_MODE_READ 1
#define PTRACE_MODE_ATTACH 2 #define PTRACE_MODE_ATTACH 2
......
...@@ -237,6 +237,8 @@ int ptrace_attach(struct task_struct *task) ...@@ -237,6 +237,8 @@ int ptrace_attach(struct task_struct *task)
int ptrace_detach(struct task_struct *child, unsigned int data) int ptrace_detach(struct task_struct *child, unsigned int data)
{ {
int dead = 0;
if (!valid_signal(data)) if (!valid_signal(data))
return -EIO; return -EIO;
...@@ -244,18 +246,21 @@ int ptrace_detach(struct task_struct *child, unsigned int data) ...@@ -244,18 +246,21 @@ int ptrace_detach(struct task_struct *child, unsigned int data)
ptrace_disable(child); ptrace_disable(child);
clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE); clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
/* protect against de_thread()->release_task() */
write_lock_irq(&tasklist_lock); write_lock_irq(&tasklist_lock);
/* protect against de_thread()->release_task() */
if (child->ptrace) { if (child->ptrace) {
child->exit_code = data; child->exit_code = data;
__ptrace_unlink(child); dead = __ptrace_detach(current, child);
if (!child->exit_state) if (!child->exit_state)
wake_up_process(child); wake_up_process(child);
} }
write_unlock_irq(&tasklist_lock); write_unlock_irq(&tasklist_lock);
if (unlikely(dead))
release_task(child);
return 0; return 0;
} }
......
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