KVM: nSVM: Add missing CET VMRUN consistency checks
PATCH v2 1/1 KVM: nSVM: Add missing CET VMRUN consistency checks
Per the APM, "Canonicalization and Consistency Checks,"
[t]he following conditions are considered illegal state combinations:
- CR4.CET=1 when CR0.WP=0
- Any reserved bit set in S_CET
- CR4.CET=1 and U_CET.SS=1 when EFLAGS.VM=1
Check these conditions in software before trying to VMRUN vmcb02, so that the illegal states result in a #VMEXIT to L1 rather than an exit to userspace with KVM_EXIT_FAIL_ENTRY.
Fixes c5ba49458513 ("KVM: nSVM: Save/load CET Shadow Stack state to/from vmcb12/vmcb02")
Signed-off-by Jim Mattson <[email protected]>
---
v1 -> v2:
- Warn and fail VMRUN if reading MSR_IA32_U_CET fails [Yosry]
v1: https://lore.kernel.org/all/[email protected]/
arch/x86/kvm/svm/nested.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
arch/x86/kvm/svm/nested.c +15 -0
@@ -469,6 +469,21 @@ static bool nested_vmcb_check_save(struct kvm_vcpu *vcpu,if (CC (!__kvm_is_valid_cr4 (vcpu, save->cr4)))return false; +if (CC ((save->cr4 &X86_CR4_CET ) && !(save->cr0 &X86_CR0_WP ))) +return false; + +if (guest_cpu_cap_has (vcpu,X86_FEATURE_SHSTK ) && +CC (!kvm_is_valid_u_s_cet (vcpu, save->s_cet))) +return false; + +if ((save->cr4 &X86_CR4_CET ) && (save->rflags &X86_EFLAGS_VM )) { +u64 u_cet =0 ; + +if (WARN_ON_ONCE (__kvm_emulate_msr_read (vcpu,MSR_IA32_U_CET , &u_cet)) || +CC (u_cet &CET_SHSTK_EN )) +return false; + } +if (CC (!kvm_valid_efer (vcpu, save->efer)))return false;
Signature · 1 line
2.56.0.567.gdb80ae8cd5-goog