From: Martin Kelly Subject: Re: [PATCH] xen/setup: add paranoid index check and warning Date: Mon, 13 Oct 2014 18:19:05 -0700 Message-ID: <543C7A09.4080006@martingkelly.com> References: <1413249063-26088-1-git-send-email-martin@martingkelly.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Xdqlb-0000Wn-Rc for xen-devel@lists.xenproject.org; Tue, 14 Oct 2014 01:19:11 +0000 Received: by mail-pd0-f172.google.com with SMTP id ft15so6560983pdb.3 for ; Mon, 13 Oct 2014 18:19:08 -0700 (PDT) In-Reply-To: <1413249063-26088-1-git-send-email-martin@martingkelly.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org, x86@kernel.org Cc: mingo@redhat.com, david.vrabel@citrix.com, Martin Kelly , boris.ostrovsky@oracle.com, tglx@linutronix.de List-Id: xen-devel@lists.xenproject.org On 10/13/2014 06:11 PM, Martin Kelly wrote: > In a call to set_phys_range_identity, i-1 is used without checking that > i is non-zero. Although unlikely, a bug in the code before it could > cause the value to be 0, leading to erroneous behavior. This patch adds > a check against 0 value and a corresponding warning. > > Signed-off-by: Martin Kelly > --- > arch/x86/xen/setup.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c > index af72161..26e39af 100644 > --- a/arch/x86/xen/setup.c > +++ b/arch/x86/xen/setup.c > @@ -671,7 +671,10 @@ char * __init xen_memory_setup(void) > * PFNs above MAX_P2M_PFN are considered identity mapped as > * well. > */ > - set_phys_range_identity(map[i-1].addr / PAGE_SIZE, ~0ul); > + if (i > 0) > + set_phys_range_identity(map[i-1].addr / PAGE_SIZE, ~0ul); > + else > + WARN(1, "Something went wrong clamping memory to a factor of EXTRA_MEM_RATIO!"); > > /* > * In domU, the ISA region is normal, usable memory, but we > Forgot to add linux-kernel@vger.kernel.org; resending.