]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
ptrace: fix possible zombie leak on PTRACE_DETACH
authorOleg Nesterov <oleg@redhat.com>
Thu, 2 Apr 2009 23:58:14 +0000 (16:58 -0700)
committerGreg Kroah-Hartman <gregkh@suse.de>
Mon, 15 Jun 2009 16:40:20 +0000 (09:40 -0700)
commit 4576145c1ecdaaea9ef8976a48335206aa1ebf91 upstream.

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: Oleg Nesterov <oleg@redhat.com>
Cc: Jerome Marchand <jmarchan@redhat.com>
Cc: Roland McGrath <roland@redhat.com>
Tested-by: Denys Vlasenko <dvlasenk@redhat.com>
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@suse.de>
include/linux/ptrace.h
kernel/ptrace.c

index 98b93ca4db064e5d6ebae919206fe5ed55a45427..1a2b0cb55535de2746d663e0cebcc1a0ca408968 100644 (file)
@@ -94,6 +94,7 @@ extern void ptrace_notify(int exit_code);
 extern void __ptrace_link(struct task_struct *child,
                          struct task_struct *new_parent);
 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);
 #define PTRACE_MODE_READ   1
 #define PTRACE_MODE_ATTACH 2
index 2f5ec7a571a86f0407291ef7ea17a9c5fa1c74f3..893c2c7615d5a045a8b07a0fc6b21040599146bb 100644 (file)
@@ -237,6 +237,8 @@ out:
 
 int ptrace_detach(struct task_struct *child, unsigned int data)
 {
+       int dead = 0;
+
        if (!valid_signal(data))
                return -EIO;
 
@@ -244,18 +246,21 @@ int ptrace_detach(struct task_struct *child, unsigned int data)
        ptrace_disable(child);
        clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
 
-       /* protect against de_thread()->release_task() */
        write_lock_irq(&tasklist_lock);
+       /* protect against de_thread()->release_task() */
        if (child->ptrace) {
                child->exit_code = data;
 
-               __ptrace_unlink(child);
+               dead = __ptrace_detach(current, child);
 
                if (!child->exit_state)
                        wake_up_process(child);
        }
        write_unlock_irq(&tasklist_lock);
 
+       if (unlikely(dead))
+               release_task(child);
+
        return 0;
 }