Skip to contentSkip to conversation

target-i386: avoid overflow in the tsc-frequency property

PATCH Applied Paolo Bonzini 2 participants 2 messages Jun 24, 2015 – Jun 25, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target-i386: avoid overflow in the tsc-frequency property

The TSC frequency fits comfortably in an int when expressed in kHz, but it may overflow when converted to Hz. In this case, tsc-frequency returns a negative value because x86_cpuid_get_tsc_freq does a 32-bit multiplication before assigning to int64_t.

For simplicity just make tsc_khz a 64-bit value.

Spotted by Coverity.

---
 target-i386/cpu.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target-i386/cpu.h +1 -1
index 603aaf0..2125049 100644
@@ -958,7 +958,7 @@ typedef struct CPUX86State {
     uint8_t has_error_code;
     uint32_t sipi_vector;
     bool tsc_valid;
-    int tsc_khz;
+    int64_t tsc_khz;
     void *kvm_xsave_buf;
 
     uint64_t mcg_cap;
Signature · 1 line
2.4.3
Reviewed-by on v1 1/1 Applied
#1 lore raw
Quoted 10 lines · Paolo Bonzini

The TSC frequency fits comfortably in an int when expressed in kHz, but it may overflow when converted to Hz. In this case, tsc-frequency returns a negative value because x86_cpuid_get_tsc_freq does a 32-bit multiplication before assigning to int64_t.

For simplicity just make tsc_khz a 64-bit value.

Spotted by Coverity.

Applied to the x86 tree. Thanks!

Signature · 1 line
Eduardo