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)
Fri, Nov 1, 5:32 PM
Unknown Object (File)
Sun, Oct 27, 4:16 PM
Unknown Object (File)
Sun, Oct 27, 4:15 PM
Unknown Object (File)
Sun, Oct 27, 4:15 PM
Unknown Object (File)
Sun, Oct 27, 4:15 PM
Unknown Object (File)
Sun, Oct 27, 4:14 PM
Unknown Object (File)
Thu, Oct 24, 12:13 AM
Unknown Object (File)
Sat, Oct 12, 11:44 AM
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.