Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp6700091pxv; Thu, 29 Jul 2021 23:31:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzz3ivb3LWfoqJPR+oo0htS3cN5Szh03a8tPRJt70htet0+CWdLhi11Jlb4ElCZ2jXEngS X-Received: by 2002:a05:6402:796:: with SMTP id d22mr1155542edy.57.1627626716264; Thu, 29 Jul 2021 23:31:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627626716; cv=none; d=google.com; s=arc-20160816; b=0Ym4AiFF1knXCPjPWHm6OczRt+1XTbwKede6QzI6TN2x9/237x//PuakofzJSwi4ji vzLgnTezxfmkdkCYpVqhFSaHM1JE29K/T/OQgTsy0hGRbnhQWZlhOBWr1rUX9IJpDVJF mwCJTDsC/etUAOHnHHLQgbL0Zi1TdnMGGjKduj3/3Vlr+d+E5lYvL+98ad0HtIJnEcWV NTyeV3xlsW4r0wRsVtxacFVwu9Al5blU20sGFjBjZbUHDLN21gsH0ZRHhx9x1VdSWemx qV0e84yL9GnQjLkJ3nrxW/HXg4PMweHwYaouvFSiO+qZp8/araPXA2PN+rRWHGbVudaY DhFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=lvyRvUnbvIjSd7/SDNVcuaUcT3EbkINGZfKNNNOX3EA=; b=Wv1tBpGZyIPjIQ2wzUAfGXo0SfKKI9pLQGUPhOhEUdF0ot38rChjyu7IpScz8gTzcZ YSL4l+Uiud98BXhc542aAl4hTYXmkBUaMpwZW3+yOQAV1fSb7WwVJ5IlavySumySK7Xu iRayJisGOu8Ubx44jiH5hlq8v34Q6RWCKQgYwSd8viU+nnN9Fa1zrqNxWhUO0g6cqPVY 9XLpaLjYKxJ2Ra0MMBJNKvBz36YpbzLfYVBUP11uTCLpH/veQtmKPU7iBOXeUH3ySaPI PNtixzEPPFHah36VoyW2P/9igKGrFm7V/xTGZuNl74igx3u4r03sM5Gm/RnkDKhMP5WU Vo7w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y14si822688eda.265.2021.07.29.23.31.33; Thu, 29 Jul 2021 23:31:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237480AbhG3GaF (ORCPT + 99 others); Fri, 30 Jul 2021 02:30:05 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:12334 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237264AbhG3GaE (ORCPT ); Fri, 30 Jul 2021 02:30:04 -0400 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > . >