From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.4 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DCEF8C4338F for ; Fri, 30 Jul 2021 06:30:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4EB8E60F6B for ; Fri, 30 Jul 2021 06:30:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4EB8E60F6B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id C1D836B0036; Fri, 30 Jul 2021 02:30:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BCDB96B005D; Fri, 30 Jul 2021 02:30:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AE2E68D0001; Fri, 30 Jul 2021 02:30:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0125.hostedemail.com [216.40.44.125]) by kanga.kvack.org (Postfix) with ESMTP id 981666B0036 for ; Fri, 30 Jul 2021 02:30:06 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 2DA9F8249980 for ; Fri, 30 Jul 2021 06:30:06 +0000 (UTC) X-FDA: 78418279212.15.197C75A Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf05.hostedemail.com (Postfix) with ESMTP id 59091502C955 for ; Fri, 30 Jul 2021 06:30:05 +0000 (UTC) Received: from dggeme703-chm.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Gbcp03TGXz7ylT; Fri, 30 Jul 2021 14:25:12 +0800 (CST) Received: from [10.174.178.209] (10.174.178.209) by dggeme703-chm.china.huawei.com (10.1.199.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Fri, 30 Jul 2021 14:29:57 +0800 Subject: Re: [PATCH 4/5] mm, memcg: avoid possible NULL pointer dereferencing in mem_cgroup_init() To: Roman Gushchin CC: , , , , , , , , , , , References: <20210729125755.16871-1-linmiaohe@huawei.com> <20210729125755.16871-5-linmiaohe@huawei.com> From: Miaohe Lin Message-ID: <2a9353e0-9ece-d8d5-1387-202b01b0fdad@huawei.com> Date: Fri, 30 Jul 2021 14:29:57 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.178.209] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggeme703-chm.china.huawei.com (10.1.199.99) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 59091502C955 Authentication-Results: imf05.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=huawei.com; spf=pass (imf05.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Stat-Signature: t5xwx8abguukg4a6gt6t9w4dxr875daa X-HE-Tag: 1627626605-38662 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: On 2021/7/30 11:12, Roman Gushchin wrote: > On Thu, Jul 29, 2021 at 08:57:54PM +0800, Miaohe Lin wrote: >> rtpn might be NULL in very rare case. We have better to check it before >> dereferencing it. Since memcg can live with NULL rb_tree_per_node in >> soft_limit_tree, warn this case and continue. >> >> Signed-off-by: Miaohe Lin >> --- >> mm/memcontrol.c | 2 ++ >> 1 file changed, 2 insertions(+) >> >> diff --git a/mm/memcontrol.c b/mm/memcontrol.c >> index 5b4592d1e0f2..70a32174e7c4 100644 >> --- a/mm/memcontrol.c >> +++ b/mm/memcontrol.c >> @@ -7109,6 +7109,8 @@ static int __init mem_cgroup_init(void) >> rtpn = kzalloc_node(sizeof(*rtpn), GFP_KERNEL, >> node_online(node) ? node : NUMA_NO_NODE); >> >> + if (WARN_ON_ONCE(!rtpn)) >> + continue; > > I also really doubt that it makes any sense to continue in this case. > If this allocations fails (at the very beginning of the system's life, it's an __init function), > something is terribly wrong and panic'ing on a NULL-pointer dereference sounds like > a perfect choice. > > Is this a real world problem? Do I miss something? No, this is a theoretical bug, a very race case but not impossible IMO. Since we can't live with NULL rb_tree_per_node in soft_limit_tree, I thinks simply continue or break here without panic is also acceptable. Or is it more proper to choose panic here? Thanks. > . >