Skip to contentSkip to conversation

net: enc28j60: cancel deferred works on remove to avoid use-after-free

PATCH Applied hyunjungg 2 participants 2 messages Nov 7 – Nov 12

Subsystems (3)
lore
Share & tools
lore

hyunjungg

author
#0 lore raw

PATCH 1/1 net: enc28j60: cancel deferred works on remove to avoid use-after-free

From: Hyunjung Ko <[email protected]>

enc28j60 defers work to three work_structs that dereference the driver private data via container_of(): tx_work (queued from ndo_start_xmit), setrx_work (from ndo_set_rx_mode) and restart_work (from ndo_tx_timeout). They run on the system workqueue and are never cancelled.

enc28j60_remove() calls unregister_netdev(), then free_irq(), then free_netdev(). unregister_netdev() brings the interface down so no new work is scheduled, but it does not cancel a work that was already queued from an xmit, rx-mode change or TX timeout shortly before the device went down. priv is netdev_priv() memory and is freed by free_netdev(), so a still-pending work then runs enc28j60_tx_work_handler() / enc28j60_setrx_work_handler() / enc28j60_restart_work_handler() against freed memory (use-after-free).

Cancel the three works after unregister_netdev() (which guarantees no new scheduling) and before free_netdev(), while priv is still valid. The handlers do not re-queue themselves or each other, so cancelling each once is sufficient.

Found by static analysis and code review; not tested on real hardware (needs an ENC28J60 SPI Ethernet device).

Fixes 3ec9c11da033 ("add driver for enc28j60 ethernet chip")
---
 drivers/net/ethernet/microchip/enc28j60.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/ethernet/microchip/enc28j60.c +3 -0
index d6c9491..5266912 100644
@@ -1602,6 +1602,9 @@ static void enc28j60_remove(struct spi_device *spi)
 
 	unregister_netdev(priv->netdev);
 	free_irq(spi->irq, priv);
+	cancel_work_sync(&priv->tx_work);
+	cancel_work_sync(&priv->setrx_work);
+	cancel_work_sync(&priv->restart_work);
 	free_netdev(priv->netdev);
 }
 
Signature · 1 line
2.43.0
#1 lore raw
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Sat, 7 Nov 2026 23:06:49 +0900 you wrote:

From: Hyunjung Ko <[email protected]>

enc28j60 defers work to three work_structs that dereference the driver private data via container_of(): tx_work (queued from ndo_start_xmit), setrx_work (from ndo_set_rx_mode) and restart_work (from ndo_tx_timeout). They run on the system workqueue and are never cancelled.

[...]

Here is the summary with links:
- [net] net: enc28j60: cancel deferred works on remove to avoid use-after-free

    https://git.kernel.org/netdev/net-next/c/bafe532bae92

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html