kernel - Fix parent process signaling race during exit
authorMatthew Dillon <dillon@apollo.backplane.com>
Sat, 29 Jan 2011 21:20:43 +0000 (13:20 -0800)
committerMatthew Dillon <dillon@apollo.backplane.com>
Sat, 29 Jan 2011 21:20:43 +0000 (13:20 -0800)
* Fix a lwpsignal race when an exiting child signals its parent
  while the child is in the process of being reparented to process 1
  (due to the parent itself exiting).

Reported-by: YONETANI Tomokazu <y0n3t4n1@gmail.com>
sys/kern/kern_exit.c

index 3270368..71697e4 100644 (file)
@@ -530,13 +530,19 @@ exit1(int rv)
                        wakeup((caddr_t)pp);
        }
 
-       if (p->p_sigparent && p->p_pptr != initproc) {
-               ksignal(p->p_pptr, p->p_sigparent);
+       /* lwkt_gettoken(&proc_token); */
+       q = p->p_pptr;
+       if (p->p_sigparent && q != initproc) {
+               PHOLD(q);
+               ksignal(q, p->p_sigparent);
+               PRELE(q);
        } else {
-               ksignal(p->p_pptr, SIGCHLD);
+               ksignal(q, SIGCHLD);
        }
+       /* lwkt_reltoken(&proc_token); */
+       /* NOTE: p->p_pptr can get ripped out */
 
-       wakeup((caddr_t)p->p_pptr);
+       wakeup(p->p_pptr);
        /*
         * cpu_exit is responsible for clearing curproc, since
         * it is heavily integrated with the thread/switching sequence.