Skip to content

Commit 5bea512

Browse files
committed
KVM: VMX: check nested state and CR4.VMXE against SMM
VMX cannot be enabled under SMM, check it when CR4 is set and when nested virtualization state is restored. This should fix some WARNs reported by syzkaller, mostly around alloc_shadow_vmcs. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 822f312 commit 5bea512

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

arch/x86/kvm/vmx.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5398,9 +5398,10 @@ static int vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
53985398
* To use VMXON (and later other VMX instructions), a guest
53995399
* must first be able to turn on cr4.VMXE (see handle_vmon()).
54005400
* So basically the check on whether to allow nested VMX
5401-
* is here.
5401+
* is here. We operate under the default treatment of SMM,
5402+
* so VMX cannot be enabled under SMM.
54025403
*/
5403-
if (!nested_vmx_allowed(vcpu))
5404+
if (!nested_vmx_allowed(vcpu) || is_smm(vcpu))
54045405
return 1;
54055406
}
54065407

@@ -13977,6 +13978,14 @@ static int vmx_set_nested_state(struct kvm_vcpu *vcpu,
1397713978
~(KVM_STATE_NESTED_SMM_GUEST_MODE | KVM_STATE_NESTED_SMM_VMXON))
1397813979
return -EINVAL;
1397913980

13981+
/*
13982+
* SMM temporarily disables VMX, so we cannot be in guest mode,
13983+
* nor can VMLAUNCH/VMRESUME be pending. Outside SMM, SMM flags
13984+
* must be zero.
13985+
*/
13986+
if (is_smm(vcpu) ? kvm_state->flags : kvm_state->vmx.smm.flags)
13987+
return -EINVAL;
13988+
1398013989
if ((kvm_state->vmx.smm.flags & KVM_STATE_NESTED_SMM_GUEST_MODE) &&
1398113990
!(kvm_state->vmx.smm.flags & KVM_STATE_NESTED_SMM_VMXON))
1398213991
return -EINVAL;

0 commit comments

Comments
 (0)