]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: nSVM: WARN and abort vmcb02 intercepts recalc if vmcb02 isn't active
authorYosry Ahmed <yosry.ahmed@linux.dev>
Wed, 18 Feb 2026 23:09:53 +0000 (15:09 -0800)
committerSean Christopherson <seanjc@google.com>
Thu, 5 Mar 2026 00:08:59 +0000 (16:08 -0800)
WARN and bail early from nested_vmcb02_recalc_intercepts() if vmcb02 isn't
the active/current VMCB, as recalculating intercepts for vmcb01 using logic
intended for merging vmcb12 and vmcb01 intercepts can yield unexpected and
unwanted results.

In addition to hardening against general bugs, this will provide additional
safeguards "if" nested_vmcb02_recalc_intercepts() is invoked directly from
nested_vmcb02_prepare_control().

Signed-off-by: Yosry Ahmed <yosry.ahmed@linux.dev>
[sean: split to separate patch, bail early on "failure"]
Link: https://patch.msgid.link/20260218230958.2877682-4-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/svm/nested.c

index 21ee75d6cdffa389ed53681d80e05d4c2eb9ba22..75e7deef51a52090601ae5893f14ee57bc5024fc 100644 (file)
@@ -128,6 +128,9 @@ void nested_vmcb02_recalc_intercepts(struct vcpu_svm *svm)
        struct vmcb_ctrl_area_cached *g;
        unsigned int i;
 
+       if (WARN_ON_ONCE(svm->vmcb != svm->nested.vmcb02.ptr))
+               return;
+
        vmcb_mark_dirty(svm->vmcb, VMCB_INTERCEPTS);
 
        c = &svm->vmcb->control;