Skip to contentSkip to conversation

KVM: nVMX: Nullify cached vmcs12 pointers if entering VMX operation fails

PATCH Applied Sean Christopherson 1 participant 2 messages Oct 22 – Nov 13

Subsystems (3)
lore
Share & tools
lore

Sean Christopherson

author maintainer
#0 lore raw

PATCH 1/1 KVM: nVMX: Nullify cached vmcs12 pointers if entering VMX operation fails

From: Amirmohammad Eftekhar <[email protected]>

Nullify the cached vmcs12 pointers after freeing them if "entering" VMX ultimately fails (because of an allocation failure), so that if a stale pointer is consumed, KVM hits a NULL pointer dereference instead of a use-after-free. I.e. crash the host instead of providing a potential guest escape vector if KVM is buggy.

[sean: rework changelog, drop stable@]
---
 arch/x86/kvm/vmx/nested.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/kvm/vmx/nested.c +2 -0
index 9b0bfa2f854c..3509a84acde2 100644
@@ -5463,9 +5463,11 @@ static int enter_vmx_operation(struct kvm_vcpu *vcpu)
 
 out_shadow_vmcs:
 	kfree(vmx->nested.cached_shadow_vmcs12);
+	vmx->nested.cached_shadow_vmcs12 = NULL;
 
 out_cached_shadow_vmcs12:
 	kfree(vmx->nested.cached_vmcs12);
+	vmx->nested.cached_vmcs12 = NULL;
 
 out_cached_vmcs12:
 	free_loaded_vmcs(&vmx->nested.vmcs02);

base-commit: 164405e8e9a0378c7e1aff2254625a6553a291f1

Signature · 1 line
2.56.0.257.gf7497c7d27-goog
author maintainer Applied
#1 lore raw
Quoted 8 lines · Sean Christopherson

Nullify the cached vmcs12 pointers after freeing them if "entering" VMX ultimately fails (because of an allocation failure), so that if a stale pointer is consumed, KVM hits a NULL pointer dereference instead of a use-after-free. I.e. crash the host instead of providing a potential guest escape vector if KVM is buggy.

[...]

Applied to kvm-x86 vmx, thanks!

[1/1] KVM: nVMX: Nullify cached vmcs12 pointers if entering VMX operation fails

      https://github.com/kvm-x86/linux/commit/7597bc333891

--
https://github.com/kvm-x86/linux/tree/next