Module Name:    src
Committed By:   riastradh
Date:           Sun Jun 26 22:31:47 UTC 2022

Modified Files:
        src/sys/kern: subr_time.c

Log Message:
kern: Use timespecsubok in ts2timo.

Should fix arithmetic overflow.

Reported-by: syzbot+4393a753a7c787abe...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/kern/subr_time.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/subr_time.c
diff -u src/sys/kern/subr_time.c:1.33 src/sys/kern/subr_time.c:1.34
--- src/sys/kern/subr_time.c:1.33	Sun Jun 26 22:31:38 2022
+++ src/sys/kern/subr_time.c	Sun Jun 26 22:31:47 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_time.c,v 1.33 2022/06/26 22:31:38 riastradh Exp $	*/
+/*	$NetBSD: subr_time.c,v 1.34 2022/06/26 22:31:47 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_time.c,v 1.33 2022/06/26 22:31:38 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_time.c,v 1.34 2022/06/26 22:31:47 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -341,13 +341,7 @@ ts2timo(clockid_t clock_id, int flags, s
 	}
 
 	if ((flags & TIMER_ABSTIME) != 0) {
-		/*
-		 * Add one to the bound to account for possible carry
-		 * from tv_nsec in timespecsub.
-		 */
-		if (tsd.tv_sec > 0 && ts->tv_sec < LLONG_MIN + tsd.tv_sec + 1)
-			return EINVAL;
-		if (tsd.tv_sec < 0 && ts->tv_sec > LLONG_MAX + tsd.tv_sec - 1)
+		if (!timespecsubok(ts, &tsd))
 			return EINVAL;
 		timespecsub(ts, &tsd, ts);
 	}

Reply via email to