diff mbox series

[next] KVM: x86: Fix bit shifting in update_intel_pt_cfg

Message ID 20181226204059.GA11391@embeddedor (mailing list archive)
State New, archived
Headers show
Series [next] KVM: x86: Fix bit shifting in update_intel_pt_cfg | expand

Commit Message

Gustavo A. R. Silva Dec. 26, 2018, 8:40 p.m. UTC
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")
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
 arch/x86/kvm/vmx/vmx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Wei Yang Dec. 27, 2018, 3:35 a.m. UTC | #1
On Wed, Dec 26, 2018 at 02:40:59PM -0600, Gustavo A. R. Silva wrote:
>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")
>Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>

Looks good.

Reviewed-by: Wei Yang <richardw.yang@linux.intel.com>

>---
> arch/x86/kvm/vmx/vmx.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
>index cbd55e7aeae5..251c68a74bbe 100644
>--- a/arch/x86/kvm/vmx/vmx.c
>+++ b/arch/x86/kvm/vmx/vmx.c
>@@ -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)
>-- 
>2.20.1
Luwei Kang Dec. 28, 2018, 7:58 a.m. UTC | #2
> -----Original Message-----
> From: Gustavo A. R. Silva [mailto:gustavo@embeddedor.com]
> Sent: Thursday, December 27, 2018 4:41 AM
> To: Kang, Luwei <luwei.kang@intel.com>; Paolo Bonzini <pbonzini@redhat.com>; Radim Krčmář <rkrcmar@redhat.com>; Thomas Gleixner
> <tglx@linutronix.de>; Ingo Molnar <mingo@redhat.com>; Borislav Petkov <bp@alien8.de>; H. Peter Anvin <hpa@zytor.com>;
> x86@kernel.org
> Cc: kvm@vger.kernel.org; linux-kernel@vger.kernel.org; Gustavo A. R. Silva <gustavo@embeddedor.com>
> 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")
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> ---
>  arch/x86/kvm/vmx/vmx.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index cbd55e7aeae5..251c68a74bbe 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -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.

Reviewed-by: Luwei Kang <luwei.kang@intel.com>

> 
>  static void vmx_cpuid_update(struct kvm_vcpu *vcpu)
> --
> 2.20.1
Radim Krčmář Jan. 11, 2019, 1:39 p.m. UTC | #3
2018-12-26 14:40-0600, 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")
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> ---

Applied, thanks.
diff mbox series

Patch

diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index cbd55e7aeae5..251c68a74bbe 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -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)