Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: sashiko-reviews@lists.linux.dev
Cc: Priyanka Mani <priyankamani2100@gmail.com>, kvm@vger.kernel.org
Subject: Re: [PATCH] KVM: nSVM: Check full nested state size before writing to user buffer
Date: Thu, 12 Nov 2026 08:42:16 -0800	[thread overview]
Message-ID: <avXsaIGjGotdeJiR@google.com> (raw)
In-Reply-To: <sashiko-outbox-210535@kernel.org>

On Thu, Nov 12, 2026, sashiko-bot@kernel.org wrote:
> [Severity: High]
> This problem wasn't introduced by this patch, but in the paired setter
> svm_set_nested_state() [1], does a failed nested_svm_load_cr3()
> leave the vCPU in guest mode with an active nested MMU context?
> 
> arch/x86/kvm/svm/nested.c:svm_set_nested_state() {
>     ...
> 	nested_vmcb02_prepare_control(svm);
>     ...
> 	ret = nested_svm_load_cr3(&svm->vcpu, vcpu->arch.cr3,
> 				  nested_npt_enabled(svm), false);
> 	if (ret)
> 		goto out_free;
>     ...
> }
> 
> nested_vmcb02_prepare_control() enters guest mode and initializes the
> nested MMU context, but the out_free error path only frees save and ctl
> without calling leave_guest_mode() or nested_svm_uninit_mmu_context().
> If userspace passes an invalid guest CR3 and then continues running the
> vCPU after KVM_SET_NESTED_STATE fails, the vCPU runs with a corrupted
> nested state and leaked MMU state.

Ya, I have this locally, just need to write a changelog and get it posted:

diff --git arch/x86/kvm/svm/nested.c arch/x86/kvm/svm/nested.c
index 07554089ec05..4b1cdc7798bb 100644
--- arch/x86/kvm/svm/nested.c
+++ arch/x86/kvm/svm/nested.c
@@ -2114,8 +2114,10 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu,
         */
        ret = nested_svm_load_cr3(&svm->vcpu, vcpu->arch.cr3,
                                  nested_npt_enabled(svm), false);
-       if (ret)
+       if (ret) {
+               svm_leave_nested(vcpu);
                goto out_free;
+       }
 
        svm->nested.force_msr_bitmap_recalc = true;

  reply	other threads:[~2026-11-12 16:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12  6:41 [PATCH] KVM: nSVM: Check full nested state size before writing to user buffer Priyanka Mani
2026-11-12  6:48 ` sashiko-bot
2026-11-12 16:42   ` Sean Christopherson [this message]
2026-11-12 11:48 ` Dan Carpenter
2026-11-12 16:44   ` Sean Christopherson

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=avXsaIGjGotdeJiR@google.com \
    --to=seanjc@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=priyankamani2100@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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