From edaa4fc85aa6a6f2a7a6371f2282ab83c49cec3c Mon Sep 17 00:00:00 2001 From: cheloha Date: Tue, 22 May 2018 18:33:42 +0000 Subject: nanosleep: ensure tv_nsec input is on [0, 1000000000) Instead of converting timespec -> timeval and truncating the input, check with timespecfix and use tstohz(9) for the tsleep. All other contemporary systems check this correctly. Also add a regression test for this case. ok tb@ --- sys/kern/kern_time.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'sys/kern') diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c index ab86d059e79..8d6a8333f38 100644 --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_time.c,v 1.101 2018/02/19 08:59:52 mpi Exp $ */ +/* $OpenBSD: kern_time.c,v 1.102 2018/05/22 18:33:41 cheloha Exp $ */ /* $NetBSD: kern_time.c,v 1.20 1996/02/18 11:57:06 fvdl Exp $ */ /* @@ -268,7 +268,6 @@ sys_nanosleep(struct proc *p, void *v, register_t *retval) struct timespec rqt, rmt; struct timespec sts, ets; struct timespec *rmtp; - struct timeval tv; int error, error1; rmtp = SCARG(uap, rmtp); @@ -283,15 +282,14 @@ sys_nanosleep(struct proc *p, void *v, register_t *retval) } #endif - TIMESPEC_TO_TIMEVAL(&tv, &rqt); - if (itimerfix(&tv)) + if (rqt.tv_sec > 100000000 || timespecfix(&rqt)) return (EINVAL); if (rmtp) getnanouptime(&sts); error = tsleep(&nanowait, PWAIT | PCATCH, "nanosleep", - MAX(1, tvtohz(&tv))); + MAX(1, tstohz(&rqt))); if (error == ERESTART) error = EINTR; if (error == EWOULDBLOCK) -- cgit v1.2.3