Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp1536616pxy; Mon, 2 Aug 2021 04:20:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwBzNg9pL6Gv9FB3PHtzijSNS/msIEy3JjjJv1ZPmpcO1x43k4GrckcPqyoths3XR871p3l X-Received: by 2002:a05:6e02:107:: with SMTP id t7mr983652ilm.77.1627903232421; Mon, 02 Aug 2021 04:20:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627903232; cv=none; d=google.com; s=arc-20160816; b=OWrNHlnUFFFcXOUNTt5aZWR4FH8JkhYNbdpnfVvZ3gFqu7bE05cdRGpNqAUvjHFs3+ kK3EevtAwuj1a9GxB6h5MNfHccmIJArVArWvW1E0+VaMihYVfdMpN6AH5JY7e/VymgQU gqNK5rTIe4vfCYOlnFi8O72Yd3ocHuQN9DmKbVFUuAvhCL0vAcHK6yE3zJ0js1rpUQbi 6Ehjqk3wvJPFAzCdWVX+lggxAocbQ3k9JOJPX7HtO+2Ck7Qux46u/fcnN8+TRRl3w517 3f0Rit1G77RW4gZczA4xa21rCeKDTr0GoHHqgxo3p5CqY+tHrNagitnDap9LTUSKTrEZ iFbA== 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=ZXbm15Z55WyQ1G0QySr0a4YxkseQz/3zsVRnW580rb4=; b=p9sqTrU+19zXXDGC3MBAXCKABfid6KtmpcOiRhG71n37RQ0DBfwBE36Y2NJAIx3Udi SNHcJ4eAs7vDigliT0qb/ziNqj0p4zqtKY0bL/7ihJequbfNdUZ1jItb3eLuo3Yq5lUB mLz7pcBPESJeYAhm0/+Ddoq+GHJ9Aa1QU5OySa6pweuz5kkuwZ5Nl9Cz3U2uJi8hqXOC mbYyM9K6hx/siQYaOG0g7g7mvvqOhmYRiklLuDoKtyX1emGXOYKorS5y1LgrBvIcgP6o QjdLE+tOSa/nWNPCr2HOsLV1XSSbZ60+upAbOr7ndz3fqVYQwidEFmBW5z2zanij1TWj SKBA== 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 f13si12799811ils.29.2021.08.02.04.20.20; Mon, 02 Aug 2021 04:20:32 -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 S233362AbhHBLSd (ORCPT + 99 others); Mon, 2 Aug 2021 07:18:33 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:7774 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231881AbhHBLSc (ORCPT ); Mon, 2 Aug 2021 07:18:32 -0400 Received: from dggeme703-chm.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Gdb8p1TkNzYh96; Mon, 2 Aug 2021 19:18:18 +0800 (CST) Received: from [10.174.179.25] (10.174.179.25) 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; Mon, 2 Aug 2021 19:18:21 +0800 Subject: Re: [PATCH 4/5] mm, memcg: avoid possible NULL pointer dereferencing in mem_cgroup_init() To: Michal Hocko CC: Roman Gushchin , , , , , , , , , , , References: <20210729125755.16871-1-linmiaohe@huawei.com> <20210729125755.16871-5-linmiaohe@huawei.com> <47daf062-f510-edb3-6ec7-f8e7615ad8a0@huawei.com> From: Miaohe Lin Message-ID: <59122ae4-52c9-4ff9-104d-872d770dec0c@huawei.com> Date: Mon, 2 Aug 2021 19:18:20 +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.179.25] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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/8/2 18:42, Michal Hocko wrote: > On Mon 02-08-21 18:00:10, Miaohe Lin wrote: >> On 2021/8/2 14:43, Michal Hocko wrote: >>> On Sat 31-07-21 10:05:51, Miaohe Lin wrote: >>>> 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. >>> >>> It is not that I would insist. I just do not see any point in the code >>> churn. This check is not going to ever trigger and there is nothing you >>> can do to recover anyway so crashing the kernel is likely the only >>> choice left. >>> >> >> I hope I get the point now. What you mean is nothing we can do to recover and panic'ing on a >> NULL-pointer dereference is a perfect choice ? Should we declare that we leave the rtpn without >> NULL check on purpose like below ? >> >> Many thanks. >> >> @@ -7109,8 +7109,12 @@ 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; >> + /* >> + * If this allocation 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. >> + */ > > I am not really sure this is really worth it. Really we do not really > want to have similar comments all over the early init code, do we? Maybe not. Will drop this patch. Thanks. > >> rtpn->rb_root = RB_ROOT; >> rtpn->rb_rightmost = NULL; >> spin_lock_init(&rtpn->lock); >