[PATCH v2 3/8] KVM: nSVM: WARN and abort vmcb02 intercepts recalc if vmcb02 isn't active

From: Sean Christopherson

Date: Wed Feb 18 2026 - 18:11:26 EST


From: Yosry Ahmed <yosry.ahmed@xxxxxxxxx>

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@xxxxxxxxx>
[sean: split to separate patch, bail early on "failure"]
Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
---
arch/x86/kvm/svm/nested.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
index 48b60dd6e7a3..793f5d2eed3a 100644
--- a/arch/x86/kvm/svm/nested.c
+++ b/arch/x86/kvm/svm/nested.c
@@ -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;
--
2.53.0.345.g96ddfc5eaa-goog