lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <81e35682-ee80-4ac7-8b6b-07ebb2a68e3f@stanley.mountain>
Date: Tue, 10 Sep 2024 10:42:02 +0300
From: Dan Carpenter <dan.carpenter@...aro.org>
To: Jacky Chou <jacky_chou@...eedtech.com>
Cc: Andrew Lunn <andrew@...n.ch>, "David S. Miller" <davem@...emloft.net>,
	Eric Dumazet <edumazet@...gle.com>,
	Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
	Uwe Kleine-König <u.kleine-koenig@...gutronix.de>,
	Jacob Keller <jacob.e.keller@...el.com>,
	"netdev@...r.kernel.org" <netdev@...r.kernel.org>,
	"kernel-janitors@...r.kernel.org" <kernel-janitors@...r.kernel.org>
Subject: Re: 回覆: 回覆: [PATCH net-next] net: ftgmac100: Fix potential NULL
 dereference in error handling

On Tue, Sep 10, 2024 at 06:19:54AM +0000, Jacky Chou wrote:
> Hello, Dan
> 
> > On Mon, Sep 09, 2024 at 02:03:32PM +0200, Andrew Lunn wrote:
> > > > > Are you actually saying:
> > > > >
> > > > >         if (netdev->phydev) {
> > > > >                 /* If we have a PHY, start polling */
> > > > >                 phy_start(netdev->phydev);
> > > > >         }
> > > > >
> > > > > is wrong, it is guaranteed there is always a phydev?
> > > > >
> > > > This patch is focus on error handling when using NC-SI at open stage.
> > > >
> > > >          if (netdev->phydev) {
> > > >                  /* If we have a PHY, start polling */
> > > >                  phy_start(netdev->phydev);
> > > >          }
> > > >
> > > > This code is used to check the other cases.
> > > > Perhaps, phy-handle or fixed-link property are not added in DTS.
> > >
> > > I'm guessing, but i think the static analysers see this condition, and
> > > deducing that phydev might be a NULL. Hence when phy_stop() is called,
> > > it needs the check.
> > >
> > > You say the static analyser is wrong, probably because it cannot check
> > > the bigger context. It can be NULL for phy_start() but not for
> > > phy_stop(). Maybe you can give it some more hints?
> > >
> > > Dan, is this Smatch? Is it possible to dump the paths through the code
> > > where it thinks it might be NULL?
> > 
> > Adding a check here is the correct thing.  The current code works because we
> > only have the one goto after the call to phy_start(netdev->phydev), but as soon
> > as we add a second goto then it will crash.
> 
> Could you share more detail about the crash is happening when you add a second goto?
> I'm wondering if there are other things I missed.

I'm saying if we add a feature in the future.  Something like this.

regards,
dan carpenter

diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
index f3cc14cc757d..417c7f4dd471 100644
--- a/drivers/net/ethernet/faraday/ftgmac100.c
+++ b/drivers/net/ethernet/faraday/ftgmac100.c
@@ -1562,10 +1562,22 @@ static int ftgmac100_open(struct net_device *netdev)
 			goto err_ncsi;
 	}
 
+	ret = some_new_feature();
+	if (ret)
+		goto err_free_ncsi;
+
 	return 0;
 
+err_free_ncsi:
+	if (priv->use_ncsi)
+		ncsi_stop_dev(priv->ndev);
 err_ncsi:
 	phy_stop(netdev->phydev);
                 ^^^^^^^^^^^^^^
Crash.

 	napi_disable(&priv->napi);
 	netif_stop_queue(netdev);
 err_alloc:

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