From: David Hildenbrand Subject: Re: [PATCH] kvm: nVMX: Validate CR3 target count on nested VM-entry Date: Mon, 8 May 2017 09:58:21 +0200 Message-ID: <0e7bc77b-1c09-8540-bfaa-9c17ace69142@redhat.com> References: <20170505182809.160185-1-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 mx1.redhat.com ([209.132.183.28]:55588 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753330AbdEHH6X (ORCPT ); Mon, 8 May 2017 03:58:23 -0400 In-Reply-To: <20170505182809.160185-1-jmattson@google.com> Content-Language: en-US Sender: kvm-owner@vger.kernel.org List-ID: On 05.05.2017 20:28, Jim Mattson wrote: > According to the SDM, the CR3-target count must not be greater than > 4. Future processors may support a different number of CR3-target > values. Software should read the VMX capability MSR IA32_VMX_MISC to > determine the number of values supported. > > Signed-off-by: Jim Mattson > --- > arch/x86/kvm/vmx.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index 28485e3d1b27..4ce055cb1cfd 100644 > --- a/arch/x86/kvm/vmx.c > +++ b/arch/x86/kvm/vmx.c > @@ -1328,6 +1328,11 @@ static inline bool report_flexpriority(void) > return flexpriority_enabled; > } > > +static inline unsigned nested_cpu_vmx_misc_cr3_count(struct kvm_vcpu *vcpu) > +{ > + return vmx_misc_cr3_count(to_vmx(vcpu)->nested.nested_vmx_misc_low); > +} > + > static inline bool nested_cpu_has(struct vmcs12 *vmcs12, u32 bit) > { > return vmcs12->cpu_based_vm_exec_control & bit; > @@ -10331,6 +10336,9 @@ static int check_vmentry_prereqs(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) > vmx->nested.nested_vmx_entry_ctls_high)) > return VMXERR_ENTRY_INVALID_CONTROL_FIELD; > > + if (vmcs12->cr3_target_count > nested_cpu_vmx_misc_cr3_count(vcpu)) > + return VMXERR_ENTRY_INVALID_CONTROL_FIELD; > + > if (!nested_host_cr0_valid(vcpu, vmcs12->host_cr0) || > !nested_host_cr4_valid(vcpu, vmcs12->host_cr4) || > !nested_cr3_valid(vcpu, vmcs12->host_cr3)) > Looks sane to me. Reviewed-by: David Hildenbrand -- Thanks, David