]> git.hungrycats.org Git - linux/commitdiff
KVM: vmx: Inject #GP on invalid PAT CR
authorNadav Amit <namit@cs.technion.ac.il>
Thu, 18 Sep 2014 19:39:44 +0000 (22:39 +0300)
committerBen Hutchings <ben@decadent.org.uk>
Tue, 13 Feb 2018 18:32:17 +0000 (18:32 +0000)
commit 4566654bb9be9e8864df417bb72ceee5136b6a6a upstream.

Guest which sets the PAT CR to invalid value should get a #GP.  Currently, if
vmx supports loading PAT CR during entry, then the value is not checked.  This
patch makes the required check in that case.

Signed-off-by: Nadav Amit <namit@cs.technion.ac.il>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
arch/x86/kvm/vmx.c
arch/x86/kvm/x86.c
arch/x86/kvm/x86.h

index 0b19852e2a32d6d7bd4700b2e5ec60d6ddf335d9..346fac6eab9f049a468a7b89ba0a02d0c47d818c 100644 (file)
@@ -2204,6 +2204,8 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data)
                break;
        case MSR_IA32_CR_PAT:
                if (vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_IA32_PAT) {
+                       if (!kvm_mtrr_valid(vcpu, MSR_IA32_CR_PAT, data))
+                               return 1;
                        vmcs_write64(GUEST_IA32_PAT, data);
                        vcpu->arch.pat = data;
                        break;
index 7e6094b0308b42f3976b5636339e342218b1ef60..29d04a41ee0a9e0a1c29ef1779d3cd541f98f846 100644 (file)
@@ -1274,7 +1274,7 @@ static bool valid_mtrr_type(unsigned t)
        return t < 8 && (1 << t) & 0x73; /* 0, 1, 4, 5, 6 */
 }
 
-static bool mtrr_valid(struct kvm_vcpu *vcpu, u32 msr, u64 data)
+bool kvm_mtrr_valid(struct kvm_vcpu *vcpu, u32 msr, u64 data)
 {
        int i;
 
@@ -1300,12 +1300,13 @@ static bool mtrr_valid(struct kvm_vcpu *vcpu, u32 msr, u64 data)
        /* variable MTRRs */
        return valid_mtrr_type(data & 0xff);
 }
+EXPORT_SYMBOL_GPL(kvm_mtrr_valid);
 
 static int set_msr_mtrr(struct kvm_vcpu *vcpu, u32 msr, u64 data)
 {
        u64 *p = (u64 *)&vcpu->arch.mtrr_state.fixed_ranges;
 
-       if (!mtrr_valid(vcpu, msr, data))
+       if (!kvm_mtrr_valid(vcpu, msr, data))
                return 1;
 
        if (msr == MSR_MTRRdefType) {
index 6c3c94f6379eb9d696636b1406bafb15f1880ae1..10eb76532a461c3bd274a36ee947c6e39a9efdd5 100644 (file)
@@ -135,6 +135,8 @@ int kvm_write_guest_virt_system(struct x86_emulate_ctxt *ctxt,
        gva_t addr, void *val, unsigned int bytes,
        struct x86_exception *exception);
 
+bool kvm_mtrr_valid(struct kvm_vcpu *vcpu, u32 msr, u64 data);
+
 extern unsigned int min_timer_period_us;
 
 #endif