summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_sig.c
diff options
context:
space:
mode:
authorvisa <visa@openbsd.org>2020-03-18 15:48:21 +0000
committervisa <visa@openbsd.org>2020-03-18 15:48:21 +0000
commit19d4244da751ce8223f33a98ff39833f0404cc1e (patch)
tree3ecf07e6418cf6d5243b4382eec5946f16007906 /sys/kern/kern_sig.c
parentPlug mem leak in SADB_REGISTER. (diff)
downloadwireguard-openbsd-19d4244da751ce8223f33a98ff39833f0404cc1e.tar.xz
wireguard-openbsd-19d4244da751ce8223f33a98ff39833f0404cc1e.zip
Restart child process scan in dowait4() if single_thread_wait() sleeps.
This ensures that the conditions checked are still in force. The sleep breaks atomicity, allowing another thread to alter the state. single_thread_set() should return immediately after sleep when called from dowait4() because there is no guarantee that the process pr still exists. When called from single_thread_set(), the process is that of the calling thread, which prevents process pr from disappearing. OK anton@, mpi@, claudio@
Diffstat (limited to 'sys/kern/kern_sig.c')
-rw-r--r--sys/kern/kern_sig.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c
index 07a519e680b..9caba3240d4 100644
--- a/sys/kern/kern_sig.c
+++ b/sys/kern/kern_sig.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_sig.c,v 1.253 2020/03/13 09:25:21 mpi Exp $ */
+/* $OpenBSD: kern_sig.c,v 1.254 2020/03/18 15:48:21 visa Exp $ */
/* $NetBSD: kern_sig.c,v 1.54 1996/04/22 01:38:32 christos Exp $ */
/*
@@ -2024,17 +2024,25 @@ single_thread_set(struct proc *p, enum single_thread_mode mode, int deep)
}
if (mode != SINGLE_PTRACE)
- single_thread_wait(pr);
+ single_thread_wait(pr, 1);
return 0;
}
-void
-single_thread_wait(struct process *pr)
+int
+single_thread_wait(struct process *pr, int recheck)
{
+ int waited = 0;
+
/* wait until they're all suspended */
- while (pr->ps_singlecount > 0)
+ while (pr->ps_singlecount > 0) {
tsleep_nsec(&pr->ps_singlecount, PWAIT, "suspend", INFSLP);
+ waited = 1;
+ if (!recheck)
+ break;
+ }
+
+ return waited;
}
void