Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-8]: src/sys/kern Pull up following revision(s) (requested by maxv...



details:   https://anonhg.NetBSD.org/src/rev/59e44e9ede49
branches:  netbsd-8
changeset: 453746:59e44e9ede49
user:      martin <martin%NetBSD.org@localhost>
date:      Sun Aug 04 11:05:29 2019 +0000

description:
Pull up following revision(s) (requested by maxv in ticket #1319):

        sys/kern/sys_ptrace_common.c: revision 1.57

Fix bug, don't release the reflock if we didn't take it in the first place.
Looks like there are other locking issues in here.

diffstat:

 sys/kern/sys_ptrace_common.c |  17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)

diffs (67 lines):

diff -r 6553ceaff3c2 -r 59e44e9ede49 sys/kern/sys_ptrace_common.c
--- a/sys/kern/sys_ptrace_common.c      Sun Aug 04 11:01:22 2019 +0000
+++ b/sys/kern/sys_ptrace_common.c      Sun Aug 04 11:05:29 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sys_ptrace_common.c,v 1.22.2.5 2019/07/22 18:02:09 martin Exp $        */
+/*     $NetBSD: sys_ptrace_common.c,v 1.22.2.6 2019/08/04 11:05:29 martin Exp $        */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -118,7 +118,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.22.2.5 2019/07/22 18:02:09 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.22.2.6 2019/08/04 11:05:29 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ptrace.h"
@@ -365,8 +365,11 @@
 }
 
 static int
-ptrace_allowed(struct lwp *l, int req, struct proc *t, struct proc *p)
+ptrace_allowed(struct lwp *l, int req, struct proc *t, struct proc *p,
+    bool *locked)
 {
+       *locked = false;
+
        /*
         * Grab a reference on the process to prevent it from execing or
         * exiting.
@@ -374,6 +377,8 @@
        if (!rw_tryenter(&t->p_reflock, RW_READER))
                return EBUSY;
 
+       *locked = true;
+
        /* Make sure we can operate on it. */
        switch (req) {
        case PT_TRACE_ME:
@@ -978,6 +983,7 @@
        int error, write, tmp, pheld;
        int signo = 0;
        int resume_all;
+       bool locked;
        error = 0;
 
        /*
@@ -993,7 +999,7 @@
        }
 
        pheld = 1;
-       if ((error = ptrace_allowed(l, req, t, p)) != 0)
+       if ((error = ptrace_allowed(l, req, t, p, &locked)) != 0)
                goto out;
 
        if ((error = kauth_authorize_process(l->l_cred,
@@ -1318,7 +1324,8 @@
        }
        if (lt != NULL)
                lwp_delref(lt);
-       rw_exit(&t->p_reflock);
+       if (locked)
+               rw_exit(&t->p_reflock);
 
        return error;
 }



Home | Main Index | Thread Index | Old Index