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: 10552931 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 04595139A for ; Wed, 1 Aug 2018 20:04:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E4FDF2B5C9 for ; Wed, 1 Aug 2018 20:04:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D95B12B7CA; Wed, 1 Aug 2018 20:04:29 +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,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C7FC2B5E9 for ; Wed, 1 Aug 2018 20:04:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C7EA26B0007; Wed, 1 Aug 2018 16:04:24 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C05376B0008; Wed, 1 Aug 2018 16:04:24 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ACD696B000A; Wed, 1 Aug 2018 16:04:24 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi0-f72.google.com (mail-oi0-f72.google.com [209.85.218.72]) by kanga.kvack.org (Postfix) with ESMTP id 7A27F6B0008 for ; Wed, 1 Aug 2018 16:04:24 -0400 (EDT) Received: by mail-oi0-f72.google.com with SMTP id 20-v6so17805764ois.21 for ; Wed, 01 Aug 2018 13:04:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=nwL45KZXQc3dyip/An/8rY2zR22RmCtB6f8mc8vZbW4=; b=tvVC+PeePYAfCTVDBLVnfRCHvic096T6figjdUWzTIwNoihZcgU2bkAkmpgLQ/m9NE Vvr13FqSCv8gGFngIwZLx/koyvb802pmjVVlba6YNjYmvesDYXu+P4/wGrFUS710ZE3c gEYvtHKjDKIPxInVMN00t79BiSkhjuEzuh4cgeFqfNTlQfHFBAPXPjCN/k2r7w1R1Oj3 n56sbQfE5zHwNIChmGKKxF3zz+P7Ch4VaS32Yj3kROmWGzcsy5EU9bobB7ySWhc+SNnm ZLLsj5P7sQUaVJj/qp9iW5Aq9wWILvvN/QasyNaHDcsboU06eOBET94A09wOl+dwQxVL Fi0Q== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of jeremy.linton@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=jeremy.linton@arm.com X-Gm-Message-State: AOUpUlGu3n+1kmuhv4n/sQFdhhU+vxORBxQ85EWw08GjFADhIexbKWgv QGXyfsMWM1/tGW7xIMMjlC902fxgkifu123klS1njWoEt6Nrl+F54FOhxKcelNm5LUsCbEJix3r KtV8x1RYmzYj9dugoZXuGmm+Uk4JNqUjSlheH15Tv9aQc1+F/HOx0JXJc/cF3h1PTsA== X-Received: by 2002:aca:d0cc:: with SMTP id j73-v6mr4306122oiy.255.1533153864257; Wed, 01 Aug 2018 13:04:24 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd6pEg1cOMl4vv7oaRk1q1zozEMw0A9LmX8z6C/JTOBYgihNjm7YeYxWu3fGvlkIt9hMsz9 X-Received: by 2002:aca:d0cc:: with SMTP id j73-v6mr4306081oiy.255.1533153863571; Wed, 01 Aug 2018 13:04:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533153863; cv=none; d=google.com; s=arc-20160816; b=mjm50EBxw3MqA4nW+/P4NNunyGvebLCcN0hsfXU9PsJ1EKR1MOeb/UqWcaJnIiNv18 DXlfYaNvA4rWj2tCY9f0xpDzoQ05Tp9vgGV+RSsBAMcpN6q2dsdWYrgPpV+jYt7MSOJR Qk/bxxkZ44N3JDAiwoJFlOi3phRVlEhJNBYBA66DpxRLIeCGeh3xggaIBhzjOCui5bHL esuh1fcO9BPhw4VuR+P2CNhuBqHxKHU1qOs6rvw9NKP0M2Rg5g8hIS1dA3I50s4xPvaZ JQpunc6BqXXaBpaNYgRzH8+cS3F06UUvsbPBuW7tRyh5htjMlgxzOWQSmP8JvaK4zCxd yt4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=nwL45KZXQc3dyip/An/8rY2zR22RmCtB6f8mc8vZbW4=; b=mCcqQ844ZMBkIKggenT6AFzzVDRHiviSVL+xqJCW5b6c3/CsoevqbpUv638TZsZbIW 0BAgOYAYrurRiGjTE8e3moHwQwMKjSUJGXqiyE3GPuskusAJa4VreOJL/BuChVkIBj2I 5HdmirXzopZFE1P+2q8qCtuMwaBS64qjsXSgq6aX2XRQfttdADEMollRnom/t0XabcZc ICG0GDREraod/f2RM4B79I2innBOHc4fI5h1DAJrK6SAJEoRGfkUtxjacqftYG2InPcI uNKfj3AtZbmrlj68n+OfoFAFUn0tm1eug981U55jwCj7sEcDPHkxqbZhZh1dQgWW3Iwk j+3Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of jeremy.linton@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=jeremy.linton@arm.com Received: from foss.arm.com (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id e66-v6si11529738oif.85.2018.08.01.13.04.23 for ; Wed, 01 Aug 2018 13:04:23 -0700 (PDT) Received-SPF: pass (google.com: domain of jeremy.linton@arm.com designates 217.140.101.70 as permitted sender) client-ip=217.140.101.70; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jeremy.linton@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=jeremy.linton@arm.com 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 Cc: cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, mhocko@suse.com, 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, Jeremy Linton 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-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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);