Module Name: src Committed By: martin Date: Sun Aug 4 11:05:29 UTC 2019
Modified Files: src/sys/kern [netbsd-8]: sys_ptrace_common.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.22.2.5 -r1.22.2.6 src/sys/kern/sys_ptrace_common.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/sys_ptrace_common.c diff -u src/sys/kern/sys_ptrace_common.c:1.22.2.5 src/sys/kern/sys_ptrace_common.c:1.22.2.6 --- src/sys/kern/sys_ptrace_common.c:1.22.2.5 Mon Jul 22 18:02:09 2019 +++ src/sys/kern/sys_ptrace_common.c Sun Aug 4 11:05:29 2019 @@ -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 @@ ptrace_find(struct lwp *l, int req, pid_ } 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 @@ ptrace_allowed(struct lwp *l, int req, s 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 @@ do_ptrace(struct ptrace_methods *ptm, st int error, write, tmp, pheld; int signo = 0; int resume_all; + bool locked; error = 0; /* @@ -993,7 +999,7 @@ do_ptrace(struct ptrace_methods *ptm, st } 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 @@ out: } if (lt != NULL) lwp_delref(lt); - rw_exit(&t->p_reflock); + if (locked) + rw_exit(&t->p_reflock); return error; }