Skip to contentSkip to conversation

KVM: VMX: Set failure code in prepare_vmcs02()

PATCH Applied Dan Carpenter 2 participants 2 messages Nov 30, 2021

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

PATCH 1/1 KVM: VMX: Set failure code in prepare_vmcs02()

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")
---
 arch/x86/kvm/vmx/nested.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/kvm/vmx/nested.c +3 -1
index 315fa456d368..f321300883f9 100644
@@ -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);
Signature · 1 line
2.20.1
maintainer Applied
#1 lore raw
Quoted 17 lines · Dan Carpenter

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")
---
  arch/x86/kvm/vmx/nested.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/kvm/vmx/nested.c +0 -0
index 315fa456d368..f321300883f9 100644
@@ -2594,8 +2594,10 @@ static int prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,
 

arch/x86/kvm/vmx/nested.c static int prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12, · line 2603

Quoted 10 lines
arch/x86/kvm/vmx/nested.c +3 -1
  	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