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
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D29093

Details

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