linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: VMX: Set failure code in prepare_vmcs02()
@ 2021-11-30 12:53 Dan Carpenter
  2021-11-30 16:30 ` Paolo Bonzini
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2021-11-30 12:53 UTC (permalink / raw)
  To: Paolo Bonzini, Oliver Upton
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Krish Sadhukhan, Peter Shier,
	kvm, linux-kernel, kernel-janitors

The error paths in the prepare_vmcs02() function are supposed to set
*entry_failure_code but this path does not.  It leads to using an
uninitialized variable in the caller.

Fixes: 71f7347025bf ("KVM: nVMX: Load GUEST_IA32_PERF_GLOBAL_CTRL MSR on VM-Entry")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 arch/x86/kvm/vmx/nested.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index 315fa456d368..f321300883f9 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -2594,8 +2594,10 @@ static int prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,
 
 	if ((vmcs12->vm_entry_controls & VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL) &&
 	    WARN_ON_ONCE(kvm_set_msr(vcpu, MSR_CORE_PERF_GLOBAL_CTRL,
-				     vmcs12->guest_ia32_perf_global_ctrl)))
+				     vmcs12->guest_ia32_perf_global_ctrl))) {
+		*entry_failure_code = ENTRY_FAIL_DEFAULT;
 		return -EINVAL;
+	}
 
 	kvm_rsp_write(vcpu, vmcs12->guest_rsp);
 	kvm_rip_write(vcpu, vmcs12->guest_rip);
-- 
2.20.1


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

* Re: [PATCH] KVM: VMX: Set failure code in prepare_vmcs02()
  2021-11-30 12:53 [PATCH] KVM: VMX: Set failure code in prepare_vmcs02() Dan Carpenter
@ 2021-11-30 16:30 ` Paolo Bonzini
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2021-11-30 16:30 UTC (permalink / raw)
  To: Dan Carpenter, Oliver Upton
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Krish Sadhukhan, Peter Shier,
	kvm, linux-kernel, kernel-janitors

On 11/30/21 13:53, Dan Carpenter wrote:
> The error paths in the prepare_vmcs02() function are supposed to set
> *entry_failure_code but this path does not.  It leads to using an
> uninitialized variable in the caller.
> 
> Fixes: 71f7347025bf ("KVM: nVMX: Load GUEST_IA32_PERF_GLOBAL_CTRL MSR on VM-Entry")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>   arch/x86/kvm/vmx/nested.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> index 315fa456d368..f321300883f9 100644
> --- a/arch/x86/kvm/vmx/nested.c
> +++ b/arch/x86/kvm/vmx/nested.c
> @@ -2594,8 +2594,10 @@ static int prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,
>   
>   	if ((vmcs12->vm_entry_controls & VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL) &&
>   	    WARN_ON_ONCE(kvm_set_msr(vcpu, MSR_CORE_PERF_GLOBAL_CTRL,
> -				     vmcs12->guest_ia32_perf_global_ctrl)))
> +				     vmcs12->guest_ia32_perf_global_ctrl))) {
> +		*entry_failure_code = ENTRY_FAIL_DEFAULT;
>   		return -EINVAL;
> +	}
>   
>   	kvm_rsp_write(vcpu, vmcs12->guest_rsp);
>   	kvm_rip_write(vcpu, vmcs12->guest_rip);
> 

Yeah, I suppose that's the right thing to do (though it really shouldn't 
happen because the value is checked earlier in 
nested_vmx_check_guest_state).

Queued, thanks.

Paolo

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

end of thread, other threads:[~2021-11-30 16:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-30 12:53 [PATCH] KVM: VMX: Set failure code in prepare_vmcs02() Dan Carpenter
2021-11-30 16:30 ` Paolo Bonzini

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).