Skip to contentSkip to conversation

net: Keep MDIO resources until netdev removal completes

PATCH In review Guangshuo Li 4 participants 8 messages Nov 17 – Nov 19

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover net: Keep MDIO resources until netdev removal completes

Unregister the Altera and Emaclite network devices while the MDIO bus is still available to detach the PHY.

Guangshuo Li (2):
net: altera: Fix potential use-after-free on removal
net: emaclite: Fix potential use-after-free during removal

 drivers/net/ethernet/altera/altera_tse_main.c | 2 +-
 drivers/net/ethernet/xilinx/xilinx_emaclite.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4

Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/2 net: altera: Fix potential use-after-free on removal

Destroying the MDIO bus before unregistering a running network device leaves its PHY attached to a freed bus. The subsequent shutdown path calls phylink_disconnect_phy(), which can access that bus.

Unregister the network device before destroying the MDIO bus.

This issue was found by our static analysis tool under development.

Fixes bbd2190ce96d ("Altera TSE: Add main and header file for Altera Ethernet Driver")
---
 drivers/net/ethernet/altera/altera_tse_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/altera/altera_tse_main.c +1 -1
index 9eed0be4411e..e203f9fcb5d7 100644
@@ -1461,8 +1461,8 @@ static void altera_tse_remove(struct platform_device *pdev)
 	struct altera_tse_private *priv = netdev_priv(ndev);
 
 	platform_set_drvdata(pdev, NULL);
-	altera_tse_mdio_destroy(ndev);
 	unregister_netdev(ndev);
+	altera_tse_mdio_destroy(ndev);
 	phylink_destroy(priv->phylink);
 	lynx_pcs_destroy(priv->pcs);
 
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH net 1/2] net: altera: Fix potential use-after-free on removal

Quoted 1 line
Fixes bbd2190ce96d ("Altera TSE: Add main and header file for Altera Ethernet Driver")

The usual question: Does this bother anybody?

If not, net-next, no Fixes:

Andrew

---
pw-bot: cr

maintainer
#3 lore raw

Re: [PATCH net 1/2] net: altera: Fix potential use-after-free on removal

Hi,

Quoted 4 lines

The usual question: Does this bother anybody?
If not, net-next, no Fixes:
    Andrew
---

Sorry for the late reply. Reviewed, no concerns from my side. Thanks.

author
#4 lore raw

Re:Re: [PATCH net 1/2] net: altera: Fix potential use-after-free on removal

In reply to Andrew Lunn

Hi Andrew,

Thanks for the review.

From: Andrew Lunn <[email protected]>
Date: 2026-11-18 02:05:30
To: Guangshuo Li <[email protected]>
Cc: Boon Khai Ng <[email protected]>,Andrew Lunn <[email protected]>,"David S. Miller" <[email protected]>,Eric Dumazet <[email protected]>,Jakub Kicinski <[email protected]>,Paolo Abeni <[email protected]>,Michal Simek <[email protected]>,[email protected],[email protected],[email protected]
Subject: Re: [PATCH net 1/2] net: altera: Fix potential use-after-free on removal>> Fixes: bbd2190ce96d ("Altera TSE: Add main and header file for Altera Ethernet Driver")

Quoted 10 lines

The usual question: Does this bother anybody?

If not, net-next, no Fixes:

Andrew

---
pw-bot: cr

I found this by reading the remove path. I don't have a user report or a reproduction on Altera hardware.

Given that, would you prefer the Altera patch on its own for net-next, without the Fixes tag? If so, I'll resend it that way.

Thanks,
Guangshuo

#6 lore raw

PATCH 2/2 net: emaclite: Fix potential use-after-free during removal

In reply to Guangshuo Li

xemaclite_of_remove() frees the MDIO bus before unregistering the network device. If the interface is up, unregister_netdev() calls xemaclite_close(), whose phy_disconnect() still accesses that bus. This can cause a use-after-free during PHY detachment.

Unregister the network device first so that PHY detachment finishes before the MDIO bus is unregistered and freed.

This issue was found by our static analysis tool under development.

Fixes 27cad0084066 ("net: emaclite: Fix MDIO bus unregister bug")
---
 drivers/net/ethernet/xilinx/xilinx_emaclite.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/xilinx/xilinx_emaclite.c +2 -2
index 4719d40a63ba..008e3d1e2981 100644
@@ -1189,6 +1189,8 @@ static void xemaclite_of_remove(struct platform_device *of_dev)
 
 	struct net_local *lp = netdev_priv(ndev);
 
+	unregister_netdev(ndev);
+
 	/* Un-register the mii_bus, if configured */
 	if (lp->mii_bus) {
 		mdiobus_unregister(lp->mii_bus);
@@ -1196,8 +1198,6 @@ static void xemaclite_of_remove(struct platform_device *of_dev)
 		lp->mii_bus = NULL;
 	}
 
-	unregister_netdev(ndev);
-
 	of_node_put(lp->phy_node);
 	lp->phy_node = NULL;
 }
Signature · 1 line
2.43.0
#7 lore raw
In reply to Guangshuo Li
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- What hardware the change was tested on. For driver fixes please mention the device (and if relevant firmware version) used for testing, or say that the change was not tested on real hardware.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.

Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.