All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Zhao Liu" <zhao1.liu@intel.com>
Cc: kvm@vger.kernel.org
Subject: Re: [RFC 1/4] KVM: nVMX: Don't copy L2's CET state to L1 if VM-entry didn't load it
Date: Fri, 04 Sep 2026 02:49:45 +0000	[thread overview]
Message-ID: <20260904024945.F34B81F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260904023105.1167376-2-zhao1.liu@intel.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] KVM fails to propagate L2's modified BNDCFGS and PAT to L1 when VM_EXIT_CLEAR_BNDCFGS or VM_EXIT_LOAD_IA32_PAT is clear.
--

commit cf134f2b2249852af5c9f30ff344481f932e8567
Author: Zhao Liu <zhao1.liu@intel.com>

KVM: nVMX: Don't copy L2's CET state to L1 if VM-entry didn't load it

On a nested VM-exit that disables VM_EXIT_LOAD_CET_STATE, only copy L2's
CET state from vmcs12 to vmcs01 if VM-entry really loaded that state,
i.e. don't copy when VM-entry fails before loading guest state.

> diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> index 151873407abd3..35f0bf84b373a 100644
> --- a/arch/x86/kvm/vmx/nested.c
> +++ b/arch/x86/kvm/vmx/nested.c

[ ... ]

> @@ -4856,12 +4902,13 @@ static void load_vmcs12_host_state(struct kvm_vcpu *vcpu,
>  	/*
>  	 * Load CET state from host state if VM_EXIT_LOAD_CET_STATE is set.
>  	 * otherwise CET state should be retained across VM-exit, i.e.,
> -	 * guest values should be propagated from vmcs12 to vmcs01.
> +	 * guest values should be propagated from vmcs12 to vmcs01, but only if
> +	 * L2's CET state is live in hardware.
>  	 */
>  	if (vmcs12->vm_exit_controls & VM_EXIT_LOAD_CET_STATE)
>  		vmcs_write_cet_state(vcpu, vmcs12->host_s_cet, vmcs12->host_ssp,
>  				     vmcs12->host_ssp_tbl);
> -	else
> +	else if (nested_l2_state_is_live(vmcs12, VM_ENTRY_LOAD_CET_STATE, l2_state))
>  		vmcs_write_cet_state(vcpu, vmcs12->guest_s_cet, vmcs12->guest_ssp,
>  				     vmcs12->guest_ssp_tbl);
>  

[Severity: High]
This isn't a bug introduced by this patch, but this pre-existing logic error
applies to BNDCFGS and PAT in arch/x86/kvm/vmx/nested.c:load_vmcs12_host_state()
as well.

If VM_EXIT_CLEAR_BNDCFGS is false, KVM skips updating vmcs01's BNDCFGS:

    /* If not VM_EXIT_CLEAR_BNDCFGS, the L2 value propagates to L1.  */
    if (vmcs12->vm_exit_controls & VM_EXIT_CLEAR_BNDCFGS)
        vmcs_write64(GUEST_BNDCFGS, 0);

This causes L1 to incorrectly resume with its original state rather than
retaining L2's modified state.

Similarly, if VM_EXIT_LOAD_IA32_PAT is false, KVM skips updating vmcs01's PAT:

    if (vmcs12->vm_exit_controls & VM_EXIT_LOAD_IA32_PAT) {
        vmcs_write64(GUEST_IA32_PAT, vmcs12->host_ia32_pat);
        vcpu->arch.pat = vmcs12->host_ia32_pat;
    }

This causes L1 to incorrectly resume with its original PAT instead of retaining
L2's modified state.

In both cases, a malicious or buggy L1 hypervisor that disables these VM-exit
controls could cause L1 to resume with the wrong state (its pre-VMENTRY state
instead of L2's state). This breaks the architectural guarantee of state
preservation on VM-exit and leads to guest hypervisor state corruption.

Should we also propagate L2's modified BNDCFGS and PAT to vmcs01 when these
controls are clear, perhaps reusing the new nested_l2_state_is_live() logic?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260904023105.1167376-1-zhao1.liu@intel.com?part=1

  reply	other threads:[~2026-09-04  2:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-04  2:31 [RFC 0/4] KVM: nVMX: Fix guest (CET) state handling on VM-entry failure Zhao Liu
2026-09-04  2:31 ` [RFC 1/4] KVM: nVMX: Don't copy L2's CET state to L1 if VM-entry didn't load it Zhao Liu
2026-09-04  2:49   ` sashiko-bot [this message]
2026-09-04 16:42   ` Sean Christopherson
2026-09-07 12:47     ` Zhao Liu
2026-09-04  2:31 ` [RFC 2/4] KVM: selftests: Synchronize and update VMCS controls Zhao Liu
2026-09-04  2:31 ` [RFC 3/4] KVM: selftests: Synchronize and update VMCS encodings Zhao Liu
2026-09-04  2:31 ` [RFC 4/4] KVM: selftests: Test VM-entry failure handling for nested VM Zhao Liu
2026-09-04  2:50   ` sashiko-bot

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=20260904024945.F34B81F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=zhao1.liu@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.