From 476c0e969a704387c24bd4f125e4c7c53013c876 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 8 Feb 2022 11:23:19 +0100 Subject: [PATCH] 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. --- src/boot/efi/ticks.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/boot/efi/ticks.c b/src/boot/efi/ticks.c index 68b2d5806c..fd0e2b2348 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 -- 2.25.1