Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp73660pxv; Fri, 30 Jul 2021 19:12:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyx4hB5sMMJ2mKaRe3MQMI4J7il2U19wj2cyDv0NdpdT5MxEOrjNm8WMVsz0ZhMO9Uk+3rl X-Received: by 2002:aa7:ccc1:: with SMTP id y1mr6649563edt.321.1627697538857; Fri, 30 Jul 2021 19:12:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627697538; cv=none; d=google.com; s=arc-20160816; b=DfL2UM39fYb7+q/icqC7+F9zpjwgRI1Y303I8bQN9uIH01qpHwVzcalWoB7mVrKUsy d4zCjLoOo+revSpeT4CaWjlgpA2GSWfgiH2y5UooDWt/WGUtLzmpB/DtV4XHRv2NuEB4 XBd1wDXiLkn/lFqBsa0dBAgNmZFRKI7ypZhwvxncRXp5Lt6J0BNoJwFmjMX+7fxJnLMl VevY4MLjDdGYIC0KHFOKmLpz2e9jCdyt/V/QVhMo3twacpsyegwDrJS0ACWTyX+fkhwi MgFbCbKcmoY20nN2C/duWC1a9GLrxtWrSoLWNA8UqP2nYugPD9Y6j9oFH2Veu7b8DYMI Sw5w== 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=7v52X5AoVDHIy5rIu4srsFtj45mKHZewElbgNuFBJZ0=; b=vFXRs8SkI0gFFNqnGFAQ6DJxGrKMXCZ0XObJS5HImceKdi8oqFNh4DofODvAAJREVl ROuK65QXmejqZc/BWA8BdJ06CsNQzqAPPVWs6dEvN7+S2yL6dgQMSZoMd+RlI5Lm+C/2 eD6JiPyZpmUZzJYELxLljbUPcKVDReGrFt1+MQkmndcVL4zBLuy/cltY0Fkt18M1iBtR dTLKmuKxdun+QZ93aXsbt6Y+ij2R1ucAMax47olnQKM7xyZZ9ZUysF3pUFsUlAF6kG13 Hv9g3j5m7kxEdEQlKia64yRYzrUjtQQySpnG2xtiOxBuQtzzg+myT7R6yomQYGLf0+Ie GX/A== 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 j25si3726644edr.48.2021.07.30.19.11.12; Fri, 30 Jul 2021 19:12:18 -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 S234944AbhGaCGA (ORCPT + 99 others); Fri, 30 Jul 2021 22:06:00 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:12430 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231335AbhGaCF7 (ORCPT ); Fri, 30 Jul 2021 22:05:59 -0400 Received: from dggeme703-chm.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Gc6wG0PjJzchv1; Sat, 31 Jul 2021 10:02:22 +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; Sat, 31 Jul 2021 10:05:51 +0800 Subject: Re: [PATCH 4/5] mm, memcg: avoid possible NULL pointer dereferencing in mem_cgroup_init() To: Michal Hocko , Roman Gushchin CC: , , , , , , , , , , References: <20210729125755.16871-1-linmiaohe@huawei.com> <20210729125755.16871-5-linmiaohe@huawei.com> From: Miaohe Lin Message-ID: Date: Sat, 31 Jul 2021 10:05:51 +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 14:44, Michal Hocko wrote: > On Thu 29-07-21 20:12:43, 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. > > Moreover this is 24B allocation during early boot. Kernel will OOM and > panic when not being able to find any victim. I do not think we need to Agree with you. But IMO it may not be a good idea to leave the rtpn without NULL check. We should defend it though it could hardly happen. But I'm not insist on this check. I will drop this patch if you insist. Thanks both of you. > do any special handling here. >