Skip to content

Commit 62f7533

Browse files
gaochaointelsean-jc
authored andcommitted
KVM: nVMX: Add consistency checks for CET states
Introduce consistency checks for CET states during nested VM-entry. A VMCS contains both guest and host CET states, each comprising the IA32_S_CET MSR, SSP, and IA32_INTERRUPT_SSP_TABLE_ADDR MSR. Various checks are applied to CET states during VM-entry as documented in SDM Vol3 Chapter "VM ENTRIES". Implement all these checks during nested VM-entry to emulate the architectural behavior. In summary, there are three kinds of checks on guest/host CET states during VM-entry: A. Checks applied to both guest states and host states: * The IA32_S_CET field must not set any reserved bits; bits 10 (SUPPRESS) and 11 (TRACKER) cannot both be set. * SSP should not have bits 1:0 set. * The IA32_INTERRUPT_SSP_TABLE_ADDR field must be canonical. B. Checks applied to host states only * IA32_S_CET MSR and SSP must be canonical if the CPU enters 64-bit mode after VM-exit. Otherwise, IA32_S_CET and SSP must have their higher 32 bits cleared. C. Checks applied to guest states only: * IA32_S_CET MSR and SSP are not required to be canonical (i.e., 63:N-1 are identical, where N is the CPU's maximum linear-address width). But, bits 63:N of SSP must be identical. Tested-by: Mathias Krause <minipli@grsecurity.net> Tested-by: John Allen <john.allen@amd.com> Tested-by: Rick Edgecombe <rick.p.edgecombe@intel.com> Signed-off-by: Chao Gao <chao.gao@intel.com> Reviewed-by: Binbin Wu <binbin.wu@linux.intel.com> Link: https://lore.kernel.org/r/20250919223258.1604852-34-seanjc@google.com [sean: have common helper return 0/-EINVAL, not true/false] Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 8060b2b commit 62f7533

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

arch/x86/kvm/vmx/nested.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3100,6 +3100,16 @@ static bool is_l1_noncanonical_address_on_vmexit(u64 la, struct vmcs12 *vmcs12)
31003100
return !__is_canonical_address(la, l1_address_bits_on_exit);
31013101
}
31023102

3103+
static int nested_vmx_check_cet_state_common(struct kvm_vcpu *vcpu, u64 s_cet,
3104+
u64 ssp, u64 ssp_tbl)
3105+
{
3106+
if (CC(!kvm_is_valid_u_s_cet(vcpu, s_cet)) || CC(!IS_ALIGNED(ssp, 4)) ||
3107+
CC(is_noncanonical_msr_address(ssp_tbl, vcpu)))
3108+
return -EINVAL;
3109+
3110+
return 0;
3111+
}
3112+
31033113
static int nested_vmx_check_host_state(struct kvm_vcpu *vcpu,
31043114
struct vmcs12 *vmcs12)
31053115
{
@@ -3169,6 +3179,27 @@ static int nested_vmx_check_host_state(struct kvm_vcpu *vcpu,
31693179
return -EINVAL;
31703180
}
31713181

3182+
if (vmcs12->vm_exit_controls & VM_EXIT_LOAD_CET_STATE) {
3183+
if (nested_vmx_check_cet_state_common(vcpu, vmcs12->host_s_cet,
3184+
vmcs12->host_ssp,
3185+
vmcs12->host_ssp_tbl))
3186+
return -EINVAL;
3187+
3188+
/*
3189+
* IA32_S_CET and SSP must be canonical if the host will
3190+
* enter 64-bit mode after VM-exit; otherwise, higher
3191+
* 32-bits must be all 0s.
3192+
*/
3193+
if (ia32e) {
3194+
if (CC(is_noncanonical_msr_address(vmcs12->host_s_cet, vcpu)) ||
3195+
CC(is_noncanonical_msr_address(vmcs12->host_ssp, vcpu)))
3196+
return -EINVAL;
3197+
} else {
3198+
if (CC(vmcs12->host_s_cet >> 32) || CC(vmcs12->host_ssp >> 32))
3199+
return -EINVAL;
3200+
}
3201+
}
3202+
31723203
return 0;
31733204
}
31743205

@@ -3279,6 +3310,23 @@ static int nested_vmx_check_guest_state(struct kvm_vcpu *vcpu,
32793310
CC((vmcs12->guest_bndcfgs & MSR_IA32_BNDCFGS_RSVD))))
32803311
return -EINVAL;
32813312

3313+
if (vmcs12->vm_entry_controls & VM_ENTRY_LOAD_CET_STATE) {
3314+
if (nested_vmx_check_cet_state_common(vcpu, vmcs12->guest_s_cet,
3315+
vmcs12->guest_ssp,
3316+
vmcs12->guest_ssp_tbl))
3317+
return -EINVAL;
3318+
3319+
/*
3320+
* Guest SSP must have 63:N bits identical, rather than
3321+
* be canonical (i.e., 63:N-1 bits identical), where N is
3322+
* the CPU's maximum linear-address width. Similar to
3323+
* is_noncanonical_msr_address(), use the host's
3324+
* linear-address width.
3325+
*/
3326+
if (CC(!__is_canonical_address(vmcs12->guest_ssp, max_host_virt_addr_bits() + 1)))
3327+
return -EINVAL;
3328+
}
3329+
32823330
if (nested_check_guest_non_reg_state(vmcs12))
32833331
return -EINVAL;
32843332

0 commit comments

Comments
 (0)