linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: VMX: Fix a TSX_CTRL_CPUID_CLEAR field mask issue
@ 2021-09-06  1:43 Zhenzhong Duan
  2021-09-08  0:07 ` Sean Christopherson
  0 siblings, 1 reply; 3+ messages in thread
From: Zhenzhong Duan @ 2021-09-06  1:43 UTC (permalink / raw)
  To: kvm
  Cc: linux-kernel, pbonzini, vkuznets, wanpengli, jmattson, joro,
	Zhenzhong Duan

Host value of TSX_CTRL_CPUID_CLEAR field should be unchangable by guest,
but the mask for this purpose is set to a wrong value. So it doesn't
take effect.

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>
---
 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 927a552393b9..36588b5feee6 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -6812,7 +6812,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] 3+ messages in thread

* Re: [PATCH] KVM: VMX: Fix a TSX_CTRL_CPUID_CLEAR field mask issue
  2021-09-06  1:43 [PATCH] KVM: VMX: Fix a TSX_CTRL_CPUID_CLEAR field mask issue Zhenzhong Duan
@ 2021-09-08  0:07 ` Sean Christopherson
  2021-09-26  1:43   ` Duan, Zhenzhong
  0 siblings, 1 reply; 3+ messages in thread
From: Sean Christopherson @ 2021-09-08  0:07 UTC (permalink / raw)
  To: Zhenzhong Duan
  Cc: kvm, linux-kernel, pbonzini, vkuznets, wanpengli, jmattson, joro

On Mon, Sep 06, 2021, Zhenzhong Duan wrote:
> Host value of TSX_CTRL_CPUID_CLEAR field should be unchangable by guest,
> but the mask for this purpose is set to a wrong value. So it doesn't
> take effect.

It would be helpful to provide a bit more info as to just how bad/boneheaded this
bug is.  E.g.

  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.   

> Fixes: 8ea8b8d6f869 ("KVM: VMX: Use common x86's uret MSR list as the one true list")

Cc: stable@vger.kernel.org

> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@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 927a552393b9..36588b5feee6 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -6812,7 +6812,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;

Egad, that's a horrific oversight on my part.

Reviewed-by: Sean Christopherson <seanjc@google.com>

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

* RE: [PATCH] KVM: VMX: Fix a TSX_CTRL_CPUID_CLEAR field mask issue
  2021-09-08  0:07 ` Sean Christopherson
@ 2021-09-26  1:43   ` Duan, Zhenzhong
  0 siblings, 0 replies; 3+ messages in thread
From: Duan, Zhenzhong @ 2021-09-26  1:43 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: kvm, linux-kernel, pbonzini, vkuznets, wanpengli, jmattson, joro

>-----Original Message-----
>From: Sean Christopherson <seanjc@google.com>
>Sent: Wednesday, September 8, 2021 8:08 AM
>To: Duan, Zhenzhong <zhenzhong.duan@intel.com>
>Cc: kvm@vger.kernel.org; linux-kernel@vger.kernel.org;
>pbonzini@redhat.com; vkuznets@redhat.com; wanpengli@tencent.com;
>jmattson@google.com; joro@8bytes.org
>Subject: Re: [PATCH] KVM: VMX: Fix a TSX_CTRL_CPUID_CLEAR field mask
>issue
>
>On Mon, Sep 06, 2021, Zhenzhong Duan wrote:
>> Host value of TSX_CTRL_CPUID_CLEAR field should be unchangable by
>> guest, but the mask for this purpose is set to a wrong value. So it
>> doesn't take effect.
>
>It would be helpful to provide a bit more info as to just how bad/boneheaded
>this bug is.  E.g.
>
>  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.
Sorry for late response, I missed this mail by a wrong mail rule.
Your comment is more clear, I'll use it in v2.

Thanks
Zhenzhong

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

end of thread, other threads:[~2021-09-26  1:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-06  1:43 [PATCH] KVM: VMX: Fix a TSX_CTRL_CPUID_CLEAR field mask issue Zhenzhong Duan
2021-09-08  0:07 ` Sean Christopherson
2021-09-26  1:43   ` Duan, Zhenzhong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).