From: sashiko-bot@kernel.org
To: "Sean Christopherson" <seanjc@google.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH 2/2] KVM: nVMX: Don't use vmcs01.GUEST_CR3 to snapshot L1's CR3 when EPT is disabled
Date: Wed, 03 Jun 2026 22:50:12 +0000 [thread overview]
Message-ID: <20260603225013.99E151F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260603223418.1720035-3-seanjc@google.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Reading `vcpu->arch.cr3` directly captures a stale CR3 value when EPT is enabled, corrupting L1's CR3 on late VM-Fail.
--
commit bc5d55e01f501ccb793937fda67ddf44633f6fda
Author: Sean Christopherson <seanjc@google.com>
KVM: nVMX: Don't use vmcs01.GUEST_CR3 to snapshot L1's CR3 when EPT is disabled
This commit adds a dedicated field in struct nested_vmx to track L1's
pre-VM-Enter CR3, avoiding the use of vmcs01.GUEST_CR3. It also modifies
nested_vmx_enter_non_root_mode() to save the CR3 value, and
nested_vmx_restore_host_state() to restore it.
> diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> --- a/arch/x86/kvm/vmx/nested.c
> +++ b/arch/x86/kvm/vmx/nested.c
> @@ -3651,19 +3651,14 @@ enum nvmx_vmentry_status nested_vmx_enter_non_root_mode(struct kvm_vcpu *vcpu,
> &vmx->nested.pre_vmenter_ssp_tbl);
>
> /*
> - * Overwrite vmcs01.GUEST_CR3 with L1's CR3 if EPT is disabled. In the
> - * event of a "late" VM-Fail, i.e. a VM-Fail detected by hardware but
> - * not KVM, KVM must unwind its software model to the pre-VM-Entry host
> - * state. When EPT is disabled, GUEST_CR3 holds KVM's shadow CR3, not
> - * L1's "real" CR3, which causes nested_vmx_restore_host_state() to
> - * corrupt vcpu->arch.cr3. Stuffing vmcs01.GUEST_CR3 results in the
> - * unwind naturally setting arch.cr3 to the correct value. Smashing
> - * vmcs01.GUEST_CR3 is safe because nested VM-Exits, and the unwind,
> - * reset KVM's MMU, i.e. vmcs01.GUEST_CR3 is guaranteed to be
> - * overwritten with a shadow CR3 prior to re-entering L1.
> + * Stash L1's CR3, so that in the event of a "late" VM-Fail, i.e. a
> + * VM-Fail detected by hardware but not KVM, KVM can unwind its
> + * software model to the pre-VM-Entry host state. When EPT is
> + * disabled, GUEST_CR3 holds KVM's shadow CR3, not L1's "real" CR3,
> + * and so simply restoring from vmcs01.GUEST_CR3 would corrupt
> + * vcpu->arch.cr3.
> */
> - if (!enable_ept)
> - vmcs_writel(GUEST_CR3, vcpu->arch.cr3);
> + vmx->nested.pre_vmenter_cr3 = vcpu->arch.cr3;
[Severity: High]
Does directly reading vcpu->arch.cr3 here capture a stale value when EPT is
enabled?
Because KVM does not intercept L1 CR3 writes when EPT is enabled, L1 can
update its CR3 without KVM immediately tracking it. On VM-Exit (such as for
VMLAUNCH), KVM invalidates the CR3 register cache by clearing the
VCPU_REG_CR3 availability bit.
If nested_vmx_enter_non_root_mode() directly assigns vmx->nested.pre_vmenter_cr3
from vcpu->arch.cr3 instead of using kvm_read_cr3(vcpu), it seems this would
bypass the cache refresh and stash a stale CR3 value.
>
> vmx_switch_vmcs(vcpu, &vmx->nested.vmcs02);
>
[ ... ]
> @@ -4975,7 +4970,7 @@ static void nested_vmx_restore_host_state(struct kvm_vcpu *vcpu)
> vmx_set_cr4(vcpu, vmcs_readl(CR4_READ_SHADOW));
>
> nested_ept_uninit_mmu_context(vcpu);
> - vcpu->arch.cr3 = vmcs_readl(GUEST_CR3);
> + vcpu->arch.cr3 = vmx->nested.pre_vmenter_cr3;
[Severity: High]
If pre_vmenter_cr3 stashed a stale value, will restoring it here corrupt L1's
CR3 on a late VM-Fail?
If a late VM-Fail occurs (detected by hardware but not KVM), writing this
potentially stale pre_vmenter_cr3 back into KVM's state (vcpu->arch.cr3) and
marking it as available could cause L1 to resume with an outdated CR3, which
might lead to guest memory corruption or a triple fault.
> kvm_register_mark_available(vcpu, VCPU_REG_CR3);
>
> /*
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260603223418.1720035-1-seanjc@google.com?part=2
next prev parent reply other threads:[~2026-06-03 22:50 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-03 22:34 [PATCH 0/2] KVM: nVMX: Fix ept=n bugs where KVM runs L2 with guest CR3 Sean Christopherson
2026-06-03 22:34 ` [PATCH 1/2] KVM: nVMX: Move vTPR vs. TPR Threshold consistency check into "normal" checks Sean Christopherson
2026-06-03 22:34 ` [PATCH 2/2] KVM: nVMX: Don't use vmcs01.GUEST_CR3 to snapshot L1's CR3 when EPT is disabled Sean Christopherson
2026-06-03 22:50 ` sashiko-bot [this message]
2026-06-03 22:57 ` Sean Christopherson
2026-06-04 6:23 ` [PATCH 0/2] KVM: nVMX: Fix ept=n bugs where KVM runs L2 with guest CR3 Jim Mattson
2026-06-04 13:15 ` Sean Christopherson
2026-06-04 14:13 ` Jim Mattson
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=20260603225013.99E151F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=seanjc@google.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