Skip to content

Commit 112e660

Browse files
committed
KVM: nVMX: add missing consistency checks for CR0 and CR4
The effective values of the guest CR0 and CR4 registers may differ from those included in the VMCS12. In particular, disabling EPT forces CR4.PAE=1 and disabling unrestricted guest mode forces CR0.PG=CR0.PE=1. Therefore, checks on these bits cannot be delegated to the processor and must be performed by KVM. Reported-by: Reima ISHII <[email protected]> Cc: [email protected] Signed-off-by: Paolo Bonzini <[email protected]>
1 parent bceeedb commit 112e660

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

arch/x86/kvm/vmx/nested.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3022,7 +3022,7 @@ static int nested_vmx_check_guest_state(struct kvm_vcpu *vcpu,
30223022
struct vmcs12 *vmcs12,
30233023
enum vm_entry_failure_code *entry_failure_code)
30243024
{
3025-
bool ia32e;
3025+
bool ia32e = !!(vmcs12->vm_entry_controls & VM_ENTRY_IA32E_MODE);
30263026

30273027
*entry_failure_code = ENTRY_FAIL_DEFAULT;
30283028

@@ -3048,6 +3048,13 @@ static int nested_vmx_check_guest_state(struct kvm_vcpu *vcpu,
30483048
vmcs12->guest_ia32_perf_global_ctrl)))
30493049
return -EINVAL;
30503050

3051+
if (CC((vmcs12->guest_cr0 & (X86_CR0_PG | X86_CR0_PE)) == X86_CR0_PG))
3052+
return -EINVAL;
3053+
3054+
if (CC(ia32e && !(vmcs12->guest_cr4 & X86_CR4_PAE)) ||
3055+
CC(ia32e && !(vmcs12->guest_cr0 & X86_CR0_PG)))
3056+
return -EINVAL;
3057+
30513058
/*
30523059
* If the load IA32_EFER VM-entry control is 1, the following checks
30533060
* are performed on the field for the IA32_EFER MSR:
@@ -3059,7 +3066,6 @@ static int nested_vmx_check_guest_state(struct kvm_vcpu *vcpu,
30593066
*/
30603067
if (to_vmx(vcpu)->nested.nested_run_pending &&
30613068
(vmcs12->vm_entry_controls & VM_ENTRY_LOAD_IA32_EFER)) {
3062-
ia32e = (vmcs12->vm_entry_controls & VM_ENTRY_IA32E_MODE) != 0;
30633069
if (CC(!kvm_valid_efer(vcpu, vmcs12->guest_ia32_efer)) ||
30643070
CC(ia32e != !!(vmcs12->guest_ia32_efer & EFER_LMA)) ||
30653071
CC(((vmcs12->guest_cr0 & X86_CR0_PG) &&

0 commit comments

Comments
 (0)