Kernel KVM virtualization development
 help / color / mirror / Atom feed
* [PATCH 0/3] KVM: nVMX: Add missing guest-state checks on nested VM-Enter
@ 2026-12-03  5:34 Zihui Guo
  2026-12-03  5:34 ` [PATCH 1/3] KVM: nVMX: Check that the guest's IA32_S_CET is canonical on VM-Enter Zihui Guo
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Zihui Guo @ 2026-12-03  5:34 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini; +Cc: Chao Gao, Binbin Wu, kvm, linux-kernel

Three guest-state checks from SDM Vol. 3C (rev. 093) 29.3.1 are missing
from nested_vmx_check_guest_state().

Patch 1 adds the canonical check of the guest's IA32_S_CET. The CET
consistency checks were meant to cover it but treat S_CET like SSP. The
hardware still checks the value on VM-Enter of vmcs02, since KVM loads
it unchanged, so this only moves the failure to the consistency checks.

Patches 2 and 3 add the HLT checks: SS.DPL must be 0, and only some
events may be injected. Here the hardware cannot help, because KVM
emulates the HLT state of L2 and never loads vmcs12's activity state
into vmcs02, so L1 currently gets a successful VM-Enter where the
architecture requires a VM-Entry failure. The injected-event check is
the TODO suggested in [1]. The v3 series [2] adds other activity-state
checks to the same function, so these patches may need a trivial rebase
on top of it. A 2019 patch [3] had similar HLT checks and was not
merged.

All three are compile-tested only (x86_64 defconfig with KVM_INTEL, W=1,
no warnings). No machine with VMX was available, so none of them was
run, and there are no kvm-unit-tests for these cases yet.

Assisted-by: Claude:claude-opus-5-5

[1] https://lore.kernel.org/all/atqDVkHjdJ2iF9Uv@google.com/
[2] https://lore.kernel.org/all/20261022215146.233479-1-amirmohammad.eftekhar@cispa.de/
[3] https://lore.kernel.org/all/20190819214650.41991-3-nikita.leshchenko@oracle.com/

Zihui Guo (3):
  KVM: nVMX: Check that the guest's IA32_S_CET is canonical on VM-Enter
  KVM: nVMX: Reject nested VM-Enter to HLT with a non-zero SS.DPL
  KVM: nVMX: Check the event injected into the HLT state on nested
    VM-Enter

 arch/x86/kvm/vmx/nested.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)


base-commit: cbe54fc3462b3949ab27b9ae81fb9ddb509040c7
-- 
2.43.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] KVM: nVMX: Check that the guest's IA32_S_CET is canonical on VM-Enter
  2026-12-03  5:34 [PATCH 0/3] KVM: nVMX: Add missing guest-state checks on nested VM-Enter Zihui Guo
@ 2026-12-03  5:34 ` Zihui Guo
  2026-12-03  5:54   ` sashiko-bot
  2026-12-03  5:34 ` [PATCH 2/3] KVM: nVMX: Reject nested VM-Enter to HLT with a non-zero SS.DPL Zihui Guo
  2026-12-03  5:34 ` [PATCH 3/3] KVM: nVMX: Check the event injected into the HLT state on nested VM-Enter Zihui Guo
  2 siblings, 1 reply; 7+ messages in thread
From: Zihui Guo @ 2026-12-03  5:34 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini; +Cc: Chao Gao, Binbin Wu, kvm, linux-kernel

SDM Vol. 3C 29.3.1.1 says: "If the 'load CET state' VM-entry control
is 1, the IA32_S_CET field and the IA32_INTERRUPT_SSP_TABLE_ADDR field
must contain canonical addresses."

The nested consistency checks were meant to cover all CET checks of
VM-Enter, but treat the guest's IA32_S_CET like SSP, for which only
bits 63:N must be identical. IA32_S_CET has no such relaxation. With
IBT enumerated to L1, bits 63:10 of the field are not reserved, so a
non-canonical value such as 0x0000800000000000 passes
nested_vmx_check_guest_state() and is left to the hardware VM-Enter of
vmcs02.

Check it next to the SSP check.

Fixes: 62f7533a6b3a ("KVM: nVMX: Add consistency checks for CET states")
Signed-off-by: Zihui Guo <youzih27@gmail.com>
---
 arch/x86/kvm/vmx/nested.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index 1a98f28651f7..92397516885d 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -3384,6 +3384,10 @@ static int nested_vmx_check_guest_state(struct kvm_vcpu *vcpu,
 		 */
 		if (CC(!__is_canonical_address(vmcs12->guest_ssp, max_host_virt_addr_bits() + 1)))
 			return -EINVAL;
+
+		/* Unlike SSP, IA32_S_CET must be canonical (SDM 29.3.1.1). */
+		if (CC(is_noncanonical_msr_address(vmcs12->guest_s_cet, vcpu)))
+			return -EINVAL;
 	}
 
 	if (nested_check_guest_non_reg_state(vmcs12))
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] KVM: nVMX: Reject nested VM-Enter to HLT with a non-zero SS.DPL
  2026-12-03  5:34 [PATCH 0/3] KVM: nVMX: Add missing guest-state checks on nested VM-Enter Zihui Guo
  2026-12-03  5:34 ` [PATCH 1/3] KVM: nVMX: Check that the guest's IA32_S_CET is canonical on VM-Enter Zihui Guo
