Netdev List
 help / color / mirror / Atom feed
From: SeungJong Ha <engineer.jjhama@gmail.com>
To: Tony Nguyen <anthony.l.nguyen@intel.com>,
	 Przemek Kitszel <przemyslaw.kitszel@intel.com>,
	 Andrew Lunn <andrew+netdev@lunn.ch>,
	 "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	 Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>
Cc: intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org,
	 SeungJong Ha <engineer.jjhama@gmail.com>
Subject: [PATCH] e100: fix use-after-free of the CB list in e100_clean_cbs()
Date: Sat, 28 Nov 2026 20:14:15 +0900	[thread overview]
Message-ID: <20261128-e100-cbs-uaf-v1-1-efda575f56e5@gmail.com> (raw)

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>


                 reply	other threads:[~2026-11-28 11:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261128-e100-cbs-uaf-v1-1-efda575f56e5@gmail.com \
    --to=engineer.jjhama@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=anthony.l.nguyen@intel.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=przemyslaw.kitszel@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox