mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Sean Christopherson <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Karthikeyan Bhargavan <karthik@cryspen.com>,
	Chris Mason <mason@kernel.org>,
	 Amirmohammad Eftekhar <amirmohammad.eftekhar@cispa.de>,
	Josef Bacik <josef@toxicpanda.com>
Subject: [PATCH] KVM: nVMX: Clear nested.smm.guest_mode when freeing nested state
Date: Thu, 22 Oct 2026 12:29:08 -0700	[thread overview]
Message-ID: <20261022192908.554376-1-seanjc@google.com> (raw)

From: Josef Bacik <josef@toxicpanda.com>

If an SMI arrives while L2 is active, vmx_enter_smm() forces a VM-Exit
to L1, and records in nested.smm.guest_mode that RSM has to re-enter L2
and in nested.smm.vmxon that the vCPU was post-VMXON.  free_nested()
clears the latter, but not the former.

Userspace can get KVM to free the nested state while the vCPU is in SMM,
with KVM_SET_NESTED_STATE, e.g. with no VMXON region to say that the
vCPU isn't in VMX operation, or by flipping the SMM flag back and forth
with KVM_SET_VCPU_EVENTS.  When the guest then executes RSM,
vmx_leave_smm() tries to re-enter L2 even though there is no vmcs12 any
more, and nested_vmx_check_restored_vmcs12() dereferences the NULL
nested.cached_vmcs12.

Clear nested.smm.guest_mode along with the state that it refers to.

Fixes: 8fcc4b5923af ("kvm: nVMX: Introduce KVM_CAP_NESTED_STATE")
Reported-by: Karthikeyan Bhargavan <karthik@cryspen.com>
Cc: stable@vger.kernel.org
Assisted-by: LLM
Cc: Chris Mason <mason@kernel.org>
Co-developed-by: Amirmohammad Eftekhar <amirmohammad.eftekhar@cispa.de>
Signed-off-by: Amirmohammad Eftekhar <amirmohammad.eftekhar@cispa.de>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 arch/x86/kvm/vmx/nested.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index 9b0bfa2f854c..66a7b57c9f16 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -349,6 +349,7 @@ static void free_nested(struct kvm_vcpu *vcpu)
 
 	vmx->nested.vmxon = false;
 	vmx->nested.smm.vmxon = false;
+	vmx->nested.smm.guest_mode = false;
 	vmx->nested.vmxon_ptr = INVALID_GPA;
 	free_vpid(vmx->nested.vpid02);
 	vmx->nested.posted_intr_nv = -1;

base-commit: 164405e8e9a0378c7e1aff2254625a6553a291f1
-- 
2.56.0.257.gf7497c7d27-goog


                 reply	other threads:[~2026-10-22 19:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261022192908.554376-1-seanjc@google.com \
    --to=seanjc@google.com \
    --cc=amirmohammad.eftekhar@cispa.de \
    --cc=josef@toxicpanda.com \
    --cc=karthik@cryspen.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mason@kernel.org \
    --cc=pbonzini@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®