Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-9]: src/sys/kern Pull up following revision(s) (requested by kami...
details: https://anonhg.NetBSD.org/src/rev/719c197d6cf0
branches: netbsd-9
changeset: 963117:719c197d6cf0
user: martin <martin%NetBSD.org@localhost>
date: Tue Oct 15 19:01:06 2019 +0000
description:
Pull up following revision(s) (requested by kamil in ticket #320):
sys/kern/kern_synch.c: revision 1.324
sys/kern/kern_sig.c: revision 1.366
sys/kern/kern_exit.c: revision 1.277
sys/kern/kern_lwp.c: revision 1.204
sys/kern/sys_ptrace_common.c: revision 1.62
Separate flag for suspended by _lwp_suspend and suspended by a debugger
Once a thread was stopped with ptrace(2), userland process must not
be able to unstop it deliberately or by an accident.
This was a Windows-style behavior that makes threading tracing fragile.
diffstat:
sys/kern/kern_exit.c | 5 +++--
sys/kern/kern_lwp.c | 13 ++++++++++---
sys/kern/kern_sig.c | 20 +++++++++++++++-----
sys/kern/kern_synch.c | 5 +++--
sys/kern/sys_ptrace_common.c | 22 ++++++++++++++--------
5 files changed, 45 insertions(+), 20 deletions(-)
diffs (223 lines):
diff -r 1a3294e0393e -r 719c197d6cf0 sys/kern/kern_exit.c
--- a/sys/kern/kern_exit.c Tue Oct 15 18:50:44 2019 +0000
+++ b/sys/kern/kern_exit.c Tue Oct 15 19:01:06 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_exit.c,v 1.276 2019/06/13 20:20:18 kamil Exp $ */
+/* $NetBSD: kern_exit.c,v 1.276.2.1 2019/10/15 19:01:06 martin Exp $ */
/*-
* Copyright (c) 1998, 1999, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.276 2019/06/13 20:20:18 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.276.2.1 2019/10/15 19:01:06 martin Exp $");
#include "opt_ktrace.h"
#include "opt_dtrace.h"
@@ -617,6 +617,7 @@
l2->l_flag |= LW_WEXIT;
if ((l2->l_stat == LSSLEEP && (l2->l_flag & LW_SINTR)) ||
l2->l_stat == LSSUSPENDED || l2->l_stat == LSSTOP) {
+ l2->l_flag &= ~LW_DBGSUSPEND;
/* setrunnable() will release the lock. */
setrunnable(l2);
continue;
diff -r 1a3294e0393e -r 719c197d6cf0 sys/kern/kern_lwp.c
--- a/sys/kern/kern_lwp.c Tue Oct 15 18:50:44 2019 +0000
+++ b/sys/kern/kern_lwp.c Tue Oct 15 19:01:06 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_lwp.c,v 1.202.2.1 2019/10/15 18:32:13 martin Exp $ */
+/* $NetBSD: kern_lwp.c,v 1.202.2.2 2019/10/15 19:01:06 martin Exp $ */
/*-
* Copyright (c) 2001, 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -211,7 +211,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.202.2.1 2019/10/15 18:32:13 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.202.2.2 2019/10/15 19:01:06 martin Exp $");
#include "opt_ddb.h"
#include "opt_lockdebug.h"
@@ -408,6 +408,11 @@
return (EDEADLK);
}
+ if ((t->l_flag & LW_DBGSUSPEND) != 0) {
+ lwp_unlock(t);
+ return 0;
+ }
+
error = 0;
switch (t->l_stat) {
@@ -472,7 +477,7 @@
l->l_flag &= ~LW_WSUSPEND;
- if (l->l_stat != LSSUSPENDED) {
+ if (l->l_stat != LSSUSPENDED || (l->l_flag & LW_DBGSUSPEND) != 0) {
lwp_unlock(l);
return;
}
@@ -497,6 +502,8 @@
lwp_lock(l);
+ KASSERT((l->l_flag & LW_DBGSUSPEND) == 0);
+
/* If not stopped, then just bail out. */
if (l->l_stat != LSSTOP) {
lwp_unlock(l);
diff -r 1a3294e0393e -r 719c197d6cf0 sys/kern/kern_sig.c
--- a/sys/kern/kern_sig.c Tue Oct 15 18:50:44 2019 +0000
+++ b/sys/kern/kern_sig.c Tue Oct 15 19:01:06 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_sig.c,v 1.364.2.1 2019/10/15 18:32:13 martin Exp $ */
+/* $NetBSD: kern_sig.c,v 1.364.2.2 2019/10/15 19:01:06 martin Exp $ */
/*-
* Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.364.2.1 2019/10/15 18:32:13 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.364.2.2 2019/10/15 19:01:06 martin Exp $");
#include "opt_ptrace.h"
#include "opt_dtrace.h"
@@ -1108,11 +1108,20 @@
SDT_PROBE(proc, kernel, , signal__send, l, p, sig, 0, 0);
+ lwp_lock(l);
+ if (__predict_false((l->l_flag & LW_DBGSUSPEND) != 0)) {
+ if ((prop & SA_KILL) != 0)
+ l->l_flag &= ~LW_DBGSUSPEND;
+ else {
+ lwp_unlock(l);
+ return 0;
+ }
+ }
+
/*
* Have the LWP check for signals. This ensures that even if no LWP
* is found to take the signal immediately, it should be taken soon.
*/
- lwp_lock(l);
l->l_flag |= LW_PENDSIG;
/*
@@ -2179,7 +2188,8 @@
LIST_FOREACH(t, &p->p_lwps, l_sibling) {
lwp_lock(t);
if (t == l) {
- t->l_flag &= ~LW_WSUSPEND;
+ t->l_flag &=
+ ~(LW_WSUSPEND | LW_DBGSUSPEND);
lwp_unlock(t);
continue;
}
@@ -2376,7 +2386,7 @@
LIST_FOREACH(l, &p->p_lwps, l_sibling) {
lwp_lock(l);
- if (l->l_stat != LSSTOP) {
+ if (l->l_stat != LSSTOP || (l->l_flag & LW_DBGSUSPEND) != 0) {
lwp_unlock(l);
continue;
}
diff -r 1a3294e0393e -r 719c197d6cf0 sys/kern/kern_synch.c
--- a/sys/kern/kern_synch.c Tue Oct 15 18:50:44 2019 +0000
+++ b/sys/kern/kern_synch.c Tue Oct 15 19:01:06 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_synch.c,v 1.323 2019/02/03 03:19:28 mrg Exp $ */
+/* $NetBSD: kern_synch.c,v 1.323.4.1 2019/10/15 19:01:06 martin Exp $ */
/*-
* Copyright (c) 1999, 2000, 2004, 2006, 2007, 2008, 2009
@@ -69,7 +69,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_synch.c,v 1.323 2019/02/03 03:19:28 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_synch.c,v 1.323.4.1 2019/10/15 19:01:06 martin Exp $");
#include "opt_kstack.h"
#include "opt_dtrace.h"
@@ -885,6 +885,7 @@
struct cpu_info *ci;
KASSERT((l->l_flag & LW_IDLE) == 0);
+ KASSERT((l->l_flag & LW_DBGSUSPEND) == 0);
KASSERT(mutex_owned(p->p_lock));
KASSERT(lwp_locked(l, NULL));
KASSERT(l->l_mutex != l->l_cpu->ci_schedstate.spc_mutex);
diff -r 1a3294e0393e -r 719c197d6cf0 sys/kern/sys_ptrace_common.c
--- a/sys/kern/sys_ptrace_common.c Tue Oct 15 18:50:44 2019 +0000
+++ b/sys/kern/sys_ptrace_common.c Tue Oct 15 19:01:06 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sys_ptrace_common.c,v 1.58.2.4 2019/10/15 18:50:44 martin Exp $ */
+/* $NetBSD: sys_ptrace_common.c,v 1.58.2.5 2019/10/15 19:01:06 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.58.2.4 2019/10/15 18:50:44 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.58.2.5 2019/10/15 19:01:06 martin Exp $");
#ifdef _KERNEL_OPT
#include "opt_ptrace.h"
@@ -787,9 +787,12 @@
DPRINTF(("%s: lwp=%d request=%d\n", __func__, (*lt)->l_lid, rq));
lwp_lock(*lt);
if (rq == PT_SUSPEND)
- (*lt)->l_flag |= LW_WSUSPEND;
- else
- (*lt)->l_flag &= ~LW_WSUSPEND;
+ (*lt)->l_flag |= LW_DBGSUSPEND;
+ else {
+ (*lt)->l_flag &= ~LW_DBGSUSPEND;
+ if ((*lt)->l_flag != LSSUSPENDED)
+ (*lt)->l_stat = LSSTOP;
+ }
lwp_unlock(*lt);
return 0;
}
@@ -1237,7 +1240,8 @@
if (resume_all) {
#ifdef PT_STEP
if (req == PT_STEP) {
- if (lt->l_flag & LW_WSUSPEND) {
+ if (lt->l_flag &
+ (LW_WSUSPEND | LW_DBGSUSPEND)) {
error = EDEADLK;
break;
}
@@ -1246,7 +1250,9 @@
{
error = EDEADLK;
LIST_FOREACH(lt2, &t->p_lwps, l_sibling) {
- if ((lt2->l_flag & LW_WSUSPEND) == 0) {
+ if ((lt2->l_flag &
+ (LW_WSUSPEND | LW_DBGSUSPEND)) == 0
+ ) {
error = 0;
break;
}
@@ -1255,7 +1261,7 @@
break;
}
} else {
- if (lt->l_flag & LW_WSUSPEND) {
+ if (lt->l_flag & (LW_WSUSPEND | LW_WSUSPEND)) {
error = EDEADLK;
break;
}
Home |
Main Index |
Thread Index |
Old Index