🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
2 messages
2 total messages Started by hyunjungg Sat, 07 Nov 2026 14:06
[PATCH net] net: enc28j60: cancel deferred works on remove to avoid use-after-free
#12490
Author: hyunjungg
Date: Sat, 07 Nov 2026 14:06
48 lines
12412 bytes
From: Hyunjung Ko <hj351016@gmail.com>

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")
Cc: stable@vger.kernel.org
Signed-off-by: Hyunjung Ko <hj351016@gmail.com>
---
 drivers/net/ethernet/microchip/enc28j60.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/ethernet/microchip/enc28j60.c b/drivers/net/ethernet/microchip/enc28j60.c
index d6c9491..5266912 100644
--- a/drivers/net/ethernet/microchip/enc28j60.c
+++ b/drivers/net/ethernet/microchip/enc28j60.c
@@ -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);
 }
 
-- 
2.43.0
Re: [PATCH net] net: enc28j60: cancel deferred works on remove to avoid use-after-free
#14825
Author: patchwork-bot+netdevbpf
Date: Thu, 12 Nov 2026 01:30
24 lines
8623 bytes
Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Sat,  7 Nov 2026 23:06:49 +0900 you wrote:
> From: Hyunjung Ko <hj351016@gmail.com>
> 
> 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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads