]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-boot: add overflow check to TSC reads
authorLennart Poettering <lennart@poettering.net>
Tue, 8 Feb 2022 10:23:19 +0000 (11:23 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 8 Feb 2022 12:46:14 +0000 (13:46 +0100)
On some archs the counter is 32bit, and in case of virtualization it
might actually overflow, who knows.

src/boot/efi/ticks.c

index 68b2d5806ce23376f62ebe0ac37db8f5adf5d964..fd0e2b234840d787d663e680db6e531831538b0e 100644 (file)
@@ -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