HomeFreeBSD

posix timers: Improve the overrun calculation

Description

posix timers: Improve the overrun calculation

timer_settime(2) may be used to configure a timeout in the past. If
the timer is also periodic, we also try to compute the number of timer
overruns that occurred between the initial timeout and the time at which
the timer fired. This is done in a loop which iterates once per period
between the initial timeout and now. If the period is small and the
initial timeout was a long time ago, this loop can take forever to run,
so the system is effectively DOSed.

Replace the loop with a more direct calculation of
(now - initial timeout) / period to compute the number of overruns.

Reported by: syzkaller
Reviewed by: kib
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D29093

(cherry picked from commit 7995dae9d3f58abf38ef0001cee24131f3c9054b)

Details

Provenance
markjAuthored on Mar 8 2021, 5:39 PM
Reviewer
kib
Differential Revision
D29093: posix timers: Improve the overrun calculation
Parents
rG7d1dda82cfda: posix timers: Sprinkle some style fixes
Branches
Unknown
Tags
Unknown