diff mbox series

[2/4] KVM: x86: nSVM: harden svm_free_nested against freeing vmcb02 while still in use

Message ID 20221020093055.224317-3-mlevitsk@redhat.com (mailing list archive)
State New, archived
Headers show
Series nSVM: fix L0 crash if L2 has shutdown condtion which L1 doesn't intercept | expand

Commit Message

Maxim Levitsky Oct. 20, 2022, 9:30 a.m. UTC
Make sure that KVM uses vmcb01 before freeing nested state,
and warn if that is not the case.

This is a minimal fix for CVE-2022-3344 making the kernel
print a warning instead of a kernel panic.

Cc: stable@vger.kernel.org
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
---
 arch/x86/kvm/svm/nested.c | 3 +++
 1 file changed, 3 insertions(+)
diff mbox series

Patch

diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
index 4c620999d230a5..b02a3a1792f194 100644
--- a/arch/x86/kvm/svm/nested.c
+++ b/arch/x86/kvm/svm/nested.c
@@ -1125,6 +1125,9 @@  void svm_free_nested(struct vcpu_svm *svm)
 	if (!svm->nested.initialized)
 		return;
 
+	if (WARN_ON_ONCE(svm->vmcb != svm->vmcb01.ptr))
+		svm_switch_vmcb(svm, &svm->vmcb01);
+
 	svm_vcpu_free_msrpm(svm->nested.msrpm);
 	svm->nested.msrpm = NULL;