Message ID | 20221116021437.145204-1-tanghui20@huawei.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3052447wru; Tue, 15 Nov 2022 18:23:43 -0800 (PST) X-Google-Smtp-Source: AA0mqf50//PomeCo9ILoZqK7j86Epnqz7ytXzm9C+kv0k/LWVzY7RlQq/RU+lat37J7athlDEnZX X-Received: by 2002:a17:90a:b946:b0:215:db2e:bb17 with SMTP id f6-20020a17090ab94600b00215db2ebb17mr1348450pjw.166.1668565423045; Tue, 15 Nov 2022 18:23:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668565423; cv=none; d=google.com; s=arc-20160816; b=Hr7Eyew6uE54mhi0irSeoh7iU4L1SiB3NrxbHKP+Ccy+keV4CvvIWqqpmPcuCYJ1c8 YOXNhImo/9V1uaBGw3oPy8H9zy3BcJHGUDORFyZe3600cinWqxfJ98lQGQ+NAKFe+iCp BVuJ2QI6LKNtEWIlnm61q1OzbuTnU/UGXuKuTJ/HrEEeK71bFfmSRNMFYaCLKwmkNTD8 rbbJ2BWHND5e/gVRYNwQhiHoA2IbVcjsLwEzrdMU7m2qiRj1ypBvcqRTBwOTnah1W4vD 0Q7A+KfHgWDPrsHvGtwNssOrw+VWxd52Nsg2wVoCcXAgLNZ1LfEPu6/lw3mALid9J4yX cXjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=EwAdeaIJq1MUaSv/3vH8a5I3Zw4fn2MHQ09F2tTFLn4=; b=c6bdvRSPqzPXuYD9a6k9XtWRuKhk5lO+vO5sh7ZuEfx2+/xELPAsnloS7O0AK020cX 8ffH1qkSxsb5t/WiMmyoNpBVC722CGoUU1S6ZVgqE6jr5VwLYmWUbniKBWtJ56RCIw6t lZNLBfpk5PC+LwC3tThXDE/az6CBEarNw8BWEGvg0ihootcOGEP3vBBY0WUYPm4tLsZl NmWQ0ZnAVp08PBURkcv8ZAOXhQrqEK7zAJ+Wwd2kWdmScEklwo4qf7wV9fgbzVOcL3+f yh94EMordSHQvWtbKiIpcE7zkTGUbU0hs4pwZzOzVZvofi+sH6Ifa/U3A3GGt2FoqJYg cNOw== 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 k8-20020a635a48000000b0046fabcb514csi14285372pgm.143.2022.11.15.18.23.29; Tue, 15 Nov 2022 18:23:43 -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 S231441AbiKPCR5 (ORCPT <rfc822;maxim.cournoyer@gmail.com> + 99 others); Tue, 15 Nov 2022 21:17:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230238AbiKPCRv (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 15 Nov 2022 21:17:51 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FEA731DF4; Tue, 15 Nov 2022 18:17:50 -0800 (PST) Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4NBmsM0kzJz15Mgn; Wed, 16 Nov 2022 10:17:27 +0800 (CST) Received: from kwepemm600005.china.huawei.com (7.193.23.191) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 16 Nov 2022 10:17:48 +0800 Received: from ubuntu1804.huawei.com (10.67.175.30) by kwepemm600005.china.huawei.com (7.193.23.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 16 Nov 2022 10:17:47 +0800 From: Hui Tang <tanghui20@huawei.com> To: <davem@davemloft.net>, <edumazet@google.com>, <kuba@kernel.org>, <mw@semihalf.com>, <linux@armlinux.org.uk>, <leon@kernel.org>, <andrew@lunn.ch> CC: <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <yusongping@huawei.com> Subject: [PATCH net v4] net: mvpp2: fix possible invalid pointer dereference Date: Wed, 16 Nov 2022 10:14:37 +0800 Message-ID: <20221116021437.145204-1-tanghui20@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221116020617.137247-1-tanghui20@huawei.com> References: <20221116020617.137247-1-tanghui20@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.175.30] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemm600005.china.huawei.com (7.193.23.191) 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?1749536455467972152?= X-GMAIL-MSGID: =?utf-8?q?1749617656570925467?= |
Series |
[net,v4] net: mvpp2: fix possible invalid pointer dereference
|
|
Commit Message
Hui Tang
Nov. 16, 2022, 2:14 a.m. UTC
It will cause invalid pointer dereference to priv->cm3_base behind,
if PTR_ERR(priv->cm3_base) in mvpp2_get_sram().
Fixes: a59d354208a7 ("net: mvpp2: enable global flow control")
Signed-off-by: Hui Tang <tanghui20@huawei.com>
---
v1 -> v2: patch title include target
v2 -> v3: keep priv->cm3_base NULL if devm_ioremap_resource() failed
v3 -> v4: change if (priv->cm3_base) to if (base)
---
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
Comments
On Wed, 16 Nov 2022 10:14:37 +0800 Hui Tang wrote: > It will cause invalid pointer dereference to priv->cm3_base behind, > if PTR_ERR(priv->cm3_base) in mvpp2_get_sram(). > > Fixes: a59d354208a7 ("net: mvpp2: enable global flow control") > Signed-off-by: Hui Tang <tanghui20@huawei.com> Please do not repost new versions so often: https://www.kernel.org/doc/html/next/process/maintainer-netdev.html#tl-dr do not use --in-reply-to > diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c > index d98f7e9a480e..efb582b63640 100644 > --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c > +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c > @@ -7349,6 +7349,7 @@ static int mvpp2_get_sram(struct platform_device *pdev, > struct mvpp2 *priv) > { > struct resource *res; > + void __iomem *base; > > res = platform_get_resource(pdev, IORESOURCE_MEM, 2); > if (!res) { > @@ -7359,9 +7360,11 @@ static int mvpp2_get_sram(struct platform_device *pdev, > return 0; > } > > - priv->cm3_base = devm_ioremap_resource(&pdev->dev, res); > + base = devm_ioremap_resource(&pdev->dev, res); > + if (!IS_ERR(base)) > + priv->cm3_base = base; > > - return PTR_ERR_OR_ZERO(priv->cm3_base); > + return PTR_ERR_OR_ZERO(base); Use the idiomatic error handling, keep success path un-indented: ptr = function(); if (IS_ERR(ptr)) return PTR_ERR(ptr); priv->bla = ptr; return 0;
On 2022/11/16 12:28, Jakub Kicinski wrote: > On Wed, 16 Nov 2022 10:14:37 +0800 Hui Tang wrote: >> It will cause invalid pointer dereference to priv->cm3_base behind, >> if PTR_ERR(priv->cm3_base) in mvpp2_get_sram(). >> >> Fixes: a59d354208a7 ("net: mvpp2: enable global flow control") >> Signed-off-by: Hui Tang <tanghui20@huawei.com> > > Please do not repost new versions so often: > > https://www.kernel.org/doc/html/next/process/maintainer-netdev.html#tl-dr > > do not use --in-reply-to Thanks for pointing out, but should I resend it with [PATCH net v3] or [PATCH net v5]? >> diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c >> index d98f7e9a480e..efb582b63640 100644 >> --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c >> +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c >> @@ -7349,6 +7349,7 @@ static int mvpp2_get_sram(struct platform_device *pdev, >> struct mvpp2 *priv) >> { >> struct resource *res; >> + void __iomem *base; >> >> res = platform_get_resource(pdev, IORESOURCE_MEM, 2); >> if (!res) { >> @@ -7359,9 +7360,11 @@ static int mvpp2_get_sram(struct platform_device *pdev, >> return 0; >> } >> >> - priv->cm3_base = devm_ioremap_resource(&pdev->dev, res); >> + base = devm_ioremap_resource(&pdev->dev, res); >> + if (!IS_ERR(base)) >> + priv->cm3_base = base; >> >> - return PTR_ERR_OR_ZERO(priv->cm3_base); >> + return PTR_ERR_OR_ZERO(base); > > Use the idiomatic error handling, keep success path un-indented: > > ptr = function(); > if (IS_ERR(ptr)) > return PTR_ERR(ptr); > > priv->bla = ptr; > return 0; > > Ok, I will fix it in next version
> Thanks for pointing out, but should I resend it with [PATCH net v3] > or [PATCH net v5]? The number should always increment. It is how we tell older versions from newer versions. Andrew
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c index d98f7e9a480e..efb582b63640 100644 --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c @@ -7349,6 +7349,7 @@ static int mvpp2_get_sram(struct platform_device *pdev, struct mvpp2 *priv) { struct resource *res; + void __iomem *base; res = platform_get_resource(pdev, IORESOURCE_MEM, 2); if (!res) { @@ -7359,9 +7360,11 @@ static int mvpp2_get_sram(struct platform_device *pdev, return 0; } - priv->cm3_base = devm_ioremap_resource(&pdev->dev, res); + base = devm_ioremap_resource(&pdev->dev, res); + if (!IS_ERR(base)) + priv->cm3_base = base; - return PTR_ERR_OR_ZERO(priv->cm3_base); + return PTR_ERR_OR_ZERO(base); } static int mvpp2_probe(struct platform_device *pdev)