summaryrefslogtreecommitdiffstats
path: root/sys/kern/sys_generic.c
diff options
context:
space:
mode:
authorcheloha <cheloha@openbsd.org>2019-10-03 18:47:19 +0000
committercheloha <cheloha@openbsd.org>2019-10-03 18:47:19 +0000
commitade044871aeb7873c05f673982d81204f7bf8fe3 (patch)
tree7850db4465a910a949cf486e1b21a58760a152cc /sys/kern/sys_generic.c
parentMove towards making RSA OAEP functions handle arbitrary message digests. (diff)
downloadwireguard-openbsd-ade044871aeb7873c05f673982d81204f7bf8fe3.tar.xz
wireguard-openbsd-ade044871aeb7873c05f673982d81204f7bf8fe3.zip
poll(2), ppoll(2), select(2), pselect(2): always set P_SELECT before tsleep
When I introduced the tsleep loops in r1.23 I screwed it up and introduced a bug: on EWOULDBLOCK we loop but fail to reset P_SELECT, so the thread will continue to sleep but miss all relevant descriptor activity after INT_MAX ticks have elapsed. Spotted by mpi@ back in July. ok mpi@
Diffstat (limited to 'sys/kern/sys_generic.c')
-rw-r--r--sys/kern/sys_generic.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c
index f72ca9fd3cb..2fd7d6ec035 100644
--- a/sys/kern/sys_generic.c
+++ b/sys/kern/sys_generic.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sys_generic.c,v 1.125 2019/06/22 06:48:25 semarie Exp $ */
+/* $OpenBSD: sys_generic.c,v 1.126 2019/10/03 18:47:19 cheloha Exp $ */
/* $NetBSD: sys_generic.c,v 1.24 1996/03/29 00:25:32 cgd Exp $ */
/*
@@ -664,7 +664,7 @@ retry:
error = selscan(p, pibits[0], pobits[0], nd, ni, retval);
if (error || *retval)
goto done;
- while (timeout == NULL || timespecisset(timeout)) {
+ if (timeout == NULL || timespecisset(timeout)) {
timo = (timeout == NULL) ? 0 : tstohz(timeout);
if (timeout != NULL)
getnanouptime(&start);
@@ -683,10 +683,8 @@ retry:
if (timeout->tv_sec < 0)
timespecclear(timeout);
}
- if (error == 0)
+ if (error == 0 || error == EWOULDBLOCK)
goto retry;
- if (error != EWOULDBLOCK)
- break;
}
done:
atomic_clearbits_int(&p->p_flag, P_SELECT);
@@ -968,7 +966,7 @@ retry:
pollscan(p, pl, nfds, retval);
if (*retval)
goto done;
- while (timeout == NULL || timespecisset(timeout)) {
+ if (timeout == NULL || timespecisset(timeout)) {
timo = (timeout == NULL) ? 0 : tstohz(timeout);
if (timeout != NULL)
getnanouptime(&start);
@@ -987,10 +985,8 @@ retry:
if (timeout->tv_sec < 0)
timespecclear(timeout);
}
- if (error == 0)
+ if (error == 0 || error == EWOULDBLOCK)
goto retry;
- if (error != EWOULDBLOCK)
- break;
}
done: