diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c index 9479401719a0..e25ddd72ac64 100644 --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -851,10 +851,18 @@ itimer_callout(void *arg) } else { getnanotime(&now); } + backwards = (timespeccmp(&it->it_time.it_value, &now, >)); - timespecadd(&it->it_time.it_value, &it->it_time.it_interval, &next); + + /* Nonnegative interval guaranteed by itimerfix. */ + KASSERT(it->it_time.it_interval.tv_sec >= 0); + KASSERT(it->it_time.it_interval.tv_nsec >= 0); + /* Handle the easy case of non-overflown timers first. */ - if (!backwards && timespeccmp(&next, &now, >)) { + if (!backwards && + timespecaddok(&it->it_time.it_value, &it->it_time.it_interval)) { + timespecadd(&it->it_time.it_value, &it->it_time.it_interval, + &next); it->it_time.it_value = next; } else { now_ns = timespec2ns(&now);