Commit 9a428805 authored by Nadav Amit's avatar Nadav Amit Committed by Jiri Slaby

KVM: vmx: Inject #GP on invalid PAT CR

commit 4566654b 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: default avatarNadav Amit <namit@cs.technion.ac.il>
Signed-off-by: default avatarBruce Rogers <brogers@suse.com>
Signed-off-by: default avatarJiri Slaby <jslaby@suse.cz>
parent a9638450
...@@ -2520,6 +2520,8 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) ...@@ -2520,6 +2520,8 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
break; break;
case MSR_IA32_CR_PAT: case MSR_IA32_CR_PAT:
if (vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_IA32_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); vmcs_write64(GUEST_IA32_PAT, data);
vcpu->arch.pat = data; vcpu->arch.pat = data;
break; break;
......
...@@ -1707,7 +1707,7 @@ static bool valid_mtrr_type(unsigned t) ...@@ -1707,7 +1707,7 @@ static bool valid_mtrr_type(unsigned t)
return t < 8 && (1 << t) & 0x73; /* 0, 1, 4, 5, 6 */ 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; int i;
...@@ -1733,12 +1733,13 @@ static bool mtrr_valid(struct kvm_vcpu *vcpu, u32 msr, u64 data) ...@@ -1733,12 +1733,13 @@ static bool mtrr_valid(struct kvm_vcpu *vcpu, u32 msr, u64 data)
/* variable MTRRs */ /* variable MTRRs */
return valid_mtrr_type(data & 0xff); 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) static int set_msr_mtrr(struct kvm_vcpu *vcpu, u32 msr, u64 data)
{ {
u64 *p = (u64 *)&vcpu->arch.mtrr_state.fixed_ranges; u64 *p = (u64 *)&vcpu->arch.mtrr_state.fixed_ranges;
if (!mtrr_valid(vcpu, msr, data)) if (!kvm_mtrr_valid(vcpu, msr, data))
return 1; return 1;
if (msr == MSR_MTRRdefType) { if (msr == MSR_MTRRdefType) {
......
...@@ -132,6 +132,8 @@ int kvm_write_guest_virt_system(struct x86_emulate_ctxt *ctxt, ...@@ -132,6 +132,8 @@ int kvm_write_guest_virt_system(struct x86_emulate_ctxt *ctxt,
gva_t addr, void *val, unsigned int bytes, gva_t addr, void *val, unsigned int bytes,
struct x86_exception *exception); struct x86_exception *exception);
bool kvm_mtrr_valid(struct kvm_vcpu *vcpu, u32 msr, u64 data);
extern u64 host_xcr0; extern u64 host_xcr0;
extern unsigned int min_timer_period_us; extern unsigned int min_timer_period_us;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment