Skip to content

Commit ee695f2

Browse files
Krish Sadhukhanbonzini
authored andcommitted
nSVM: Check addresses of MSR and IO permission maps
According to section "Canonicalization and Consistency Checks" in APM vol 2, the following guest state is illegal: "The MSR or IOIO intercept tables extend to a physical address that is greater than or equal to the maximum supported physical address." Suggested-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Krish Sadhukhan <krish.sadhukhan@oracle.com> Message-Id: <20210412215611.110095-5-krish.sadhukhan@oracle.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 47903dc commit ee695f2

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

‎arch/x86/kvm/svm/nested.c‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,19 @@ static bool nested_svm_vmrun_msrpm(struct vcpu_svm *svm)
215215
return true;
216216
}
217217

218-
static bool nested_vmcb_check_controls(struct vmcb_control_area *control)
218+
/*
219+
* Bits 11:0 of bitmap address are ignored by hardware
220+
*/
221+
static bool nested_svm_check_bitmap_pa(struct kvm_vcpu *vcpu, u64 pa, u32 size)
222+
{
223+
u64 addr = PAGE_ALIGN(pa);
224+
225+
return kvm_vcpu_is_legal_gpa(vcpu, addr) &&
226+
kvm_vcpu_is_legal_gpa(vcpu, addr + size - 1);
227+
}
228+
229+
static bool nested_vmcb_check_controls(struct kvm_vcpu *vcpu,
230+
struct vmcb_control_area *control)
219231
{
220232
if (CC(!vmcb_is_intercept(control, INTERCEPT_VMRUN)))
221233
return false;
@@ -226,6 +238,13 @@ static bool nested_vmcb_check_controls(struct vmcb_control_area *control)
226238
if (CC((control->nested_ctl & SVM_NESTED_CTL_NP_ENABLE) && !npt_enabled))
227239
return false;
228240

241+
if (CC(!nested_svm_check_bitmap_pa(vcpu, control->msrpm_base_pa,
242+
MSRPM_SIZE)))
243+
return false;
244+
if (CC(!nested_svm_check_bitmap_pa(vcpu, control->iopm_base_pa,
245+
IOPM_SIZE)))
246+
return false;
247+
229248
return true;
230249
}
231250

@@ -604,7 +623,7 @@ int nested_svm_vmrun(struct kvm_vcpu *vcpu)
604623
nested_load_control_from_vmcb12(svm, &vmcb12->control);
605624

606625
if (!nested_vmcb_valid_sregs(vcpu, &vmcb12->save) ||
607-
!nested_vmcb_check_controls(&svm->nested.ctl)) {
626+
!nested_vmcb_check_controls(vcpu, &svm->nested.ctl)) {
608627
vmcb12->control.exit_code = SVM_EXIT_ERR;
609628
vmcb12->control.exit_code_hi = 0;
610629
vmcb12->control.exit_info_1 = 0;
@@ -1252,7 +1271,7 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu,
12521271
goto out_free;
12531272

12541273
ret = -EINVAL;
1255-
if (!nested_vmcb_check_controls(ctl))
1274+
if (!nested_vmcb_check_controls(vcpu, ctl))
12561275
goto out_free;
12571276

12581277
/*

0 commit comments

Comments
 (0)