From patchwork Wed Aug 1 20:04:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Linton X-Patchwork-Id: 10552935 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BEAF913BB for ; Wed, 1 Aug 2018 20:04:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8B4F2B645 for ; Wed, 1 Aug 2018 20:04:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 994222B5E9; Wed, 1 Aug 2018 20:04:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 136D72B5E9 for ; Wed, 1 Aug 2018 20:04:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=kNzD/jJx5aSoRJZKYyIng9VOug/tWTpVu37M7fsR31E=; b=i5/PZjhIgZ8UY+LmlfLcDQzl2l dkri3OaQ7Mim8aTzfo0KydDjaYYPTtEvjqLShb1F6UopjDAGVM/HvO3asz+U1zF1woYW745fkplfH YonUyAMzkHzd0Mf2Q6ut3CbHjmCgX6ODObThpbKqlj1H4Rtis93Tf+79tn2qq5lcGOmuXZK5eexom 3Hb57Hu+Ha5E35bA44kKDpYlNHRxIOqsaLDPHQ2NnMvQy8Xm+ZIuGAlfng58/s2arK1FC2az4mkQC /NaSyb9bm0qsPNHXjPDleG6BIYfjQycpRl+XqLI88vBJhGvdjYLPKOjo/wEOqq20iE0/aNR881aMQ fOAhht/Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fkxMQ-0004Er-GN; Wed, 01 Aug 2018 20:04:42 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fkxME-000434-Vy for linux-arm-kernel@lists.infradead.org; Wed, 01 Aug 2018 20:04:32 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3D0AC1596; Wed, 1 Aug 2018 13:04:23 -0700 (PDT) Received: from beelzebub.austin.arm.com (beelzebub.austin.arm.com [10.118.12.119]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 9717D3F5BA; Wed, 1 Aug 2018 13:04:22 -0700 (PDT) From: Jeremy Linton To: linux-mm@kvack.org Subject: [RFC 2/2] mm: harden alloc_pages code paths against bogus nodes Date: Wed, 1 Aug 2018 15:04:18 -0500 Message-Id: <20180801200418.1325826-3-jeremy.linton@arm.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180801200418.1325826-1-jeremy.linton@arm.com> References: <20180801200418.1325826-1-jeremy.linton@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180801_130431_039288_EC7F8069 X-CRM114-Status: GOOD ( 10.98 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mhocko@suse.com, akpm@linux-foundation.org, Punit.Agrawal@arm.com, linux-kernel@vger.kernel.org, Jeremy Linton , penberg@kernel.org, Lorenzo.Pieralisi@arm.com, linux-arm-kernel@lists.infradead.org, rientjes@google.com, bhelgaas@google.com, cl@linux.com, iamjoonsoo.kim@lge.com, vbabka@suse.cz MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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. 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);