From: Lennart Poettering Date: Tue, 8 Feb 2022 10:23:19 +0000 (+0100) Subject: sd-boot: add overflow check to TSC reads X-Git-Tag: v251-rc1~326^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=476c0e969a704387c24bd4f125e4c7c53013c876;p=thirdparty%2Fsystemd.git sd-boot: add overflow check to TSC reads On some archs the counter is 32bit, and in case of virtualization it might actually overflow, who knows. --- diff --git a/src/boot/efi/ticks.c b/src/boot/efi/ticks.c index 68b2d5806ce..fd0e2b23484 100644 --- a/src/boot/efi/ticks.c +++ b/src/boot/efi/ticks.c @@ -45,6 +45,10 @@ UINT64 ticks_freq(void) { BS->Stall(1000); ticks_end = ticks_read(); + if (ticks_end < ticks_start) /* Check for an overflow (which is not that unlikely, given on some + * archs the value is 32bit) */ + return 0; + return (ticks_end - ticks_start) * 1000UL; } #endif