@ 2026-12-03  5:34 ` Zihui Guo
  2026-12-03  5:34 ` [PATCH 3/3] KVM: nVMX: Check the event injected into the HLT state on nested VM-Enter Zihui Guo
  2 siblings, 0 replies; 7+ messages in thread
From: Zihui Guo @ 2026-12-03  5:34 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini; +Cc: Chao Gao, Binbin Wu, kvm, linux-kernel

SDM Vol. 3C 29.3.1.5: "The activity-state field must not indicate the
HLT state if the DPL (bits 6:5) in the access-rights field for SS is not
0."

nested_check_guest_non_reg_state() only checks the range of the
activity state. The hardware cannot catch this either, because KVM
emulates the HLT state of L2 and never loads vmcs12's activity state
into vmcs02, so L1 gets a successful VM-Enter where the architecture
requires a VM-Entry failure due to invalid guest state.

Fixes: 6dfacadd5858 ("KVM: nVMX: Add support for activity state HLT")
Signed-off-by: Zihui Guo <youzih27@gmail.com>
---
 arch/x86/kvm/vmx/nested.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index 92397516885d..82618f74d4ad 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -3288,6 +3288,10 @@ static int nested_check_guest_non_reg_state(struct vmcs12 *vmcs12)
 	       vmcs12->guest_activity_state != GUEST_ACTIVITY_WAIT_SIPI))
 		return -EINVAL;
 
+	if (CC(vmcs12->guest_activity_state == GUEST_ACTIVITY_HLT &&
+	       VMX_AR_DPL(vmcs12->guest_ss_ar_bytes) != 0))
+		return -EINVAL;
+
 	return 0;
 }
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] KVM: nVMX: Check the event injected into the HLT state on nested VM-Enter
  2026-12-03  5:34 [PATCH 0/3] KVM: nVMX: Add missing guest-state checks on nested VM-Enter Zihui Guo
  2026-12-03  5:34 ` [PATCH 1/3] KVM: nVMX: Check that the guest's IA32_S_CET is canonical on VM-Enter Zihui Guo
  2026-12-03  5:34 ` [PATCH 2/3] KVM: nVMX: Reject nested VM-Enter to HLT with a non-zero SS.DPL Zihui Guo
@ 2026-12-03  5:34 ` Zihui Guo
  2026-12-03  5:55   ` sashiko-bot
  2 siblings, 1 reply; 7+ messages in thread
From: Zihui Guo @ 2026-12-03  5:34 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini; +Cc: Chao Gao, Binbin Wu, kvm, linux-kernel

SDM Vol. 3C 29.3.1.5 allows only these injected events when the
activity state is HLT: an external interrupt, an NMI, a #DB or #MC
hardware exception, and the pending MTF VM exit (other event, vector
0). KVM does not check this, and as with the SS.DPL check the hardware
never sees vmcs12's activity state, so L1 can inject, for example, a #GP
into an L2 that is in the HLT state and get a successful VM-Enter.

Add the check.

