Skip to content

Commit 8060b2b

Browse files
gaochaointelsean-jc
authored andcommitted
KVM: nVMX: Add consistency checks for CR0.WP and CR4.CET
Add consistency checks for CR4.CET and CR0.WP in guest-state or host-state area in the VMCS12. This ensures that configurations with CR4.CET set and CR0.WP not set result in VM-entry failure, aligning with architectural behavior. 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-33-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 6258849 commit 8060b2b

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

arch/x86/kvm/vmx/nested.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3110,6 +3110,9 @@ static int nested_vmx_check_host_state(struct kvm_vcpu *vcpu,
31103110
CC(!kvm_vcpu_is_legal_cr3(vcpu, vmcs12->host_cr3)))
31113111
return -EINVAL;
31123112

3113+
if (CC(vmcs12->host_cr4 & X86_CR4_CET && !(vmcs12->host_cr0 & X86_CR0_WP)))
3114+
return -EINVAL;
3115+
31133116
if (CC(is_noncanonical_msr_address(vmcs12->host_ia32_sysenter_esp, vcpu)) ||
31143117
CC(is_noncanonical_msr_address(vmcs12->host_ia32_sysenter_eip, vcpu)))
31153118
return -EINVAL;
@@ -3224,6 +3227,9 @@ static int nested_vmx_check_guest_state(struct kvm_vcpu *vcpu,
32243227
CC(!nested_guest_cr4_valid(vcpu, vmcs12->guest_cr4)))
32253228
return -EINVAL;
32263229

3230+
if (CC(vmcs12->guest_cr4 & X86_CR4_CET && !(vmcs12->guest_cr0 & X86_CR0_WP)))
3231+
return -EINVAL;
3232+
32273233
if ((vmcs12->vm_entry_controls & VM_ENTRY_LOAD_DEBUG_CONTROLS) &&
32283234
(CC(!kvm_dr7_valid(vmcs12->guest_dr7)) ||
32293235
CC(!vmx_is_valid_debugctl(vcpu, vmcs12->guest_ia32_debugctl, false))))

0 commit comments

Comments
 (0)