Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1782240imm; Thu, 2 Aug 2018 00:32:54 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdBkvTD4WjE4bSOSfGRBAGYv9OLoxy/AS2JwHoOGGzyXCmOSJ0CD23Rx3OoiiaaMf2ipQQG X-Received: by 2002:a63:9619:: with SMTP id c25-v6mr1585172pge.75.1533195174045; Thu, 02 Aug 2018 00:32:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533195174; cv=none; d=google.com; s=arc-20160816; b=u2qAbDjnr1uv98Lp3e8VX5sFR3JA0guIVb7cDUjbA+s9z8tQWC4R6rN02gs8+mJL9l Cgsyg0GoON2KzUdu6TkAWDVrnln6wJwM7RGst1gKZ2NHj9e+RamD9xOPYSQ5EDiwWPii IRRF+e08y5CaIXNZTo7/9ngA0wwJP1JY8NLG8ch4V1dDpwyjt6yE394AaHLRR8pvFLWt zTvwi06NWexdvZHOkn5fHf8zvl3rGcgVEdafO+qzeKc6IuExNDTpzajYel4oKtxs7ebx e6hoB3RUTau8RDZx+qEbF3o0zrtksTWqrnA6DSRU6yELk+EemTRbFXdvUwg5IOvVTkMo BTxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=Nsy64L29R4uNzLg9RfJikq6SXjS2QnOarhTcM4/kpXY=; b=gTCJZHyLhWupRjRxD2j4abAOPgkTCx2I7smnVK2SQpmTxZIp+beSE7sSHdEj5Y13nf Ja4Lrqdc6aumYuZ3P5pXVXwruwWb9HQXjAZZO/ZgZ5FlLI48HTYGGybX/ZMFWGgBq7ZR HsnkVmNEa4932fScgkulUUtpRdDq7sIRpjMSSbsGNUTSOexkh6IpDvuFwC5e8XMe7Oh9 GZNiQRUatVIR2BssuegjsfG8Aj5mt13geEawq1x4X6S/NNyKzLekyEtxybLoitOYLbY0 5c9jwZ+6WsoMn5UEmRegG5jHsALeDBVvC2C+ckb7DtiPXpHb2R8A4VUQY7MEU1WAippd wEqw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d10-v6si868009pla.511.2018.08.02.00.32.39; Thu, 02 Aug 2018 00:32:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727047AbeHBJVl (ORCPT + 99 others); Thu, 2 Aug 2018 05:21:41 -0400 Received: from mx2.suse.de ([195.135.220.15]:50168 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726237AbeHBJVl (ORCPT ); Thu, 2 Aug 2018 05:21:41 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 08CAFAE2D; Thu, 2 Aug 2018 07:31:49 +0000 (UTC) Date: Thu, 2 Aug 2018 09:31:47 +0200 From: Michal Hocko To: Jeremy Linton Cc: linux-mm@kvack.org, cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, vbabka@suse.cz, Punit.Agrawal@arm.com, Lorenzo.Pieralisi@arm.com, linux-arm-kernel@lists.infradead.org, bhelgaas@google.com, linux-kernel@vger.kernel.org Subject: Re: [RFC 2/2] mm: harden alloc_pages code paths against bogus nodes Message-ID: <20180802073147.GA10808@dhcp22.suse.cz> References: <20180801200418.1325826-1-jeremy.linton@arm.com> <20180801200418.1325826-3-jeremy.linton@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180801200418.1325826-3-jeremy.linton@arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed 01-08-18 15:04:18, Jeremy Linton wrote: > Its possible to crash __alloc_pages_nodemask by passing it > bogus node ids. This is caused by NODE_DATA() returning null > (hopefully) when the requested node is offline. We can > harded against the basic case of a mostly valid node, that > isn't online by checking for null and failing prepare_alloc_pages. > > But this then suggests we should also harden NODE_DATA() like this > > #define NODE_DATA(nid) ( (nid) < MAX_NUMNODES ? node_data[(nid)] : NULL) > > eventually this starts to add a bunch of generally uneeded checks > in some code paths that are called quite frequently. But the page allocator is really a hot path and people will not be happy to have yet another branch there. No code should really use invalid numa node ids in the first place. If I remember those bugs correctly then it was the arch code which was doing something wrong. I would prefer that code to be fixed instead. > Signed-off-by: Jeremy Linton > --- > include/linux/gfp.h | 2 ++ > mm/page_alloc.c | 2 ++ > 2 files changed, 4 insertions(+) > > diff --git a/include/linux/gfp.h b/include/linux/gfp.h > index a6afcec53795..17d70271c42e 100644 > --- a/include/linux/gfp.h > +++ b/include/linux/gfp.h > @@ -436,6 +436,8 @@ static inline int gfp_zonelist(gfp_t flags) > */ > static inline struct zonelist *node_zonelist(int nid, gfp_t flags) > { > + if (unlikely(!NODE_DATA(nid))) //VM_WARN_ON? > + return NULL; > return NODE_DATA(nid)->node_zonelists + gfp_zonelist(flags); > } > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index a790ef4be74e..3a3d9ac2662a 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -4306,6 +4306,8 @@ static inline bool prepare_alloc_pages(gfp_t gfp_mask, unsigned int order, > { > ac->high_zoneidx = gfp_zone(gfp_mask); > ac->zonelist = node_zonelist(preferred_nid, gfp_mask); > + if (!ac->zonelist) > + return false; > ac->nodemask = nodemask; > ac->migratetype = gfpflags_to_migratetype(gfp_mask); > > -- > 2.14.3 > -- Michal Hocko SUSE Labs