Fixes: 6dfacadd5858 ("KVM: nVMX: Add support for activity state HLT")
Signed-off-by: Zihui Guo <youzih27@gmail.com>
---
 arch/x86/kvm/vmx/nested.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index 82618f74d4ad..2712648915a9 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -3281,6 +3281,24 @@ static int nested_vmx_check_vmcs_link_ptr(struct kvm_vcpu *vcpu,
 /*
  * Checks related to Guest Non-register State
  */
+/* Events that may be injected in the HLT state (SDM 29.3.1.5). */
+static bool nested_hlt_event_allowed(u32 intr_info)
+{
+	u8 vector = intr_info & INTR_INFO_VECTOR_MASK;
+
+	switch (intr_info & INTR_INFO_INTR_TYPE_MASK) {
+	case INTR_TYPE_EXT_INTR:
+	case INTR_TYPE_NMI_INTR:
+		return true;
+	case INTR_TYPE_HARD_EXCEPTION:
+		return vector == DB_VECTOR || vector == MC_VECTOR;
+	case INTR_TYPE_OTHER_EVENT:
+		return vector == 0;
+	default:
+		return false;
+	}
+}
+
 static int nested_check_guest_non_reg_state(struct vmcs12 *vmcs12)
 {
 	if (CC(vmcs12->guest_activity_state != GUEST_ACTIVITY_ACTIVE &&
@@ -3292,6 +3310,11 @@ static int nested_check_guest_non_reg_state(struct vmcs12 *vmcs12)
 	       VMX_AR_DPL(vmcs12->guest_ss_ar_bytes) != 0))
 		return -EINVAL;
 
+	if (CC(vmcs12->guest_activity_state == GUEST_ACTIVITY_HLT &&
+	       (vmcs12->vm_entry_intr_info_field & INTR_INFO_VALID_MASK) &&
+	       !nested_hlt_event_allowed(vmcs12->vm_entry_intr_info_field)))
+		return -EINVAL;
+
 	return 0;
 }
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] KVM: nVMX: Check that the guest's IA32_S_CET is canonical on VM-Enter
  2026-12-03  5:34 ` [PATCH 1/3] KVM: nVMX: Check that the guest's IA32_S_CET is canonical on VM-Enter Zihui Guo
@ 2026-12-03  5:54   ` sashiko-bot
  0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-12-03  5:54 UTC (permalink / raw)
  To: Zihui Guo; +Cc: kvm

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] KVM: nVMX: duplicated IA32_S_CET canonicality check in guest
  state validation
--

commit 9bc88a8b241d767905cd44717c2ac408fdd9a0b3
Author: Zihui Guo <youzih27@gmail.com>

KVM: nVMX: Check that the guest's IA32_S_CET is canonical on VM-Enter

This commit adds a canonicality check for vmcs12->guest_s_cet in
nested_vmx_check_guest_state() when VM_ENTRY_LOAD_CET_STATE is set.

> diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> index 1a98f28651f70..92397516885db 100644
> --- a/arch/x86/kvm/vmx/nested.c
> +++ b/arch/x86/kvm/vmx/nested.c
> @@ -3384,6 +3384,10 @@ static int nested_vmx_check_guest_state(struct kvm_vcpu *vcpu,
>  		 */
>  		if (CC(!__is_canonical_address(vmcs12->guest_ssp, max_host_virt_addr_bits() + 1)))
>  			return -EINVAL;
> +
> +		/* Unlike SSP, IA32_S_CET must be canonical (SDM 29.3.1.1). */
> +		if (CC(is_noncanonical_msr_address(vmcs12->guest_s_cet, vcpu)))
> +			return -EINVAL;
>  	}

[Severity: Low]
Could this canonicality check move into nested_vmx_check_cet_state_common()
instead of duplicating it here and in nested_vmx_check_host_state()?

