Page MenuHomeFreeBSD

posix timers: Improve the overrun calculation
ClosedPublic

Authored by markj on Mar 5 2021, 4:43 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Apr 16, 3:48 PM
Unknown Object (File)
Feb 21 2024, 3:10 AM
Unknown Object (File)
Feb 14 2024, 6:07 AM
Unknown Object (File)
Feb 6 2024, 1:07 PM
Unknown Object (File)
Jan 29 2024, 5:30 AM
Unknown Object (File)
Dec 26 2023, 6:45 PM
Unknown Object (File)
Dec 20 2023, 12:27 AM
Unknown Object (File)
Dec 14 2023, 10:38 PM
Subscribers

Details

Summary

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

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

markj requested review of this revision.Mar 5 2021, 4:43 PM
sys/kern/kern_time.c
1640

but now - value can overflow if unchecked

1641

same for it_overrun + overruns

Both overflows are not UB but I think we want to avoid them nonetheless for correctness, since we check for other overflow there?

sys/kern/kern_time.c
1640

Which overflow do you mean exactly? We know that now >= value here.

sys/kern/kern_time.c
1640

Yes, this comment is nonsensical. But I still think it_overrun+overruns can overflow

Try to handle overflow when computing the 64-bit number of overruns.

This revision is now accepted and ready to land.Mar 7 2021, 3:38 PM
This revision was automatically updated to reflect the committed changes.