commit 901e2c6cc177dd4151a4c88c62948703caa160cb Author: Greg Kroah-Hartman Date: Thu Jun 18 14:31:08 2020 +0200 Linux 5.7.4 commit 72b01e01812e774e8aece494c845dadf86825168 Author: Thomas Gleixner Date: Sat Jun 6 23:51:16 2020 +0200 lib/vdso: Provide sanity check for cycles (again) commit 72ce778007e57e8996b4bebdec738fc5e1145fd2 upstream. The original x86 VDSO implementation checked for the validity of the clock source read by testing whether the returned signed cycles value is less than zero. This check was also used by the vdso read function to signal that the current selected clocksource is not VDSO capable. During the rework of the VDSO code the check was removed and replaced with a check for the clocksource mode being != NONE. This turned out to be a mistake because the check is necessary for paravirt and hyperv clock sources. The reason is that these clock sources have their own internal sequence counter to validate the clocksource at the point of reading it. This is necessary because the hypervisor can invalidate the clocksource asynchronously so a check during the VDSO data update is not sufficient. Having a separate indicator for the validity is slower than just validating the cycles value. The check for it being negative turned out to be the fastest implementation and safe as it would require an uptime of ~73 years with a 4GHz counter frequency to result in a false positive. Add an optional function to validate the cycles with a default implementation which allows the compiler to optimize it out for architectures which do not require it. Fixes: 5d51bee725cc ("clocksource: Add common vdso clock mode storage") Reported-by: Miklos Szeredi Signed-off-by: Thomas Gleixner Tested-by: Miklos Szeredi Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/20200606221531.963970768@linutronix.de Signed-off-by: Greg Kroah-Hartman