target-i386: avoid overflow in the tsc-frequency property
authorPaolo Bonzini <pbonzini@redhat.com>
Wed, 24 Jun 2015 12:11:27 +0000 (14:11 +0200)
committerEduardo Habkost <ehabkost@redhat.com>
Tue, 7 Jul 2015 13:47:16 +0000 (10:47 -0300)
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.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
target-i386/cpu.h

index 0bfe64c5b907ed1ed7a9c98d4a1a4dbbd2338c62..14dced08a7a2d6b8c64b01c2cde052d508b58dee 100644 (file)
@@ -962,7 +962,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;