kernel - MPSAFE work - fix bugs in recent MPSAFE work.
authorMatthew Dillon <dillon@apollo.backplane.com>
Sun, 13 Jun 2010 16:31:25 +0000 (09:31 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Sun, 13 Jun 2010 16:31:25 +0000 (09:31 -0700)
* Adjust comment for zpfind(), it does not PHOLD() the returned process,
  in order to match pfind().

* Adjust two use-cases for zpfind() to hold proc_token across the call,
  and to PHOLD/PRELE(p) if necessary, so (p) remains stable.

Reported-by: Venkatesh Srinivas <vsrinivas@crater.dragonflybsd.org>
sys/emulation/linux/linux_signal.c
sys/kern/kern_event.c
sys/kern/kern_proc.c

index 00b8130..d1e14b7 100644 (file)
@@ -424,30 +424,36 @@ linux_do_tkill(l_int tgid, l_int pid, l_int sig)
                sig = linux_to_bsd_signal[_SIG_IDX(sig)];
 
        get_mplock();
+       lwkt_gettoken(&proc_token);
        if ((p = pfind(pid)) == NULL) {
                if ((p = zpfind(pid)) == NULL) {
-                       rel_mplock();
-                       return (ESRCH);
+                       error = ESRCH;
+                       goto done2;
                }
        }
+       PHOLD(p);
 
        EMUL_LOCK();
        em = emuldata_get(p);
 
        if (em == NULL) {
                EMUL_UNLOCK();
-               rel_mplock();
-               return (ESRCH);
+               error = ESRCH;
+               goto done1;
        }
 
        if (tgid > 0 && em->s->group_pid != tgid) {
                EMUL_UNLOCK();
-               rel_mplock();
-               return (ESRCH);
+               error = ESRCH;
+               goto done1;
        }
        EMUL_UNLOCK();
        
        error = kern_kill(sig, pid, -1);
+done1:
+       PRELE(p);
+done2:
+       lwkt_reltoken(&proc_token);
        rel_mplock();
 
        return (error);
index 72eaecf..defe052 100644 (file)
@@ -198,15 +198,20 @@ filt_procattach(struct knote *kn)
        int immediate;
 
        immediate = 0;
+       lwkt_gettoken(&proc_token);
        p = pfind(kn->kn_id);
        if (p == NULL && (kn->kn_sfflags & NOTE_EXIT)) {
                p = zpfind(kn->kn_id);
                immediate = 1;
        }
-       if (p == NULL)
+       if (p == NULL) {
+               lwkt_reltoken(&proc_token);
                return (ESRCH);
-       if (!PRISON_CHECK(curthread->td_ucred, p->p_ucred))
+       }
+       if (!PRISON_CHECK(curthread->td_ucred, p->p_ucred)) {
+               lwkt_reltoken(&proc_token);
                return (EACCES);
+       }
 
        kn->kn_ptr.p_proc = p;
        kn->kn_flags |= EV_CLEAR;               /* automatically set */
@@ -230,6 +235,7 @@ filt_procattach(struct knote *kn)
         */
        if (immediate && filt_proc(kn, NOTE_EXIT))
                KNOTE_ACTIVATE(kn);
+       lwkt_reltoken(&proc_token);
 
        return (0);
 }
index 4d6975b..5fb6942 100644 (file)
@@ -689,7 +689,7 @@ DB_SHOW_COMMAND(pgrpdump, pgrpdump)
 #endif /* DDB */
 
 /*
- * Locate a process on the zombie list.  Return a held process or NULL.
+ * Locate a process on the zombie list.  Return a process or NULL.
  *
  * The caller must hold proc_token if a stable result is desired.
  * No other requirements.