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

Guangshuo Li liguangshuo at mail.sdu.edu.cn
Tue Nov 17 06:45:18 PST 2026


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")
Cc: stable at vger.kernel.org
Signed-off-by: Guangshuo Li <liguangshuo at mail.sdu.edu.cn>
---
 drivers/net/ethernet/xilinx/xilinx_emaclite.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/xilinx/xilinx_emaclite.c b/drivers/net/ethernet/xilinx/xilinx_emaclite.c
index 4719d40a63ba..008e3d1e2981 100644
--- a/drivers/net/ethernet/xilinx/xilinx_emaclite.c
+++ b/drivers/net/ethernet/xilinx/xilinx_emaclite.c
@@ -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;
 }
-- 
2.43.0




More information about the linux-arm-kernel mailing list