vdso: Make delta calculation overflow safe
authorAdrian Hunter <adrian.hunter@intel.com>
Mon, 25 Mar 2024 06:40:11 +0000 (08:40 +0200)
committerThomas Gleixner <tglx@linutronix.de>
Mon, 8 Apr 2024 13:03:07 +0000 (15:03 +0200)
commit456e3788bc7164c1c8298045e04068b8e3d8e413
tree09efbe2666a269c3da3a88e9dba4ff3498b30a23
parentd2e58ab5cda2a225c406ac10d0a8b960bc5a39b6
vdso: Make delta calculation overflow safe

Kernel timekeeping is designed to keep the change in cycles (since the last
timer interrupt) below max_cycles, which prevents multiplication overflow
when converting cycles to nanoseconds. However, if timer interrupts stop,
the calculation will eventually overflow.

Add protection against that, enabled by config option
CONFIG_GENERIC_VDSO_OVERFLOW_PROTECT. Check against max_cycles, falling
back to a slower higher precision calculation.

Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20240325064023.2997-8-adrian.hunter@intel.com
lib/vdso/gettimeofday.c