From: Jim Mattson Subject: [PATCH v2 3/3] kvm: nVMX: Validate the I/O bitmaps on nested VM-entry Date: Mon, 10 Jul 2017 12:29:04 -0700 Message-ID: <20170710192904.102893-3-jmattson@google.com> References: <201707081510.ZhaGqybS%fengguang.wu@intel.com> <20170710192904.102893-1-jmattson@google.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Jim Mattson To: kvm@vger.kernel.org Return-path: Received: from mail-pf0-f172.google.com ([209.85.192.172]:34983 "EHLO mail-pf0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754284AbdGJT35 (ORCPT ); Mon, 10 Jul 2017 15:29:57 -0400 Received: by mail-pf0-f172.google.com with SMTP id c73so54727485pfk.2 for ; Mon, 10 Jul 2017 12:29:57 -0700 (PDT) In-Reply-To: <20170710192904.102893-1-jmattson@google.com> Sender: kvm-owner@vger.kernel.org List-ID: 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 --- 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 eec9e0191311..7f27e7908477 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -9594,6 +9594,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) { @@ -10288,6 +10301,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; -- 2.13.2.725.g09c95d1e9-goog