Module Name: src
Committed By: kamil
Date: Thu Jul 18 20:10:46 UTC 2019
Modified Files:
src/sys/kern: sys_ptrace_common.c
Log Message:
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.57 -r1.58 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.57 src/sys/kern/sys_ptrace_common.c:1.58
--- src/sys/kern/sys_ptrace_common.c:1.57 Sat Jun 29 11:37:17 2019
+++ src/sys/kern/sys_ptrace_common.c Thu Jul 18 20:10:46 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sys_ptrace_common.c,v 1.57 2019/06/29 11:37:17 maxv Exp $ */
+/* $NetBSD: sys_ptrace_common.c,v 1.58 2019/07/18 20:10:46 kamil 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.57 2019/06/29 11:37:17 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.58 2019/07/18 20:10:46 kamil Exp $");
#ifdef _KERNEL_OPT
#include "opt_ptrace.h"
@@ -552,9 +552,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);
@@ -562,6 +562,7 @@ ptrace_update_lwp(struct proc *t, struct
}
if ((*lt)->l_flag & LW_SYSTEM) {
+ mutex_exit(t->p_lock);
*lt = NULL;
return EINVAL;
}
@@ -601,9 +602,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;