]> git.hungrycats.org Git - linux/commitdiff
[PATCH] fix spinlock deadlock in ptrace-reaping of detached thread
authorRoland McGrath <roland@redhat.com>
Tue, 5 Aug 2003 17:52:34 +0000 (10:52 -0700)
committerLinus Torvalds <torvalds@home.osdl.org>
Tue, 5 Aug 2003 17:52:34 +0000 (10:52 -0700)
When a dead detached thread has been temporarily zombified because it's
ptraced and its tracer tries to reap it, it deadlocks on SMP.

Here's the fix.

kernel/exit.c

index d5f45b814d1fe125a4de1697ec557a3da44a28f6..a7328cc9992bf481f19c26ecbd35514507dbb3a1 100644 (file)
@@ -898,13 +898,19 @@ static int wait_task_zombie(task_t *p, unsigned int *stat_addr, struct rusage *r
                        __ptrace_unlink(p);
                        p->state = TASK_ZOMBIE;
                        /* If this is a detached thread, this is where it goes away.  */
-                       if (p->exit_signal == -1)
+                       if (p->exit_signal == -1) {
+                               /* release_task takes the lock itself.  */
+                               write_unlock_irq(&tasklist_lock);
                                release_task (p);
-                       else
+                       }
+                       else {
                                do_notify_parent(p, p->exit_signal);
+                               write_unlock_irq(&tasklist_lock);
+                       }
                        p = NULL;
                }
-               write_unlock_irq(&tasklist_lock);
+               else
+                       write_unlock_irq(&tasklist_lock);
        }
        if (p != NULL)
                release_task(p);