All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] KVM: VMX: Fix a TSX_CTRL_CPUID_CLEAR field mask issue
@ 2021-09-26  1:55 Zhenzhong Duan
  2021-09-27 15:25 ` Paolo Bonzini
  0 siblings, 1 reply; 2+ messages in thread
From: Zhenzhong Duan @ 2021-09-26  1:55 UTC (permalink / raw)
  To: kvm
  Cc: linux-kernel, pbonzini, vkuznets, wanpengli, jmattson, joro,
	Zhenzhong Duan, stable, Sean Christopherson

When updating the host's mask for its MSR_IA32_TSX_CTRL user return entry,
clear the mask in the found uret MSR instead of vmx->guest_uret_msrs[i].
Modifying guest_uret_msrs directly is completely broken as 'i' does not
point at the MSR_IA32_TSX_CTRL entry.  In fact, it's guaranteed to be an
out-of-bounds accesses as is always set to kvm_nr_uret_msrs in a prior
loop. By sheer dumb luck, the fallout is limited to "only" failing to
preserve the host's TSX_CTRL_CPUID_CLEAR.  The out-of-bounds access is
benign as it's guaranteed to clear a bit in a guest MSR value, which are
always zero at vCPU creation on both x86-64 and i386.

Cc: stable@vger.kernel.org
Fixes: 8ea8b8d6f869 ("KVM: VMX: Use common x86's uret MSR list as the one true list")
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
Reviewed-by: Sean Christopherson <seanjc@google.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 0c2c0d5ae873..cbf3d33432b9 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -6833,7 +6833,7 @@ static int vmx_create_vcpu(struct kvm_vcpu *vcpu)
 		 */
 		tsx_ctrl = vmx_find_uret_msr(vmx, MSR_IA32_TSX_CTRL);
 		if (tsx_ctrl)
-			vmx->guest_uret_msrs[i].mask = ~(u64)TSX_CTRL_CPUID_CLEAR;
+			tsx_ctrl->mask = ~(u64)TSX_CTRL_CPUID_CLEAR;
 	}
 
 	err = alloc_loaded_vmcs(&vmx->vmcs01);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] KVM: VMX: Fix a TSX_CTRL_CPUID_CLEAR field mask issue
  2021-09-26  1:55 [PATCH v2] KVM: VMX: Fix a TSX_CTRL_CPUID_CLEAR field mask issue Zhenzhong Duan
@ 2021-09-27 15:25 ` Paolo Bonzini
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2021-09-27 15:25 UTC (permalink / raw)
  To: Zhenzhong Duan, kvm
  Cc: linux-kernel, vkuznets, wanpengli, jmattson, joro, stable,
	Sean Christopherson

On 26/09/21 03:55, Zhenzhong Duan wrote:
> When updating the host's mask for its MSR_IA32_TSX_CTRL user return entry,
> clear the mask in the found uret MSR instead of vmx->guest_uret_msrs[i].
> Modifying guest_uret_msrs directly is completely broken as 'i' does not
> point at the MSR_IA32_TSX_CTRL entry.  In fact, it's guaranteed to be an
> out-of-bounds accesses as is always set to kvm_nr_uret_msrs in a prior
> loop. By sheer dumb luck, the fallout is limited to "only" failing to
> preserve the host's TSX_CTRL_CPUID_CLEAR.  The out-of-bounds access is
> benign as it's guaranteed to clear a bit in a guest MSR value, which are
> always zero at vCPU creation on both x86-64 and i386.
> 
> Cc: stable@vger.kernel.org
> Fixes: 8ea8b8d6f869 ("KVM: VMX: Use common x86's uret MSR list as the one true list")
> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
> Reviewed-by: Sean Christopherson <seanjc@google.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 0c2c0d5ae873..cbf3d33432b9 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -6833,7 +6833,7 @@ static int vmx_create_vcpu(struct kvm_vcpu *vcpu)
>   		 */
>   		tsx_ctrl = vmx_find_uret_msr(vmx, MSR_IA32_TSX_CTRL);
>   		if (tsx_ctrl)
> -			vmx->guest_uret_msrs[i].mask = ~(u64)TSX_CTRL_CPUID_CLEAR;
> +			tsx_ctrl->mask = ~(u64)TSX_CTRL_CPUID_CLEAR;
>   	}
>   
>   	err = alloc_loaded_vmcs(&vmx->vmcs01);
> 

Queued, thanks.

Paolo


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-09-27 15:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-26  1:55 [PATCH v2] KVM: VMX: Fix a TSX_CTRL_CPUID_CLEAR field mask issue Zhenzhong Duan
2021-09-27 15:25 ` Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.