Skip to contentSkip to conversation

KVM: x86: Fix bit shifting in update_intel_pt_cfg

PATCH Applied Gustavo A. R. Silva 4 participants 4 messages Dec 26, 2018 – Jan 11, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: x86: Fix bit shifting in update_intel_pt_cfg

ctl_bitmask in pt_desc is of type u64. When an integer like 0xf is being left shifted more than 32 bits, the behavior is undefined.

Fix this by adding suffix ULL to integer 0xf.

Addresses-Coverity-ID: 1476095 ("Bad bit shift operation")

Fixes 6c0f0bba85a0 ("KVM: x86: Introduce a function to initialize the PT configuration")
---
 arch/x86/kvm/vmx/vmx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/vmx/vmx.c +1 -1
index cbd55e7aeae5..251c68a74bbe 100644
@@ -7012,7 +7012,7 @@ static void update_intel_pt_cfg(struct kvm_vcpu *vcpu)
 
 	/* unmask address range configure area */
 	for (i = 0; i < vmx->pt_desc.addr_range; i++)
-		vmx->pt_desc.ctl_bitmask &= ~(0xf << (32 + i * 4));
+		vmx->pt_desc.ctl_bitmask &= ~(0xfULL << (32 + i * 4));
 }
 
 static void vmx_cpuid_update(struct kvm_vcpu *vcpu)
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Gustavo A. R. Silva

ctl_bitmask in pt_desc is of type u64. When an integer like 0xf is being left shifted more than 32 bits, the behavior is undefined.

Fix this by adding suffix ULL to integer 0xf.

Addresses-Coverity-ID: 1476095 ("Bad bit shift operation")

Fixes 6c0f0bba85a0 ("KVM: x86: Introduce a function to initialize the PT configuration")

Looks good.

Quoted 19 lines

---
arch/x86/kvm/vmx/vmx.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/vmx/vmx.c +1 -1
index cbd55e7aeae5..251c68a74bbe 100644
@@ -7012,7 +7012,7 @@ static void update_intel_pt_cfg(struct kvm_vcpu *vcpu)
 
 	/* unmask address range configure area */
 	for (i = 0; i < vmx->pt_desc.addr_range; i++)
-		vmx->pt_desc.ctl_bitmask &= ~(0xf << (32 + i * 4));
+		vmx->pt_desc.ctl_bitmask &= ~(0xfULL << (32 + i * 4));
 }
 
 static void vmx_cpuid_update(struct kvm_vcpu *vcpu)
Signature · 1 line
2.20.1
Signature · 2 lines
Wei Yang
Help you, Help me
Reviewed-by on v1 1/1
#2 lore raw
In reply to Gustavo A. R. Silva
Quoted 26 lines

-----Original Message-----
From: Gustavo A. R. Silva [mailto:[email protected]]
Sent: Thursday, December 27, 2018 4:41 AM
To: Kang, Luwei <[email protected]>; Paolo Bonzini <[email protected]>; Radim Krčmář <[email protected]>; Thomas Gleixner <[email protected]>; Ingo Molnar <[email protected]>; Borislav Petkov <[email protected]>; H. Peter Anvin <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; Gustavo A. R. Silva <[email protected]>
Subject: [PATCH][next] KVM: x86: Fix bit shifting in update_intel_pt_cfg

ctl_bitmask in pt_desc is of type u64. When an integer like 0xf is being left shifted more than 32 bits, the behavior is undefined.

Fix this by adding suffix ULL to integer 0xf.

Addresses-Coverity-ID: 1476095 ("Bad bit shift operation")

Fixes 6c0f0bba85a0 ("KVM: x86: Introduce a function to initialize the PT configuration")
---
 arch/x86/kvm/vmx/vmx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

arch/x86/kvm/vmx/vmx.c static void update_intel_pt_cfg(struct kvm_vcpu *vcpu) · line 7016

Quoted 6 lines
arch/x86/kvm/vmx/vmx.c +1 -1
@@ -7012,7 +7012,7 @@ static void update_intel_pt_cfg(struct kvm_vcpu *vcpu)
 
 	/* unmask address range configure area */
 	for (i = 0; i < vmx->pt_desc.addr_range; i++)
-		vmx->pt_desc.ctl_bitmask &= ~(0xf << (32 + i * 4));
+		vmx->pt_desc.ctl_bitmask &= ~(0xfULL << (32 + i * 4));
 }

Looks good to me, thanks.

Quoted 4 lines
arch/x86/kvm/vmx/vmx.c +0 -1
 static void vmx_cpuid_update(struct kvm_vcpu *vcpu)
--

2.20.1

#3 lore raw
In reply to Gustavo A. R. Silva

2018-12-26 14:40-0600, Gustavo A. R. Silva:

Quoted 9 lines

ctl_bitmask in pt_desc is of type u64. When an integer like 0xf is being left shifted more than 32 bits, the behavior is undefined.

Fix this by adding suffix ULL to integer 0xf.

Addresses-Coverity-ID: 1476095 ("Bad bit shift operation")

Fixes 6c0f0bba85a0 ("KVM: x86: Introduce a function to initialize the PT configuration")

---

Applied, thanks.