Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp6076365pxv; Thu, 29 Jul 2021 06:02:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyofRcnB8MHB1b8KxbD9SRqQaDqDDXKhFtRry2huxh/8wJNCOhzqyMy6uMl3x2ZloSKbVI7 X-Received: by 2002:a05:6402:c1b:: with SMTP id co27mr5255006edb.147.1627563764520; Thu, 29 Jul 2021 06:02:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627563764; cv=none; d=google.com; s=arc-20160816; b=Ow76Q7i6PB9rQPRIdJXXkvl5wQG2dYOUXZfNcSKZ8GYcDKtlEdHiQonztnnXiYvNhx k9nFfNFOt0M41gKu1LljuTt6aTvRa7bbSbnK0JvBVjso0kWd32oJ6ElgW7cb7ZrGQFbE 6D8cc+Dm7n+J8gcn1IK3PZ9PpwlD9o99NsTKOAjhklArtRME6EoVnK9vumPfgZR2tnkb zmPKhM7zW9Gxwk+2t1LUJiAvVpKN0qHgj7wyAd1aRbkowS1dcaLJscKg3b3Cii3T9O6l M+x0OLvieoNo557JBEmeri2yDhzp0uLusF9/iYoVEO2KCGilYhInH4i9iiRCO6TBQhJs CW5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=AT/3FVxGahF1a02MjDV/Hp7nrzPvPUXFvANJlYeTlHU=; b=CWTrWRoAchUNNaSIB1s9hTGiLYLd1L9LBKwiT5E2E+0fh0DqZ0k2/pI8wFxxU/joDI DMmYXySXTKIl9dygRx/BUGLkC0Tl5xRG/hWUG7+0qP7e9d6WK0IWt8GQRRD4ftuw5NGj UAjQ+6ySnPDI/huuyGfzLA1HRlM74P29C1nICYTxX4s77OjNPPlP4wsJyLuPs2/B86zz +RVATy/RgMtfSBQXgl950Dhm1L/oVWLsNrpndU9WyI7wakUaqqY4w2YvsfW1j5e/i1wh yxhCYdJgXtZeEo04+sKp5+GSj/5u64XhEx8nuY38//GnR9OYpaboBXQMXWf/cQU1Gk10 eXPw== 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 m11si2801418edv.453.2021.07.29.06.02.19; Thu, 29 Jul 2021 06:02:44 -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 S237398AbhG2M6F (ORCPT + 99 others); Thu, 29 Jul 2021 08:58:05 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:7896 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237311AbhG2M6B (ORCPT ); Thu, 29 Jul 2021 08:58:01 -0400 Received: from dggeme703-chm.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Gb9TG4cBPz81HB; Thu, 29 Jul 2021 20:54:10 +0800 (CST) Received: from huawei.com (10.175.124.27) 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; Thu, 29 Jul 2021 20:57:56 +0800 From: Miaohe Lin To: , , , CC: , , , , , , , , , Subject: [PATCH 4/5] mm, memcg: avoid possible NULL pointer dereferencing in mem_cgroup_init() Date: Thu, 29 Jul 2021 20:57:54 +0800 Message-ID: <20210729125755.16871-5-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20210729125755.16871-1-linmiaohe@huawei.com> References: <20210729125755.16871-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.124.27] 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 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; rtpn->rb_root = RB_ROOT; rtpn->rb_rightmost = NULL; spin_lock_init(&rtpn->lock); -- 2.23.0