Skip to content

Commit 586ef9d

Browse files
yang-weijiangsean-jc
authored andcommitted
KVM: x86: Add fault checks for guest CR4.CET setting
Check potential faults for CR4.CET setting per Intel SDM requirements. CET can be enabled if and only if CR0.WP == 1, i.e. setting CR4.CET == 1 faults if CR0.WP == 0 and setting CR0.WP == 0 fails if CR4.CET == 1. Signed-off-by: Yang Weijiang <[email protected]> Reviewed-by: Chao Gao <[email protected]> Reviewed-by: Maxim Levitsky <[email protected]> Reviewed-by: Xiaoyao Li <[email protected]> Tested-by: Mathias Krause <[email protected]> Tested-by: John Allen <[email protected]> Tested-by: Rick Edgecombe <[email protected]> Signed-off-by: Chao Gao <[email protected]> Reviewed-by: Binbin Wu <[email protected]> Co-developed-by: Sean Christopherson <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent e44eb58 commit 586ef9d

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

arch/x86/kvm/x86.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,9 @@ int kvm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
11761176
(is_64_bit_mode(vcpu) || kvm_is_cr4_bit_set(vcpu, X86_CR4_PCIDE)))
11771177
return 1;
11781178

1179+
if (!(cr0 & X86_CR0_WP) && kvm_is_cr4_bit_set(vcpu, X86_CR4_CET))
1180+
return 1;
1181+
11791182
kvm_x86_call(set_cr0)(vcpu, cr0);
11801183

11811184
kvm_post_set_cr0(vcpu, old_cr0, cr0);
@@ -1376,6 +1379,9 @@ int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
13761379
return 1;
13771380
}
13781381

1382+
if ((cr4 & X86_CR4_CET) && !kvm_is_cr0_bit_set(vcpu, X86_CR0_WP))
1383+
return 1;
1384+
13791385
kvm_x86_call(set_cr4)(vcpu, cr4);
13801386

13811387
kvm_post_set_cr4(vcpu, old_cr4, cr4);

0 commit comments

Comments
 (0)