Message ID | 20230615073226.1343-2-haifeng.xu@shopee.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp459599vqr; Thu, 15 Jun 2023 00:50:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6x809yFNgQ7DAWh2VcdAOVWc55iwEN5moYPiNAtckYIsaDxboytsZQK2RcpZuxyyHeavd4 X-Received: by 2002:a05:620a:6c86:b0:75f:7d9:d0ee with SMTP id uj6-20020a05620a6c8600b0075f07d9d0eemr2634879qkn.31.1686815420235; Thu, 15 Jun 2023 00:50:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686815420; cv=none; d=google.com; s=arc-20160816; b=Tw6HxeZS6SrV623yM+eLchogYceX/ijqp/7eH/SwPBfLSM/MIy7uDB79uIYoGc6hRZ n5mfnY3wix3nK1mOGHMrUM9Q+8ovzfZWKbBjx2LRz3BEN/0suAvgqy+Es1x2azNadkod rI9NzP58wzMeP4f9sB3R4Mlp/Qacf0O3I9rQRSwqiHmL3Htxmd3AKS8AUWpFsKi3ELFQ xc9ZxfzyQtOXbmtBia9ihPWnu3/2TzG9vmGHgbyvVS/+B5Q1I87zA0vQ55Mi+wbNc0Bl AFPDntPwnsCuJjrYK38M1vHYyfSWQk1lEnc1jmC67+CHxffypteGDcpC3UxvLY7W5rGT 07WA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=fNxDzGJxt2Rtrqq4SUvAlNEkp/z3fWK6RSnN1kjt4g4=; b=CDU+kikQ8n5RrRG8TLwnljPaH/D+qjTLQI6oHj/xwzyYIjGVLWbNrOXSCdLTF/6jtN glDS4RoYpkZ6nabQntBd7c0pwfY6s3OaySJspu44O73h4grXWwql9+wjjGquPTaa5TCD 5Nqu9iT7y5XK2v9cR5qpOWhiUho3p0v5EdpKdNMbSHBblVfU5p30fl72AEGxDw3jiBkd i11OzKyJ66EvKNBBQNnwJ7hUaXf6AJtzWo11HkCtjWSZwot4me3X8fMj1xA/ni+v24lS MCaQRWODFlUCzBwRU5bp7JmFL2HKQfuQvd2mdm8zzc+5BghQO7DKkYQGiWGZtYW6dflQ WAZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shopee.com header.s=shopee.com header.b=KEuKbPWo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=shopee.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z30-20020aa7991e000000b0064d2d8d7c33si9579151pff.45.2023.06.15.00.49.14; Thu, 15 Jun 2023 00:50:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@shopee.com header.s=shopee.com header.b=KEuKbPWo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=shopee.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244948AbjFOHdb (ORCPT <rfc822;n2h9z4@gmail.com> + 99 others); Thu, 15 Jun 2023 03:33:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244336AbjFOHc7 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 15 Jun 2023 03:32:59 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 165152D76 for <linux-kernel@vger.kernel.org>; Thu, 15 Jun 2023 00:32:43 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1b4f9583404so14344155ad.2 for <linux-kernel@vger.kernel.org>; Thu, 15 Jun 2023 00:32:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shopee.com; s=shopee.com; t=1686814362; x=1689406362; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=fNxDzGJxt2Rtrqq4SUvAlNEkp/z3fWK6RSnN1kjt4g4=; b=KEuKbPWosv9iUFbOmk/dVUFWj71DFPDvQ7CbfsaMugZZDa8k//E8CAEE0n7vr+1f9j LuaB0+g520Fb2VC8JF2Ke6qTtXHB+JzbKxSjCpCxOC9+m6pzYQjTgltBzMdNNNeet8Ea TA9tu43p8KzKc8oCUgqgD54eZUaQvLI/G36bAbrWX2vpG6RWPW0E2Yk20bIdnngUwFnx D1g4aYowz3lb2PduXbvRW/O2vQlVUUk6t5e9VKATy19FtWYWUTaAZlJk+ItZuMhRmNEr ZqgledtelE5KdFama0C4457YvSAPiqJd6KA8hxamKJH0N860sPoNcs9G9Wa6jhBqj3x8 THYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686814362; x=1689406362; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fNxDzGJxt2Rtrqq4SUvAlNEkp/z3fWK6RSnN1kjt4g4=; b=IrY2UQseNyJPmAv2xILqe+IEvehauVK/CpzA88fNYGl4k/zOHx5QUEqjAceRrdt08s uosXWdrse9gc67chll+/AKTSctUCnugkIwcT+5oA+4StkTLkH8tX/EKiIcAZvkzIo6Ly 2u8mK734Qv+kysYJQDcfk6wQLkNKRJ+Tc9/DLXm4d47gvPEJBEvBbpiIVxUxMBo9nuG4 0lWc06xbZUrhFadcvhVV02NGdJnCJOE8o8gkFsQdIwVcgdT+9P6oCcvi0aqm6lYPkIq0 Y24pZCne/vUA+TtLIjx8YmKuIxmmVuLvKf9EiE13Xx+OQ9FX6j7vHCq/oJ26q+1jbMMz Qs5A== X-Gm-Message-State: AC+VfDxxltO3ghHMncFOzVRGAcVhshRaBVojnKx5Ez+hVN3Wz1ZXc5BN h+lWpu7yrntzOGHuL1xxWOTDzw== X-Received: by 2002:a17:903:2350:b0:1a1:b3bb:cd5b with SMTP id c16-20020a170903235000b001a1b3bbcd5bmr17543833plh.62.1686814362490; Thu, 15 Jun 2023 00:32:42 -0700 (PDT) Received: from ubuntu-hf2.default.svc.cluster.local ([101.127.248.173]) by smtp.gmail.com with ESMTPSA id z18-20020a170903019200b001acad86ebc5sm13352570plg.33.2023.06.15.00.32.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jun 2023 00:32:42 -0700 (PDT) From: Haifeng Xu <haifeng.xu@shopee.com> To: mhocko@suse.com Cc: roman.gushchin@linux.dev, hannes@cmpxchg.org, shakeelb@google.com, akpm@linux-foundation.org, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Haifeng Xu <haifeng.xu@shopee.com> Subject: [PATCH 2/2] mm/memcontrol: add check for allocation failure in mem_cgroup_init() Date: Thu, 15 Jun 2023 07:32:26 +0000 Message-Id: <20230615073226.1343-2-haifeng.xu@shopee.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768754166102656973?= X-GMAIL-MSGID: =?utf-8?q?1768754166102656973?= |
Series |
[1/2] mm/memcontrol: do not tweak node in mem_cgroup_init()
|
|
Commit Message
Haifeng Xu
June 15, 2023, 7:32 a.m. UTC
If mem_cgroup_init() fails to allocate mem_cgroup_tree_per_node, we
should not try to initilaize it. Add check for this case to avoid
potential NULL pointer dereference.
Signed-off-by: Haifeng Xu <haifeng.xu@shopee.com>
---
mm/memcontrol.c | 2 ++
1 file changed, 2 insertions(+)
Comments
On Thu 15-06-23 07:32:26, Haifeng Xu wrote: > If mem_cgroup_init() fails to allocate mem_cgroup_tree_per_node, we > should not try to initilaize it. Add check for this case to avoid > potential NULL pointer dereference. Technically yes and it seems that all users of soft_limit_tree.rb_tree_per_node correctly check for NULL so this would be graceful failure handling. At least superficially because the feature itself would be semi-broken when used. But more practically this is a 24B allocation and if we fail to allocate that early during the boot we are screwed anyway. Would such a system have any chance to boot all the way to userspace? Woul any userspace actually work? Is this patch motivated by a code reading or is there any actual practical upside of handling the error here? > Signed-off-by: Haifeng Xu <haifeng.xu@shopee.com> > --- > mm/memcontrol.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index c73c5fb33f65..7ebf64e48b25 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -7422,6 +7422,8 @@ static int __init mem_cgroup_init(void) > struct mem_cgroup_tree_per_node *rtpn; > > rtpn = kzalloc_node(sizeof(*rtpn), GFP_KERNEL, node); > + if (!rtpn) > + continue; > > rtpn->rb_root = RB_ROOT; > rtpn->rb_rightmost = NULL; > -- > 2.25.1
On 2023/6/15 16:26, Michal Hocko wrote: > On Thu 15-06-23 07:32:26, Haifeng Xu wrote: >> If mem_cgroup_init() fails to allocate mem_cgroup_tree_per_node, we >> should not try to initilaize it. Add check for this case to avoid >> potential NULL pointer dereference. > > Technically yes and it seems that all users of soft_limit_tree.rb_tree_per_node > correctly check for NULL so this would be graceful failure handling. At > least superficially because the feature itself would be semi-broken when > used. But more practically this is a 24B allocation and if we fail to > allocate that early during the boot we are screwed anyway. Would such > a system have any chance to boot all the way to userspace? Woul any > userspace actually work? > The memory request is too small and It's unlikely to fail during early init. If it fails, I think the system won't work. > Is this patch motivated by a code reading or is there any actual > practical upside of handling the error here? > There is no real world problem, just from code review. >> Signed-off-by: Haifeng Xu <haifeng.xu@shopee.com> >> --- >> mm/memcontrol.c | 2 ++ >> 1 file changed, 2 insertions(+) >> >> diff --git a/mm/memcontrol.c b/mm/memcontrol.c >> index c73c5fb33f65..7ebf64e48b25 100644 >> --- a/mm/memcontrol.c >> +++ b/mm/memcontrol.c >> @@ -7422,6 +7422,8 @@ static int __init mem_cgroup_init(void) >> struct mem_cgroup_tree_per_node *rtpn; >> >> rtpn = kzalloc_node(sizeof(*rtpn), GFP_KERNEL, node); >> + if (!rtpn) >> + continue; >> >> rtpn->rb_root = RB_ROOT; >> rtpn->rb_rightmost = NULL; >> -- >> 2.25.1 >
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index c73c5fb33f65..7ebf64e48b25 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -7422,6 +7422,8 @@ static int __init mem_cgroup_init(void) struct mem_cgroup_tree_per_node *rtpn; rtpn = kzalloc_node(sizeof(*rtpn), GFP_KERNEL, node); + if (!rtpn) + continue; rtpn->rb_root = RB_ROOT; rtpn->rb_rightmost = NULL;