Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern kern: Use timespecsubok in ts2timo.



details:   https://anonhg.NetBSD.org/src/rev/9efc6a37d2df
branches:  trunk
changeset: 368179:9efc6a37d2df
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Jun 26 22:31:47 2022 +0000

description:
kern: Use timespecsubok in ts2timo.

Should fix arithmetic overflow.

Reported-by: syzbot+4393a753a7c787abe6e2%syzkaller.appspotmail.com@localhost

diffstat:

 sys/kern/subr_time.c |  12 +++---------
 1 files changed, 3 insertions(+), 9 deletions(-)

diffs (33 lines):

diff -r a1aa394ee73f -r 9efc6a37d2df sys/kern/subr_time.c
--- a/sys/kern/subr_time.c      Sun Jun 26 22:31:38 2022 +0000
+++ b/sys/kern/subr_time.c      Sun Jun 26 22:31:47 2022 +0000
@@ -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 @@
        }
 
        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);
        }



Home | Main Index | Thread Index | Old Index