From: Paolo Bonzini Subject: Re: [PATCH 2/3] kvm: nVMX: Validate the I/O bitmaps on nested VM-entry Date: Fri, 7 Jul 2017 10:40:52 +0200 Message-ID: <4e7776f6-498b-47da-a253-1374957d1190@redhat.com> References: <20170706233307.85493-1-jmattson@google.com> <20170706233307.85493-2-jmattson@google.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit To: Jim Mattson , kvm@vger.kernel.org Return-path: Received: from mail-wr0-f194.google.com ([209.85.128.194]:36094 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751782AbdGGIk4 (ORCPT ); Fri, 7 Jul 2017 04:40:56 -0400 Received: by mail-wr0-f194.google.com with SMTP id 77so6067434wrb.3 for ; Fri, 07 Jul 2017 01:40:56 -0700 (PDT) In-Reply-To: <20170706233307.85493-2-jmattson@google.com> Content-Language: en-US Sender: kvm-owner@vger.kernel.org List-ID: On 07/07/2017 01:33, Jim Mattson wrote: > According to the SDM, if the "use I/O bitmaps" VM-execution control is > 1, bits 11:0 of each I/O-bitmap address must be 0. Neither address > should set any bits beyond the processor's physical-address width. > > Signed-off-by: Jim Mattson Reviewed-by: Paolo Bonzini > --- > arch/x86/kvm/vmx.c | 16 ++++++++++++++++ > 1 file changed, 16 insertions(+) > > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index 8ab625feb46e..f03dcd744557 100644 > --- a/arch/x86/kvm/vmx.c > +++ b/arch/x86/kvm/vmx.c > @@ -9571,6 +9571,19 @@ static void vmx_start_preemption_timer(struct kvm_vcpu *vcpu) > ns_to_ktime(preemption_timeout), HRTIMER_MODE_REL); > } > > +static int nested_vmx_check_io_bitmap_controls(struct kvm_vcpu *vcpu, > + struct vmcs12 *vmcs12) > +{ > + if (!nested_cpu_has(vmcs12, CPU_BASED_USE_IO_BITMAPS)) > + return 0; > + > + if (!page_address_valid(vcpu, vmcs12->io_bitmap_a) || > + !page_address_valid(vcpu, vmcs12->io_bitmap_b)) > + return -EINVAL; > + > + return 0; > +} > + > static int nested_vmx_check_msr_bitmap_controls(struct kvm_vcpu *vcpu, > struct vmcs12 *vmcs12) > { > @@ -10275,6 +10288,9 @@ static int check_vmentry_prereqs(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) > vmcs12->guest_activity_state != GUEST_ACTIVITY_HLT) > return VMXERR_ENTRY_INVALID_CONTROL_FIELD; > > + if (nested_vmx_check_io_bitmap_controls(vcpu, vmcs12)) > + return VMXERR_ENTRY_INVALID_CONTROL_FIELD; > + > if (nested_vmx_check_msr_bitmap_controls(vcpu, vmcs12)) > return VMXERR_ENTRY_INVALID_CONTROL_FIELD; > >