[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241028-ftgmac-fixes-v1-1-b334a507be6c@codeconstruct.com.au>
Date: Mon, 28 Oct 2024 12:54:10 +0800
From: Jeremy Kerr <jk@...econstruct.com.au>
To: Andrew Lunn <andrew+netdev@...n.ch>,
"David S. Miller" <davem@...emloft.net>, Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
Joel Stanley <joel@....id.au>, Jacky Chou <jacky_chou@...eedtech.com>,
Jacob Keller <jacob.e.keller@...el.com>
Cc: netdev@...r.kernel.org
Subject: [PATCH net 1/2] net: ethernet: ftgmac100: prevent use after free
on unregister when using NCSI
When removing an active ftgmac100 netdev that is configured for NCSI, we
have a double free of the ncsi device: We currently unregister the ncsi
device (freeing it), then unregister the netdev itself. If the netdev is
running, the netdev_unregister() path performs a ->ndo_stop(), which
calls ncsi_stop_dev() on the now-free ncsi pointer.
Instead, modify ftgmac100_stop() to check the ncsi pointer before
freeing (rather than use_ncsi, which reflects configuration intent), and
clear the pointer once we have done the ncsi_unregister().
Fixes: 3d5179458d22 ("net: ftgmac100: Fix crash when removing driver")
Signed-off-by: Jeremy Kerr <jk@...econstruct.com.au>
---
drivers/net/ethernet/faraday/ftgmac100.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
index 0b61f548fd188f64344ff67136c882a49598f6d3..9caee68468ff5f71d7ea63a0c8c9ec2be4a718bc 100644
--- a/drivers/net/ethernet/faraday/ftgmac100.c
+++ b/drivers/net/ethernet/faraday/ftgmac100.c
@@ -1599,7 +1599,7 @@ static int ftgmac100_stop(struct net_device *netdev)
netif_napi_del(&priv->napi);
if (netdev->phydev)
phy_stop(netdev->phydev);
- if (priv->use_ncsi)
+ if (priv->ndev)
ncsi_stop_dev(priv->ndev);
ftgmac100_stop_hw(priv);
@@ -2059,8 +2059,10 @@ static void ftgmac100_remove(struct platform_device *pdev)
netdev = platform_get_drvdata(pdev);
priv = netdev_priv(netdev);
- if (priv->ndev)
+ if (priv->ndev) {
ncsi_unregister_dev(priv->ndev);
+ priv->ndev = NULL;
+ }
unregister_netdev(netdev);
clk_disable_unprepare(priv->rclk);
--
2.39.2
Powered by blists - more mailing lists