net: enc28j60: cancel deferred works on remove to avoid use-after-free
Subsystems (3)
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).
--- drivers/net/ethernet/microchip/enc28j60.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/ethernet/microchip/enc28j60.c +3 -0
@@ -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
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_structsthat dereference the driver private data viacontainer_of():tx_work(queued fromndo_start_xmit),setrx_work(fromndo_set_rx_mode) andrestart_work(fromndo_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