Message ID | 20221115045028.182441-1-tanghui20@huawei.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a40e:b0:83:7221:86ba with SMTP id ck14csp3427548dyb; Mon, 14 Nov 2022 21:08:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf5CgHPk6702vQ4+0lXy3KiHjD69TSOKW0XvUPyZFgV0GFQwzqg0P8W5Nj+3zjkRMW9K/+YL X-Received: by 2002:a17:906:dfe4:b0:7ad:8bc6:46e7 with SMTP id lc4-20020a170906dfe400b007ad8bc646e7mr13590925ejc.28.1668488895043; Mon, 14 Nov 2022 21:08:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668488895; cv=none; d=google.com; s=arc-20160816; b=kTQZufSap/XP1Q4hwlLFbeGAfVHXrVtsdSCvAcs/InLL9J/rp4CfiryuDEBnIN95fX OTHIjtPH7SI/XIVUDOQn+TxXPsJ6thUZcgTMmMqc+CjfpDSm3M8wc2iyFU1Utek1OOeO AeQ7baoHGKoliZeo7DsKMoYyXMsnR46Gzxg+UNzIBByWdE1vjk5/m0UjSS550oU1PvlC bWAfTvSptrSMqiQ7WTPE6eybniopGE+7tNsyqRy4T5oiqu6rCl6r3qH7YQA5PgHAu7MI bDhhbXAdgu1ikrA/U7JfETy5TS6bDm1Km5KchzR1taS92Tjdbs6hTh0kd6wJDD3Ft13e OJog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=prMNeSNvvv1g/aw12lmQPbYL1X139q53lV3QJ6C0v0E=; b=YqbwZS9vjLV4FaGMWlK+2WCBmcTug1hAagA5TZDltSQMksMnIXaWG6pn3DMSFLwqVf 13jnFHnbYU0sLbhzFzoH0ewiBgUZwTuk9CYjUtn7DM5Oi6DXSpJsrggVGu8jS2OlhrEM e9n8IWoHay5QSFUFgaOA9lX04L8C5hxXAJntJ2Vv12QuQgdXVeJ+VLt2+DiZXnsxAzjd 3HD+b3cPbdGWtXU9AdxW01qgdJmvqpNB4W0OJNS7LBV1anXDfypMLQqVwZ6a29B/yp+c 4j+03n84VWYG0R3+D8S8UgmYTzB/b5sGttGeWP97LY4Hscnhqn7xoH4xATW02vEBdY5O fZeg== 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 xh14-20020a170906da8e00b0078dbd939dacsi10634429ejb.545.2022.11.14.21.07.36; Mon, 14 Nov 2022 21:08:15 -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 S232158AbiKOExq (ORCPT <rfc822;zwp10758@gmail.com> + 99 others); Mon, 14 Nov 2022 23:53:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232118AbiKOExo (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 14 Nov 2022 23:53:44 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F25A63D3; Mon, 14 Nov 2022 20:53:44 -0800 (PST) Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4NBDMj2Sc0z15MMt; Tue, 15 Nov 2022 12:53:21 +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; Tue, 15 Nov 2022 12:53:41 +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; Tue, 15 Nov 2022 12:53:40 +0800 From: Hui Tang <tanghui20@huawei.com> To: <davem@davemloft.net>, <edumazet@google.com>, <kuba@kernel.org>, <mw@semihalf.com>, <linux@armlinux.org.uk>, <andrew@lunn.ch>, <pabeni@redhat.com> CC: <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <yusongping@huawei.com> Subject: [PATCH] net: mdio-ipq4019: fix possible invalid pointer dereference Date: Tue, 15 Nov 2022 12:50:28 +0800 Message-ID: <20221115045028.182441-1-tanghui20@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.175.30] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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?1749537411846688266?= X-GMAIL-MSGID: =?utf-8?q?1749537411846688266?= |
Series |
net: mdio-ipq4019: fix possible invalid pointer dereference
|
|
Commit Message
Hui Tang
Nov. 15, 2022, 4:50 a.m. UTC
priv->eth_ldo_rdy is saved the return value of devm_ioremap_resource(),
which !IS_ERR() should be used to check.
Fixes: 23a890d493e3 ("net: mdio: Add the reset function for IPQ MDIO driver")
Signed-off-by: Hui Tang <tanghui20@huawei.com>
---
drivers/net/mdio/mdio-ipq4019.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Tue, Nov 15, 2022 at 12:50:28PM +0800, Hui Tang wrote: > priv->eth_ldo_rdy is saved the return value of devm_ioremap_resource(), > which !IS_ERR() should be used to check. > > Fixes: 23a890d493e3 ("net: mdio: Add the reset function for IPQ MDIO driver") > Signed-off-by: Hui Tang <tanghui20@huawei.com> > --- > drivers/net/mdio/mdio-ipq4019.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/net/mdio/mdio-ipq4019.c b/drivers/net/mdio/mdio-ipq4019.c > index 4eba5a91075c..d7a1f7c56f97 100644 > --- a/drivers/net/mdio/mdio-ipq4019.c > +++ b/drivers/net/mdio/mdio-ipq4019.c > @@ -188,7 +188,7 @@ static int ipq_mdio_reset(struct mii_bus *bus) > /* To indicate CMN_PLL that ethernet_ldo has been ready if platform resource 1 > * is specified in the device tree. > */ > - if (priv->eth_ldo_rdy) { > + if (!IS_ERR(priv->eth_ldo_rdy)) { > val = readl(priv->eth_ldo_rdy); > val |= BIT(0); > writel(val, priv->eth_ldo_rdy); There is a general pattern in the kernel that optional things are set to NULL if the resource does not exist. Often there is a get_foo_optional() which will return a NULL point if the things does not exist, the thing if it does exist, or an error code if a real error happened. So please follow this patterns. Check the return value in ipq4019_mdio_probe(). Looking at __devm_ioremap_resource() i _think_ it returns -ENOMEM if the resource does not exist? So maybe any other error is a real error, and should be reported, and -ENOMEM should result in eth_ldo_rdy set to NULL? Andrew
On 2022/11/15 21:36, Andrew Lunn wrote: > On Tue, Nov 15, 2022 at 12:50:28PM +0800, Hui Tang wrote: >> priv->eth_ldo_rdy is saved the return value of devm_ioremap_resource(), >> which !IS_ERR() should be used to check. >> >> Fixes: 23a890d493e3 ("net: mdio: Add the reset function for IPQ MDIO driver") >> Signed-off-by: Hui Tang <tanghui20@huawei.com> >> --- >> drivers/net/mdio/mdio-ipq4019.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/drivers/net/mdio/mdio-ipq4019.c b/drivers/net/mdio/mdio-ipq4019.c >> index 4eba5a91075c..d7a1f7c56f97 100644 >> --- a/drivers/net/mdio/mdio-ipq4019.c >> +++ b/drivers/net/mdio/mdio-ipq4019.c >> @@ -188,7 +188,7 @@ static int ipq_mdio_reset(struct mii_bus *bus) >> /* To indicate CMN_PLL that ethernet_ldo has been ready if platform resource 1 >> * is specified in the device tree. >> */ >> - if (priv->eth_ldo_rdy) { >> + if (!IS_ERR(priv->eth_ldo_rdy)) { >> val = readl(priv->eth_ldo_rdy); >> val |= BIT(0); >> writel(val, priv->eth_ldo_rdy); > > There is a general pattern in the kernel that optional things are set > to NULL if the resource does not exist. Often there is a > get_foo_optional() which will return a NULL point if the things does > not exist, the thing if it does exist, or an error code if a real > error happened. > > So please follow this patterns. Check the return value in > ipq4019_mdio_probe(). Looking at __devm_ioremap_resource() i _think_ > it returns -ENOMEM if the resource does not exist? So maybe any other > error is a real error, and should be reported, and -ENOMEM should > result in eth_ldo_rdy set to NULL? Thanks, I will resend it according to the style you said.
diff --git a/drivers/net/mdio/mdio-ipq4019.c b/drivers/net/mdio/mdio-ipq4019.c index 4eba5a91075c..d7a1f7c56f97 100644 --- a/drivers/net/mdio/mdio-ipq4019.c +++ b/drivers/net/mdio/mdio-ipq4019.c @@ -188,7 +188,7 @@ static int ipq_mdio_reset(struct mii_bus *bus) /* To indicate CMN_PLL that ethernet_ldo has been ready if platform resource 1 * is specified in the device tree. */ - if (priv->eth_ldo_rdy) { + if (!IS_ERR(priv->eth_ldo_rdy)) { val = readl(priv->eth_ldo_rdy); val |= BIT(0); writel(val, priv->eth_ldo_rdy);