From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932185AbdIRMTc (ORCPT ); Mon, 18 Sep 2017 08:19:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54686 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754469AbdIRMTa (ORCPT ); Mon, 18 Sep 2017 08:19:30 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7DF6581DF0 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=david@redhat.com Subject: Re: [PATCH] KVM: x86: Fix the NULL pointer parameter in check_cr_write() To: Yu Zhang , kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, pbonzini@redhat.com, jmattson@google.com, rkrcmar@redhat.com, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com References: <1505731501-6821-1-git-send-email-yu.c.zhang@linux.intel.com> From: David Hildenbrand Organization: Red Hat GmbH Message-ID: <62dd03f0-4049-1d9c-d07b-61cac4c49c93@redhat.com> Date: Mon, 18 Sep 2017 14:19:26 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <1505731501-6821-1-git-send-email-yu.c.zhang@linux.intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 18 Sep 2017 12:19:30 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 18.09.2017 12:45, Yu Zhang wrote: > Routine check_cr_write() will trigger emulator_get_cpuid()-> > kvm_cpuid() to get maxphyaddr, and NULL is passed as values > for ebx/ecx/edx. This is problematic because kvm_cpuid() will > dereference these pointers. > > Fixes: d1cd3ce90044 ("KVM: MMU: check guest CR3 reserved bits based on its physical address width.") > Reported-by: Jim Mattson > Signed-off-by: Yu Zhang > --- > arch/x86/kvm/emulate.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c > index 16bf665..15f527b 100644 > --- a/arch/x86/kvm/emulate.c > +++ b/arch/x86/kvm/emulate.c > @@ -4102,10 +4102,12 @@ static int check_cr_write(struct x86_emulate_ctxt *ctxt) > ctxt->ops->get_msr(ctxt, MSR_EFER, &efer); > if (efer & EFER_LMA) { > u64 maxphyaddr; > - u32 eax = 0x80000008; > + u32 eax, ebx, ecx, edx; > > - if (ctxt->ops->get_cpuid(ctxt, &eax, NULL, NULL, > - NULL, false)) > + eax = 0x80000008; > + ecx = 0; > + if (ctxt->ops->get_cpuid(ctxt, &eax, &ebx, &ecx, > + &edx, false)) > maxphyaddr = eax & 0xff; > else > maxphyaddr = 36; > Not sure if fixing kvm_cpuid() would be better. Reviewed-by: David Hildenbrand -- Thanks, David