KVM: x86: Inject #GP if guest attempts to set unsupported EFER bits
authorSean Christopherson <sean.j.christopherson@intel.com>
Tue, 2 Apr 2019 15:19:16 +0000 (08:19 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 16 Apr 2019 13:39:07 +0000 (15:39 +0200)
EFER.LME and EFER.NX are considered reserved if their respective feature
bits are not advertised to the guest.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/x86.c

index 5d7dcd06d08ab89aa15785eca090dcc22617f1f3..38440316a806c456f21282e484a985927de35cc7 100644 (file)
@@ -1266,6 +1266,13 @@ static bool __kvm_valid_efer(struct kvm_vcpu *vcpu, u64 efer)
        if (efer & EFER_SVME && !guest_cpuid_has(vcpu, X86_FEATURE_SVM))
                return false;
 
+       if (efer & (EFER_LME | EFER_LMA) &&
+           !guest_cpuid_has(vcpu, X86_FEATURE_LM))
+               return false;
+
+       if (efer & EFER_NX && !guest_cpuid_has(vcpu, X86_FEATURE_NX))
+               return false;
+
        return true;
 
 }