Message ID | 20221202110430.1472991-1-william.xuanziyang@huawei.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp771059wrr; Fri, 2 Dec 2022 03:15:41 -0800 (PST) X-Google-Smtp-Source: AA0mqf6ukj6kzFDa+jjru2AOI/ulHbGOLC/66cfQVaa5m1JE27eDfIBqxZhKdvE+ywHL8aol4Ze+ X-Received: by 2002:a17:906:3b11:b0:7c0:cb36:d6eb with SMTP id g17-20020a1709063b1100b007c0cb36d6ebmr990923ejf.736.1669979740915; Fri, 02 Dec 2022 03:15:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669979740; cv=none; d=google.com; s=arc-20160816; b=fV3YhPjHEdyC7PiZQtnTMlJu/r05DFl/9CvQDPVxGx3UZS6mWiFqdauPJg9E0Lss5h mf4DZN8L2PgXn19QTVKjDtdr5e9b60iYPrDpTnA4RKu0RL7lM79pMzPBL3PDg8nI8vOO w1foW45IAa/GdXsPNo2Oa8/qreviwMHLT/m4Cl1Xxd7My5QWaU2jcu3qPj+ADvzlwX// PkAheVRsGCTavrHeIWJ/b+xPRf71sstAwle2NZbR/zVYzi8m8VWlP+aB3VO4k2AyCvKJ XiiiFO7vdYPI4jXIAbGQorqryXmhlgskFjTh9pDWwY7JbqXZ8lnw07L5Fj21QmeEgO10 XmOg== 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; bh=CZzupZYYCOHaBcsP51NF7E3lNz9arUaP/eq62M1rcRU=; b=t/eXPTD0OAz+FXdys7+KzuVWzyU3G5lhLgaHyhpSj01qCeQXpoo3fsCXrP5FC6haoX V76I2xpxispyJfHIuD/LwF2ouBrUqk87hEWciRs9FH4NCIlDMJYt5+QlpWHNDhJACnVQ EIFIWxjWFj/J8oFwDsEOJz8pL18c+i7ddOh6O2EaQmrQXppvhg6z0chgqBP+8SoJEiBl XEslMrULvOXVeUQPZcOgavR9zkkJvx++K1fQygVGrjEB+iKP49Mrw6Pjvv9txN/jLRaf uRr7g/TEQpeKsk7zBzk2TaVe5QB1lFcTiUye026WGmY6zD42Hlq/qXarBmrR6n//ND6U GI4g== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i16-20020a0564020f1000b0046b2840ca3dsi314056eda.474.2022.12.02.03.15.17; Fri, 02 Dec 2022 03:15:40 -0800 (PST) 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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232745AbiLBLEm (ORCPT <rfc822;lhua1029@gmail.com> + 99 others); Fri, 2 Dec 2022 06:04:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232740AbiLBLEh (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 2 Dec 2022 06:04:37 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5600BC5AD; Fri, 2 Dec 2022 03:04:35 -0800 (PST) Received: from canpemm500006.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NNqnL3QTyzRpvK; Fri, 2 Dec 2022 19:03:50 +0800 (CST) Received: from localhost.localdomain (10.175.104.82) by canpemm500006.china.huawei.com (7.192.105.130) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 2 Dec 2022 19:04:33 +0800 From: Ziyang Xuan <william.xuanziyang@huawei.com> To: <sgoutham@marvell.com>, <gakula@marvell.com>, <sbhatta@marvell.com>, <hkelam@marvell.com>, <davem@davemloft.net>, <edumazet@google.com>, <kuba@kernel.org>, <pabeni@redhat.com>, <netdev@vger.kernel.org> CC: <linux-kernel@vger.kernel.org> Subject: [PATCH net v2] octeontx2-pf: Fix potential memory leak in otx2_init_tc() Date: Fri, 2 Dec 2022 19:04:30 +0800 Message-ID: <20221202110430.1472991-1-william.xuanziyang@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.104.82] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500006.china.huawei.com (7.192.105.130) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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?1751100676643760084?= X-GMAIL-MSGID: =?utf-8?q?1751100676643760084?= |
Series |
[net,v2] octeontx2-pf: Fix potential memory leak in otx2_init_tc()
|
|
Commit Message
Ziyang Xuan
Dec. 2, 2022, 11:04 a.m. UTC
In otx2_init_tc(), if rhashtable_init() failed, it does not free
tc->tc_entries_bitmap which is allocated in otx2_tc_alloc_ent_bitmap().
Fixes: 2e2a8126ffac ("octeontx2-pf: Unify flow management variables")
Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>
---
v2:
- Remove patch 2 which is not a problem, see the following link:
https://www.spinics.net/lists/netdev/msg864159.html
---
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
Comments
On Fri, Dec 02, 2022 at 07:04:30PM +0800, Ziyang Xuan wrote: > In otx2_init_tc(), if rhashtable_init() failed, it does not free > tc->tc_entries_bitmap which is allocated in otx2_tc_alloc_ent_bitmap(). > > Fixes: 2e2a8126ffac ("octeontx2-pf: Unify flow management variables") > Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com> > --- > v2: > - Remove patch 2 which is not a problem, see the following link: > https://www.spinics.net/lists/netdev/msg864159.html > --- > drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c > index e64318c110fd..6a01ab1a6e6f 100644 > --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c > +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c > @@ -1134,7 +1134,12 @@ int otx2_init_tc(struct otx2_nic *nic) > return err; > > tc->flow_ht_params = tc_flow_ht_params; > - return rhashtable_init(&tc->flow_table, &tc->flow_ht_params); > + err = rhashtable_init(&tc->flow_table, &tc->flow_ht_params); > + if (err) { > + kfree(tc->tc_entries_bitmap); > + tc->tc_entries_bitmap = NULL; Why do you set NULL here? All callers of otx2_init_tc() unwind error properly. > + } > + return err; > } > EXPORT_SYMBOL(otx2_init_tc); > > -- > 2.25.1 >
> On Fri, Dec 02, 2022 at 07:04:30PM +0800, Ziyang Xuan wrote: >> In otx2_init_tc(), if rhashtable_init() failed, it does not free >> tc->tc_entries_bitmap which is allocated in otx2_tc_alloc_ent_bitmap(). >> >> Fixes: 2e2a8126ffac ("octeontx2-pf: Unify flow management variables") >> Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com> >> --- >> v2: >> - Remove patch 2 which is not a problem, see the following link: >> https://www.spinics.net/lists/netdev/msg864159.html >> --- >> drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c | 7 ++++++- >> 1 file changed, 6 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c >> index e64318c110fd..6a01ab1a6e6f 100644 >> --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c >> +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c >> @@ -1134,7 +1134,12 @@ int otx2_init_tc(struct otx2_nic *nic) >> return err; >> >> tc->flow_ht_params = tc_flow_ht_params; >> - return rhashtable_init(&tc->flow_table, &tc->flow_ht_params); >> + err = rhashtable_init(&tc->flow_table, &tc->flow_ht_params); >> + if (err) { >> + kfree(tc->tc_entries_bitmap); >> + tc->tc_entries_bitmap = NULL; > > Why do you set NULL here? All callers of otx2_init_tc() unwind error > properly. See the implementation of otx2_tc_alloc_ent_bitmap() as following: int otx2_tc_alloc_ent_bitmap(struct otx2_nic *nic) { struct otx2_tc_info *tc = &nic->tc_info; if (!nic->flow_cfg->max_flows) return 0; /* Max flows changed, free the existing bitmap */ kfree(tc->tc_entries_bitmap); ... } Hello Leon Romanovsky, It will kfree(tc->tc_entries_bitmap) firstly, and otx2_tc_alloc_ent_bitmap() is called by otx2_dl_mcam_count_set() and otx2_init_tc(). I am not sure their sequence and whether it will cause double free for tc->tc_entries_bitmap. So setting tc->tc_entries_bitmap to NULL is safe, I think. Thank you! > >> + } >> + return err; >> } >> EXPORT_SYMBOL(otx2_init_tc); >> >> -- >> 2.25.1 >> > . >
On Mon, Dec 05, 2022 at 10:31:02AM +0800, Ziyang Xuan (William) wrote: > > On Fri, Dec 02, 2022 at 07:04:30PM +0800, Ziyang Xuan wrote: > >> In otx2_init_tc(), if rhashtable_init() failed, it does not free > >> tc->tc_entries_bitmap which is allocated in otx2_tc_alloc_ent_bitmap(). > >> > >> Fixes: 2e2a8126ffac ("octeontx2-pf: Unify flow management variables") > >> Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com> > >> --- > >> v2: > >> - Remove patch 2 which is not a problem, see the following link: > >> https://www.spinics.net/lists/netdev/msg864159.html > >> --- > >> drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c | 7 ++++++- > >> 1 file changed, 6 insertions(+), 1 deletion(-) > >> > >> diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c > >> index e64318c110fd..6a01ab1a6e6f 100644 > >> --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c > >> +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c > >> @@ -1134,7 +1134,12 @@ int otx2_init_tc(struct otx2_nic *nic) > >> return err; > >> > >> tc->flow_ht_params = tc_flow_ht_params; > >> - return rhashtable_init(&tc->flow_table, &tc->flow_ht_params); > >> + err = rhashtable_init(&tc->flow_table, &tc->flow_ht_params); > >> + if (err) { > >> + kfree(tc->tc_entries_bitmap); > >> + tc->tc_entries_bitmap = NULL; > > > > Why do you set NULL here? All callers of otx2_init_tc() unwind error > > properly. > > See the implementation of otx2_tc_alloc_ent_bitmap() as following: > > int otx2_tc_alloc_ent_bitmap(struct otx2_nic *nic) > { > struct otx2_tc_info *tc = &nic->tc_info; > > if (!nic->flow_cfg->max_flows) > return 0; > > /* Max flows changed, free the existing bitmap */ > kfree(tc->tc_entries_bitmap); It is worthless call for probe() calls as tc->tc_entries_bitmap is always NULL at this point for them. The kfree(tc->tc_entries_bitmap); needs to be moved into otx2_dl_mcam_count_set() as it is the one place which can change bitmap. But ok, it is probably too much to request. Thanks, Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Hello: This patch was applied to netdev/net.git (master) by David S. Miller <davem@davemloft.net>: On Fri, 2 Dec 2022 19:04:30 +0800 you wrote: > In otx2_init_tc(), if rhashtable_init() failed, it does not free > tc->tc_entries_bitmap which is allocated in otx2_tc_alloc_ent_bitmap(). > > Fixes: 2e2a8126ffac ("octeontx2-pf: Unify flow management variables") > Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com> > --- > v2: > - Remove patch 2 which is not a problem, see the following link: > https://www.spinics.net/lists/netdev/msg864159.html > > [...] Here is the summary with links: - [net,v2] octeontx2-pf: Fix potential memory leak in otx2_init_tc() https://git.kernel.org/netdev/net/c/fbf33f5ac76f You are awesome, thank you!
diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c index e64318c110fd..6a01ab1a6e6f 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c @@ -1134,7 +1134,12 @@ int otx2_init_tc(struct otx2_nic *nic) return err; tc->flow_ht_params = tc_flow_ht_params; - return rhashtable_init(&tc->flow_table, &tc->flow_ht_params); + err = rhashtable_init(&tc->flow_table, &tc->flow_ht_params); + if (err) { + kfree(tc->tc_entries_bitmap); + tc->tc_entries_bitmap = NULL; + } + return err; } EXPORT_SYMBOL(otx2_init_tc);