Module Name:    src
Committed By:   martin
Date:           Mon Jul 22 18:02:09 UTC 2019

Modified Files:
        src/sys/kern [netbsd-8]: sys_ptrace_common.c

Log Message:
Pull up following revision(s) (requested by kamil in ticket #1302):

        sys/kern/sys_ptrace_common.c: revision 1.58

Enhance locking of ptrace_update_lwp

Replace lwp_delref() + mutex_enter() with: mutex_enter() + lwp_delref2().=

This avoids extra taking and exiting from a mutex.

Add missing mutex_exit() for LW_SYSTEM.

Do not switch lwp for PT_SET_SIGINFO. This operation is not needed and
avoids panic for >2 LWPs as p_lock is attempted to be entered again in a
critical section.


To generate a diff of this commit:
cvs rdiff -u -r1.22.2.4 -r1.22.2.5 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.4 src/sys/kern/sys_ptrace_common.c:1.22.2.5
--- src/sys/kern/sys_ptrace_common.c:1.22.2.4	Thu Nov 29 14:58:25 2018
+++ src/sys/kern/sys_ptrace_common.c	Mon Jul 22 18:02:09 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_ptrace_common.c,v 1.22.2.4 2018/11/29 14:58:25 martin Exp $	*/
+/*	$NetBSD: sys_ptrace_common.c,v 1.22.2.5 2019/07/22 18:02:09 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.4 2018/11/29 14:58:25 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.22.2.5 2019/07/22 18:02:09 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ptrace.h"
@@ -527,9 +527,9 @@ ptrace_update_lwp(struct proc *t, struct
 	if (lid == 0 || lid == (*lt)->l_lid || t->p_nlwps == 1)
 		return 0;
 
-	lwp_delref(*lt);
-
 	mutex_enter(t->p_lock);
+	lwp_delref2(*lt);
+
 	*lt = lwp_find(t, lid);
 	if (*lt == NULL) {
 		mutex_exit(t->p_lock);
@@ -537,6 +537,7 @@ ptrace_update_lwp(struct proc *t, struct
 	}
 
 	if ((*lt)->l_flag & LW_SYSTEM) {
+		mutex_exit(t->p_lock);
 		*lt = NULL;
 		return EINVAL;
 	}
@@ -574,9 +575,6 @@ ptrace_set_siginfo(struct proc *t, struc
 	if (psi.psi_siginfo.si_signo < 0 || psi.psi_siginfo.si_signo >= NSIG)
 		return EINVAL;
 
-	if ((error = ptrace_update_lwp(t, lt, psi.psi_lwpid)) != 0)
-		return error;
-
 	t->p_sigctx.ps_faked = true;
 	t->p_sigctx.ps_info = psi.psi_siginfo._info;
 	t->p_sigctx.ps_lwp = psi.psi_lwpid;

Reply via email to