🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
2 messages
2 total messages Started by SeungJong Ha Sat, 28 Nov 2026 11:14
[PATCH] e100: fix use-after-free of the CB list in e100_clean_cbs()
#23846
Author: SeungJong Ha
Date: Sat, 28 Nov 2026 11:14
125 lines
15466 bytes
ndo_set_rx_mode() can run without RTNL. An unprivileged IPv6 multicast
join reaches it that way since commit 1767bb2d47b7 ("ipv6: mcast: Don't
hold RTNL for IPV6_ADD_MEMBERSHIP and MCAST_JOIN_GROUP."):

  setsockopt(IPV6_JOIN_GROUP)
    __ipv6_sock_mc_join()
      dev_mc_add()
        e100_set_multicast_list()
          e100_exec_cb()

e100_exec_cb() queues a CB under cb_lock if cbs_avail is non-zero.
e100_clean_cbs() frees the CB list without cb_lock and zeroes cbs_avail
only afterwards, so a concurrent e100_exec_cb() writes to freed CBs.
This hits every e100_down(), not only ndo_stop.

Looping IPV6_JOIN_GROUP/IPV6_LEAVE_GROUP as an unprivileged user while
toggling the link down and up crashes within seconds (QEMU -device
i82557b, SLUB_DEBUG_ON):

  Oops: general protection fault, ... address 0xf4f4f0f4f4f4f53a
  KASAN: maybe wild-memory-access in range [0xa7a7a7a7a7a7a9d0-...]
  RIP: 0010:e100_exec_cb+0x219/0x410
  Call Trace:
   e100_set_multicast_list+0xf1/0x2b0
   dev_mc_add+0xb3/0x100
   igmp6_group_added+0x145/0x5e0
   __ipv6_dev_mc_inc+0x60e/0x8a0
   __ipv6_sock_mc_join+0x3da/0x620
   do_ipv6_setsockopt+0x16cf/0x1f80

Clear cbs_avail under cb_lock before freeing the list, so a later
e100_exec_cb() fails with -ENOMEM, and publish a new list in
e100_alloc_cbs() under cb_lock as well, so cbs_avail is never seen
before the list pointers.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: SeungJong Ha <engineer.jjhama@gmail.com>
---
Fixes points at the initial import: dev_mc_add() was called without
RTNL before 1767bb2d47b7 too (rxe, DSA, and IPv6 itself before v3.17).

I found this with a prototype static analysis tool I am developing. It
flags drivers whose ndo_set_rx_mode() and ndo_stop() share no lock
while ndo_stop() frees state.

The analysis, the reproducer and the fix were written with Claude Code
(Claude Opus 5.5). I reviewed every line of the patch and the commit
message, and re-ran the reproducer myself.

The tool flags more legacy ndo_set_rx_mode() drivers with the same
pattern; tulip is also confirmed in QEMU. Would a core change that keeps
ndo_set_rx_mode() from running concurrently with ndo_stop() be preferred
over fixing drivers one by one? This patch is needed either way, since
e100 also frees the list in its other e100_down() paths.

Tested in QEMU (-device i82557b) only. Before: 5/5 runs crash within
seconds. After: 0/5 in 5 x 120 s (12,809 down/up cycles). No real
8255x hardware was tested.
---
 drivers/net/ethernet/intel/e100.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/intel/e100.c b/drivers/net/ethernet/intel/e100.c
index 29960762e64a..7923239a2b35 100644
--- a/drivers/net/ethernet/intel/e100.c
+++ b/drivers/net/ethernet/intel/e100.c
@@ -1849,8 +1849,16 @@ static int e100_tx_clean(struct nic *nic)
 
 static void e100_clean_cbs(struct nic *nic)
 {
+	unsigned int avail;
+	unsigned long flags;
+
+	spin_lock_irqsave(&nic->cb_lock, flags);
+	avail = nic->cbs_avail;
+	nic->cbs_avail = 0;
+	spin_unlock_irqrestore(&nic->cb_lock, flags);
+
 	if (nic->cbs) {
-		while (nic->cbs_avail != nic->params.cbs.count) {
+		while (avail != nic->params.cbs.count) {
 			struct cb *cb = nic->cb_to_clean;
 			if (cb->skb) {
 				dma_unmap_single(&nic->pdev->dev,
@@ -1860,11 +1868,10 @@ static void e100_clean_cbs(struct nic *nic)
 				dev_kfree_skb(cb->skb);
 			}
 			nic->cb_to_clean = nic->cb_to_clean->next;
-			nic->cbs_avail++;
+			avail++;
 		}
 		dma_pool_free(nic->cbs_pool, nic->cbs, nic->cbs_dma_addr);
 		nic->cbs = NULL;
-		nic->cbs_avail = 0;
 	}
 	nic->cuc_cmd = cuc_start;
 	nic->cb_to_use = nic->cb_to_send = nic->cb_to_clean =
@@ -1875,6 +1882,7 @@ static int e100_alloc_cbs(struct nic *nic)
 {
 	struct cb *cb;
 	unsigned int i, count = nic->params.cbs.count;
+	unsigned long flags;
 
 	nic->cuc_cmd = cuc_start;
 	nic->cb_to_use = nic->cb_to_send = nic->cb_to_clean = NULL;
@@ -1894,8 +1902,10 @@ static int e100_alloc_cbs(struct nic *nic)
 			((i+1) % count) * sizeof(struct cb));
 	}
 
+	spin_lock_irqsave(&nic->cb_lock, flags);
 	nic->cb_to_use = nic->cb_to_send = nic->cb_to_clean = nic->cbs;
 	nic->cbs_avail = count;
+	spin_unlock_irqrestore(&nic->cb_lock, flags);
 
 	return 0;
 }

---
base-commit: d4a07bc573c33e72a69445741f53b9105579328a
change-id: 20261127-e100-cbs-uaf-05d7259c64b1

Best regards,
--  
SeungJong Ha <engineer.jjhama@gmail.com>
Re: [PATCH] e100: fix use-after-free of the CB list in e100_clean_cbs()
#24144
Author: SeungJong Ha
Date: Sun, 29 Nov 2026 12:24
27 lines
11738 bytes
netdev AI review [1]:

> Can e100_tx_clean() reopen this gate while the list is being torn
> down?

Yes, through netpoll in the tx timeout, ringparam and self-test paths.
v2 frees the whole list under cb_lock, with dev_kfree_skb_any().

> A netpoll e100_tx_clean() that runs after cb_to_clean has been set to
> NULL would dereference NULL at cb->status.

Reproduced with netconsole and "ethtool -G", also without this patch.
I'll fix it on v2.

> the note about the prototype static analysis tool (and the Claude
> Code involvement) only appears below the --- line.

Moved into the changelog in v2.

The other points (the skb left in a CB after a TX DMA mapping error,
the device still running when the list is freed, the e100_up() error
path) are pre-existing and not touched by this series.

[1] https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261128-e100-cbs-uaf-v1-1-efda575f56e5%40gmail.com

pw-bot: cr
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