Now that guest IA32_S_CET must also be canonical, the check applies to both
host and guest state (with !ia32e host state still enforcing host_s_cet >> 32
== 0).  Moving it into nested_vmx_check_cet_state_common() next to ssp_tbl, or
into kvm_is_valid_u_s_cet(), avoids repeating the check in both callers.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203053449.25917-1-youzih27@gmail.com?part=1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] KVM: nVMX: Check the event injected into the HLT state on nested VM-Enter
  2026-12-03  5:34 ` [PATCH 3/3] KVM: nVMX: Check the event injected into the HLT state on nested VM-Enter Zihui Guo
@ 2026-12-03  5:55   ` sashiko-bot
  2026-12-03  6:05     ` Zihui Guo
  0 siblings, 1 reply; 7+ messages in thread
From: sashiko-bot @ 2026-12-03  5:55 UTC (permalink / raw)
  To: Zihui Guo; +Cc: kvm

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] KVM: nVMX: nested_check_guest_non_reg_state() rejects stale
  entry intr info
--

commit 452383a9c0e3395f4748f51dbdcfd8ecc5c17e73
Author: Zihui Guo <youzih27@gmail.com>

KVM: nVMX: Check the event injected into the HLT state on nested VM-Enter

This commit adds a consistency check in nested_check_guest_non_reg_state()
to reject disallowed VM-entry event injections when vmcs12's guest activity
state is HLT.

> diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> index 82618f74d4ad2..2712648915a90 100644
> --- a/arch/x86/kvm/vmx/nested.c
> +++ b/arch/x86/kvm/vmx/nested.c

[ ... ]

> @@ -3292,6 +3310,11 @@ static int nested_check_guest_non_reg_state(struct vmcs12 *vmcs12)
>  	       VMX_AR_DPL(vmcs12->guest_ss_ar_bytes) != 0))
>  		return -EINVAL;
>  
> +	if (CC(vmcs12->guest_activity_state == GUEST_ACTIVITY_HLT &&
> +	       (vmcs12->vm_entry_intr_info_field & INTR_INFO_VALID_MASK) &&
> +	       !nested_hlt_event_allowed(vmcs12->vm_entry_intr_info_field)))
> +		return -EINVAL;

[Severity: High]
Can this reject stale vmcs12->vm_entry_intr_info_field during
KVM_SET_NESTED_STATE when vcpu->arch.nested_run_pending is 0?

If L1 enters an active L2 with CPU_BASED_HLT_EXITING clear and injects an
event disallowed in HLT (such as #PF), vmcs12->vm_entry_intr_info_field
keeps INTR_INFO_VALID_MASK set until prepare_vmcs12() runs on an L2-to-L1
exit.

When L2 later executes HLT, L0 handles it in guest mode with
nested_run_pending cleared.  vmx_get_nested_state() ->
sync_vmcs02_to_vmcs12() then sets guest_activity_state to
GUEST_ACTIVITY_HLT without clearing the stale entry interruption info.

On restore, vmx_set_nested_state() clears nested_run_pending and calls
nested_vmx_check_restored_vmcs12() -> nested_vmx_check_guest_state() ->
nested_check_guest_non_reg_state(), failing live migration with -EINVAL
even though prepare_vmcs02_early() ignores vm_entry_intr_info_field then.

Gating this check on vcpu->arch.nested_run_pending, as
nested_vmx_check_guest_state() does for VM_ENTRY_LOAD_IA32_EFER, avoids
rejecting stale state while still enforcing the check on nested VM-Enter.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203053449.25917-1-youzih27@gmail.com?part=3

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] KVM: nVMX: Check the event injected into the HLT state on nested VM-Enter
  2026-12-03  5:55   ` sashiko-bot
@ 2026-12-03  6:05     ` Zihui Guo
  0 siblings, 0 replies; 7+ messages in thread
From: Zihui Guo @ 2026-12-03  6:05 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini; +Cc: Chao Gao, Binbin Wu, kvm, linux-kernel

Right. vm_entry_intr_info_field keeps its valid bit until the next
nested VM-Exit, so with this patch KVM_SET_NESTED_STATE rejects the
saved state of an L2 that executed HLT after L1 injected a #PF. v2 will
check the injected event only when a nested run is pending, as is done
for the guest's IA32_EFER.

Thanks,
Zihui

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-12-03  6:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03  5:34 [PATCH 0/3] KVM: nVMX: Add missing guest-state checks on nested VM-Enter Zihui Guo
2026-12-03  5:34 ` [PATCH 1/3] KVM: nVMX: Check that the guest's IA32_S_CET is canonical on VM-Enter Zihui Guo
2026-12-03  5:54   ` sashiko-bot
2026-12-03  5:34 ` [PATCH 2/3] KVM: nVMX: Reject nested VM-Enter to HLT with a non-zero SS.DPL Zihui Guo
2026-12-03  5:34 ` [PATCH 3/3] KVM: nVMX: Check the event injected into the HLT state on nested VM-Enter Zihui Guo
2026-12-03  5:55   ` sashiko-bot
2026-12-03  6:05     ` Zihui Guo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox