Netdev List
 help / color / mirror / Atom feed
* [PATCH net] net: dsa: hold the device a queued FDB event is reported to
@ 2026-11-22 17:33 Julius Bairaktaris
  2026-11-22 17:37 ` netdev-bot+sinfo
  0 siblings, 1 reply; 3+ messages in thread
From: Julius Bairaktaris @ 2026-11-22 17:33 UTC (permalink / raw)
  To: Andrew Lunn, Vladimir Oltean
  Cc: Nikolay Aleksandrov, Ido Schimmel, netdev, bridge,
	David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Willem de Bruijn, Simon Horman, Florian Fainelli

dsa_user_fdb_event() queues an FDB event on the DSA workqueue together
with the device the event was emitted for (orig_dev), and
dsa_user_switchdev_event_work() reports an added entry to that device
with SWITCHDEV_FDB_OFFLOADED once the switch is programmed. No
reference is held on orig_dev. It is a DSA user port only when the
entry is on one: for an entry on another port of the bridge, which DSA
installs as a host address, it is that port. DSA flushes its workqueue
before one of its own ports leaves the bridge, but nothing waits for
the queue when a foreign bridge port is unregistered, and a work that
runs after the device was freed reads it in br_switchdev_event():

  BUG: KASAN: slab-use-after-free in br_switchdev_event+0x41b/0x550
  Read of size 8 at addr ffff888004d00000 by task kworker/u16:0/13
  Workqueue: dsa_ordered dsa_user_switchdev_event_work
  Call Trace:
   br_switchdev_event+0x41b/0x550
   notifier_call_chain+0x9a/0x2a0
   atomic_notifier_call_chain+0x5a/0x110
   dsa_user_switchdev_event_work+0x32c/0x4c0
   process_one_work+0x8e1/0x1640
  Freed by task 139:
   kfree+0x1b7/0x550
   device_release+0xca/0x250

Hold a reference on orig_dev while the event is queued, as mlxsw,
prestera, sparx5 and cpsw do for the device of their deferred FDB
events. Unregistering the device then waits for the work, which does
not take RTNL.

DSA held the device until commit 425d19cedef8 ("net: dsa: stop calling
dev_hold in dsa_slave_fdb_event"), when the report still went to the
DSA user port.

In QEMU with KASAN, with dsa_loop given FDB operations, assisted
learning on the CPU port and a 500 ms delay in its FDB add (test-only
changes), deleting a veth bridge port right after an address was
learned on it gives the report above in 3 of 3 boots, and nothing with
this change in 3 of 3 boots.

Fixes: 93c798230af5 ("net: dsa: call SWITCHDEV_FDB_OFFLOADED for the orig_dev")
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
This and "[PATCH net] net: dsa: do not run queued FDB events after the
port left the bridge" <20261121185821.1471559-1-julius@bairaktaris.de>
both change the end of dsa_user_switchdev_event_work(). Applied
together, that patch's out: label goes above the netdev_put() added
here, so that an event it drops still releases the device.

I used Claude (Anthropic) to help write these patches.

 net/dsa/user.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/net/dsa/user.c b/net/dsa/user.c
index 041f9060c8ef..5e72fb34e308 100644
--- a/net/dsa/user.c
+++ b/net/dsa/user.c
@@ -35,6 +35,7 @@
 struct dsa_switchdev_event_work {
 	struct net_device *dev;
 	struct net_device *orig_dev;
+	netdevice_tracker orig_dev_tracker;
 	struct work_struct work;
 	unsigned long event;
 	/* Specific for SWITCHDEV_FDB_ADD_TO_DEVICE and
@@ -3686,6 +3687,7 @@ static void dsa_user_switchdev_event_work(struct work_struct *work)
 		break;
 	}
 
+	netdev_put(switchdev_work->orig_dev, &switchdev_work->orig_dev_tracker);
 	kfree(switchdev_work);
 }
 
@@ -3764,6 +3766,10 @@ static int dsa_user_fdb_event(struct net_device *dev,
 	switchdev_work->event = event;
 	switchdev_work->dev = dev;
 	switchdev_work->orig_dev = orig_dev;
+	/* The work reports to orig_dev, which can be a foreign bridge port
+	 * that is unregistered before the work runs
+	 */
+	netdev_hold(orig_dev, &switchdev_work->orig_dev_tracker, GFP_ATOMIC);
 
 	ether_addr_copy(switchdev_work->addr, fdb_info->addr);
 	switchdev_work->vid = fdb_info->vid;

base-commit: af6737b9066832a2017c281159950ba92385ce00
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net: dsa: hold the device a queued FDB event is reported to
  2026-11-22 17:33 [PATCH net] net: dsa: hold the device a queued FDB event is reported to Julius Bairaktaris
@ 2026-11-22 17:37 ` netdev-bot+sinfo
  2026-11-22 17:40   ` Julius Bairaktaris
  0 siblings, 1 reply; 3+ messages in thread
From: netdev-bot+sinfo @ 2026-11-22 17:37 UTC (permalink / raw)
  To: Julius Bairaktaris
  Cc: Andrew Lunn, Vladimir Oltean, Nikolay Aleksandrov, Ido Schimmel,
	netdev, bridge, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Willem de Bruijn, Simon Horman, Florian Fainelli

Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - How the issue was discovered, e.g. hit in production, hit during
   development, syzbot report, manual code inspection, LLM or static
   analysis tool scan.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net: dsa: hold the device a queued FDB event is reported to
  2026-11-22 17:37 ` netdev-bot+sinfo
@ 2026-11-22 17:40   ` Julius Bairaktaris
  0 siblings, 0 replies; 3+ messages in thread
From: Julius Bairaktaris @ 2026-11-22 17:40 UTC (permalink / raw)
  To: netdev-bot+sinfo
  Cc: andrew, olteanv, razor, idosch, netdev, bridge, davem, edumazet,
	kuba, pabeni, willemb, horms, f.fainelli

On Sun, 22 Nov 2026 17:37:38 +0000, netdev-bot wrote:
> - How the issue was discovered, e.g. hit in production, hit during
>   development, syzbot report, manual code inspection, LLM or static
>   analysis tool scan.

Found by an LLM review (Claude) of a follow-up DSA FDB patch, then
reproduced in QEMU with KASAN as the commit message describes.
Trigger: a non-DSA bridge port (veth, Wi-Fi, USB NIC) is unregistered
while an FDB event for an address learned on it is still queued, on a
switch with assisted_learning_on_cpu_port (mt7530, felix, sja1105,
rtl8365mb, mxl862xx, motorcomm). Impact: use-after-free read in
br_switchdev_event(); CVSS 3.1 4.1 (AV:L/AC:H/PR:H/UI:N/S:U/C:N/I:N/A:H).
Nothing short of the fix avoids it.

Julius

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-22 17:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-22 17:33 [PATCH net] net: dsa: hold the device a queued FDB event is reported to Julius Bairaktaris
2026-11-22 17:37 ` netdev-bot+sinfo
2026-11-22 17:40   ` Julius Bairaktaris

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox