]> 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)
committerJiri Slaby <jslaby@suse.cz>
Mon, 16 Feb 2015 13:45:36 +0000 (14:45 +0100)
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: Bruce Rogers <brogers@suse.com>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
arch/x86/kvm/vmx.c
arch/x86/kvm/x86.c
arch/x86/kvm/x86.h

index 4530a72510b22285f3784d3d117ea347ba849556..f5ddacc4c8852855d436ceb8f9a084ae07f58b5e 100644 (file)
@@ -2520,6 +2520,8 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
                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 790551bc4f158aa084c97d4ce78a678a4dd08589..fabb62bad47c60423381dfac38794e4a1e9a58a2 100644 (file)
@@ -1707,7 +1707,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;
 
@@ -1733,12 +1733,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 7626d3efa064f5dc8df5826d373d2d69b321c9a7..e2968a500c4e093fe1d32ccb0be11f31566a6762 100644 (file)
@@ -132,6 +132,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 u64 host_xcr0;
 
 extern unsigned int min_timer_period_us;