* [PATCH net 0/6] net: dsa: offload_fwd_mark on unbridged ports, bridge numbers across switches
@ 2026-11-28 16:51 Julius Bairaktaris
2026-11-28 16:52 ` [PATCH net 1/6] net: dsa: free struct dsa_bridge after an RCU grace period Julius Bairaktaris
` (6 more replies)
0 siblings, 7 replies; 12+ messages in thread
From: Julius Bairaktaris @ 2026-11-28 16:51 UTC (permalink / raw)
To: Andrew Lunn, Vladimir Oltean, netdev
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Willem de Bruijn, Simon Horman, Alvin Šipraga, Linus Walleij,
Florian Fainelli, Pawel Dembicki, Tobias Waldekranz, Daniel Golle,
Russell King, linux-kernel
Patches 1-3 are about a frame with offload_fwd_mark that reaches the
xmit of a port which is not in a bridge. Patches 4-6 are about bridge
numbers, which DSA hands out across all trees.
1-2. vsc73xx-8021q and sja1105: a frame received on a bridged port keeps
offload_fwd_mark through a tc mirred redirect or mirror, or an nft
netdev fwd or dup, to a standalone port of the same switch, and the
tagger calls br_vlan_enabled() on the standalone port's bridge, which is
NULL.
- Trigger: a local administrator (CAP_NET_ADMIN) adds such a redirect;
then every frame that a remote host sends to the bridged port and that
the rule matches oopses the kernel in softirq. Less often, a port
leaving its bridge while a frame the bridge marked is queued for it.
- Reachability: vsc73xx-8021q or sja1105/sja1110 with
CONFIG_BRIDGE_VLAN_FILTERING=y.
- Impact: kernel oops (NULL pointer dereference); with the race, also a
read of a freed struct dsa_bridge.
- CVSS 3.1: 4.4 AV:L/AC:L/PR:H/UI:N/S:U/C:N/I:N/A:H (the redirect).
- Workaround: no redirect, mirror or netdev fwd from a bridged port to a
standalone port of the same switch; nothing short of the fix closes
the race.
- Patch 1 frees struct dsa_bridge after an RCU grace period and reads
dp->bridge once wherever the datapath reads it; patch 2 makes the two
taggers send such a frame in the port's standalone VLAN.
3. tag_dsa: the same redirect makes mv88e6xxx's tagger send the frame as
FORWARD on behalf of bridge 0, i.e. from switch device dst->last_switch,
port 0, instead of FROM_CPU to the port.
- Trigger, reachability (mv88e6xxx with dsa or edsa tagging) and
workaround as for 1-2; impact: the frame goes where the switch sends a
FORWARD frame of that device instead of out of the port; no crash.
- CVSS 3.1: 2.3 AV:L/AC:L/PR:H/UI:N/S:U/C:N/I:L/A:N.
4. A switch gets a bridge number above its own max_num_bridges when
another switch, with a larger limit, numbered the bridge first: an
mv88e6xxx (up to 31) or mxl862xx (48) tree beside a sja1105 or vsc73xx
tree (7) and eight or more offloaded bridges give the tag_8021q switch
bridge 9 in the VLAN of bridge 1, so two bridges share a broadcast domain
in that switch.
5. On 32-bit, an mxl862xx switch can take bridge number 32, past the end
of the one unsigned long that tracks them, and set_bit() writes past it.
6. A bridge spanning two trees loses its number when its last port in one
tree leaves, while the other tree still uses it; the next bridge then
gets the same number, with the same sharing as in 4.
- Trigger (4-6): a local administrator creating bridges with ports of
those switches; reachability: the switch combinations named; impact:
frames of one bridge reach the ports of another (4, 6), memory
corruption of the adjacent variable (5).
- CVSS 3.1: 3.4 AV:L/AC:L/PR:H/UI:N/S:U/C:L/I:L/A:N (4, 6);
4.4 AV:L/AC:L/PR:H/UI:N/S:U/C:N/I:N/A:H (5).
- Workaround: fewer offloaded bridges than the smallest limit (4, 5);
do not remove the last port of one tree from a bridge that spans two
(6).
All six were found by an LLM review (Claude). 1-4 and 6 were reproduced
in QEMU (x86_64, KASAN and lockdep) with dsa_loop given the tag_8021q
ops, a second switch in a second tree and per-switch bridge limits (a
test-only change, not part of this series), on veth conduits, one run
each:
- redirect: tc ingress matchall mirred redirect from a port of a
vsc73xx-8021q bridge to a standalone port, one frame sent in the
bridge's tag_8021q VLAN: on net 28a371228 "Oops: general protection
fault ... KASAN: null-ptr-deref" in br_vlan_enabled() from
vsc73xx_xmit() and tcf_mirred_act(); with the series the frame leaves
in the standalone port's VLAN;
- leave: two ports with a 400 ms netem delay leave the bridge with 20
broadcasts queued: on net "BUG: KASAN: null-ptr-deref in
br_vlan_enabled"; with the series 18
of the 20 leave in a standalone VLAN and dmesg is clean;
- edsa, the same redirect: on net the frame leaves with a FORWARD tag
(first tag byte 0xc0); with the series FROM_CPU to the port (0x40,
port 2);
- two trees with limits 31 and 1: on net the second is handed bridge
number 2; with the series its port is bridged in software with "Range
of offloadable bridges exceeded";
- a bridge with one port in each tree, the port of the first tree taken
out, a new bridge created there: on net the new bridge gets the number
the second tree still uses; with the series the next free one.
5 is from reading: dsa_loop has too few ports to reach 32 bridges.
I used Claude (Anthropic) to help write these patches.
Julius Bairaktaris (6):
net: dsa: free struct dsa_bridge after an RCU grace period
net: dsa: tag_sja1105, tag_vsc73xx_8021q: read the bridge once in xmit
net: dsa: tag_dsa: send a marked frame of an unbridged port from the
CPU
net: dsa: do not hand a switch a bridge number above its limit
net: dsa: do not take a bridge number past the end of the bitmap
net: dsa: keep a bridge number while another tree uses it
include/net/dsa.h | 14 ++++++++++++--
net/dsa/dsa.c | 17 +++++++++++++----
net/dsa/port.c | 21 +++++++++++++++++----
net/dsa/tag.h | 4 ++--
net/dsa/tag_8021q.c | 6 ++++--
net/dsa/tag_dsa.c | 14 ++++++++------
net/dsa/tag_sja1105.c | 21 ++++++++++++++-------
net/dsa/tag_vsc73xx_8021q.c | 14 +++++++++-----
8 files changed, 79 insertions(+), 32 deletions(-)
base-commit: 28a371228d4eb4857cc31eeb1a0d7d01e9c3ea2f
--
2.53.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH net 1/6] net: dsa: free struct dsa_bridge after an RCU grace period
2026-11-28 16:51 [PATCH net 0/6] net: dsa: offload_fwd_mark on unbridged ports, bridge numbers across switches Julius Bairaktaris
@ 2026-11-28 16:52 ` Julius Bairaktaris
2026-11-28 16:52 ` [PATCH net 2/6] net: dsa: tag_sja1105, tag_vsc73xx_8021q: read the bridge once in xmit Julius Bairaktaris
` (5 subsequent siblings)
6 siblings, 0 replies; 12+ messages in thread
From: Julius Bairaktaris @ 2026-11-28 16:52 UTC (permalink / raw)
To: Andrew Lunn, Vladimir Oltean, netdev
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Willem de Bruijn, Simon Horman, Alvin Šipraga, Linus Walleij,
Florian Fainelli, Pawel Dembicki, Tobias Waldekranz, Daniel Golle,
Russell King, linux-kernel
A tagger that offloads TX forwarding reads dp->bridge from its xmit
function, in an RCU read-side critical section with BH disabled, to find
the bridge number of a frame that the bridge marked with
offload_fwd_mark; the receive path reads it as well
(dsa_tag_8021q_find_port_by_vbid()). dsa_port_bridge_destroy() clears
dp->bridge under rtnl_lock and frees the structure with kfree() once the
last port has left. A frame that was marked before the leave can still
be on its way through the tagger at that point, and the tagger then
dereferences freed memory. dsa_port_bridge_dev_get() and
dsa_port_bridge_num_get() read the pointer twice, so a concurrent leave
also turns their NULL test into a NULL dereference.
Free the structure with kfree_rcu(), publish dp->bridge with
smp_store_release() and clear it with WRITE_ONCE(), and read it with
READ_ONCE() in the datapath: in both helpers, once each, and in
dsa_find_designated_bridge_port_by_vid(), dsa_default_offload_fwd_mark()
and dsa_tag_8021q_find_port_by_vbid(), which uses the bridge it read for
the number as well.
Found by an LLM review (Claude).
Fixes: d3eed0e57d5d ("net: dsa: keep the bridge_dev and bridge_num as part of the same structure")
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
include/net/dsa.h | 14 ++++++++++++--
net/dsa/port.c | 11 +++++++----
net/dsa/tag.h | 4 ++--
net/dsa/tag_8021q.c | 6 ++++--
4 files changed, 25 insertions(+), 10 deletions(-)
diff --git a/include/net/dsa.h b/include/net/dsa.h
index 5d12191b6f6..1076439e838 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -242,6 +242,7 @@ struct dsa_bridge {
unsigned int num;
bool tx_fwd_offload;
refcount_t refcount;
+ struct rcu_head rcu;
};
struct dsa_port {
@@ -302,6 +303,11 @@ struct dsa_port {
struct device_node *dn;
unsigned int ageing_time;
+ /* Written under rtnl_lock. The datapath reads it once, with
+ * READ_ONCE(), in an RCU read-side critical section: the port can
+ * leave its bridge while a frame is on its way through the tagger,
+ * and the structure is freed only after a grace period.
+ */
struct dsa_bridge *bridge;
struct devlink_port devlink_port;
struct phylink *pl;
@@ -772,12 +778,16 @@ struct net_device *dsa_port_to_bridge_port(const struct dsa_port *dp)
static inline struct net_device *
dsa_port_bridge_dev_get(const struct dsa_port *dp)
{
- return dp->bridge ? dp->bridge->dev : NULL;
+ const struct dsa_bridge *bridge = READ_ONCE(dp->bridge);
+
+ return bridge ? bridge->dev : NULL;
}
static inline unsigned int dsa_port_bridge_num_get(struct dsa_port *dp)
{
- return dp->bridge ? dp->bridge->num : 0;
+ const struct dsa_bridge *bridge = READ_ONCE(dp->bridge);
+
+ return bridge ? bridge->num : 0;
}
static inline bool dsa_port_bridge_same(const struct dsa_port *a,
diff --git a/net/dsa/port.c b/net/dsa/port.c
index 1f5536c0dff..997e68cd215 100644
--- a/net/dsa/port.c
+++ b/net/dsa/port.c
@@ -427,7 +427,8 @@ static int dsa_port_bridge_create(struct dsa_port *dp,
bridge = dsa_tree_bridge_find(ds->dst, br);
if (bridge) {
refcount_inc(&bridge->refcount);
- dp->bridge = bridge;
+ /* Pairs with the READ_ONCE() of the datapath */
+ smp_store_release(&dp->bridge, bridge);
return 0;
}
@@ -447,7 +448,8 @@ static int dsa_port_bridge_create(struct dsa_port *dp,
return -EOPNOTSUPP;
}
- dp->bridge = bridge;
+ /* Pairs with the READ_ONCE() of the datapath */
+ smp_store_release(&dp->bridge, bridge);
return 0;
}
@@ -457,7 +459,7 @@ static void dsa_port_bridge_destroy(struct dsa_port *dp,
{
struct dsa_bridge *bridge = dp->bridge;
- dp->bridge = NULL;
+ WRITE_ONCE(dp->bridge, NULL);
if (!refcount_dec_and_test(&bridge->refcount))
return;
@@ -465,7 +467,8 @@ static void dsa_port_bridge_destroy(struct dsa_port *dp,
if (bridge->num)
dsa_bridge_num_put(br, bridge->num);
- kfree(bridge);
+ /* The datapath may still hold the pointer it read from dp->bridge */
+ kfree_rcu(bridge, rcu);
}
static bool dsa_port_supports_mst(struct dsa_port *dp)
diff --git a/net/dsa/tag.h b/net/dsa/tag.h
index cf52283fe9d..0e1be1da453 100644
--- a/net/dsa/tag.h
+++ b/net/dsa/tag.h
@@ -201,7 +201,7 @@ dsa_find_designated_bridge_port_by_vid(struct net_device *conduit, u16 vid)
if (dp->type != DSA_PORT_TYPE_USER)
continue;
- if (!dp->bridge)
+ if (!READ_ONCE(dp->bridge))
continue;
if (dp->stp_state != BR_STATE_LEARNING &&
@@ -238,7 +238,7 @@ static inline void dsa_default_offload_fwd_mark(struct sk_buff *skb)
{
struct dsa_port *dp = dsa_user_to_port(skb->dev);
- skb->offload_fwd_mark = !!(dp->bridge);
+ skb->offload_fwd_mark = !!READ_ONCE(dp->bridge);
}
/* Helper for removing DSA header tags from packets in the RX path.
diff --git a/net/dsa/tag_8021q.c b/net/dsa/tag_8021q.c
index f91646e6024..ac9ba1ee04f 100644
--- a/net/dsa/tag_8021q.c
+++ b/net/dsa/tag_8021q.c
@@ -482,7 +482,9 @@ dsa_tag_8021q_find_port_by_vbid(struct net_device *conduit, int vbid)
return NULL;
dsa_tree_for_each_user_port(dp, dst) {
- if (!dp->bridge)
+ const struct dsa_bridge *bridge = READ_ONCE(dp->bridge);
+
+ if (!bridge)
continue;
if (dp->stp_state != BR_STATE_LEARNING &&
@@ -492,7 +494,7 @@ dsa_tag_8021q_find_port_by_vbid(struct net_device *conduit, int vbid)
if (dp->cpu_dp != cpu_dp)
continue;
- if (dsa_port_bridge_num_get(dp) == vbid)
+ if (bridge->num == vbid)
return dp->user;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH net 2/6] net: dsa: tag_sja1105, tag_vsc73xx_8021q: read the bridge once in xmit
2026-11-28 16:51 [PATCH net 0/6] net: dsa: offload_fwd_mark on unbridged ports, bridge numbers across switches Julius Bairaktaris
2026-11-28 16:52 ` [PATCH net 1/6] net: dsa: free struct dsa_bridge after an RCU grace period Julius Bairaktaris
@ 2026-11-28 16:52 ` Julius Bairaktaris
2026-12-06 3:54 ` willemb
2026-11-28 16:52 ` [PATCH net 3/6] net: dsa: tag_dsa: send a marked frame of an unbridged port from the CPU Julius Bairaktaris
` (4 subsequent siblings)
6 siblings, 1 reply; 12+ messages in thread
From: Julius Bairaktaris @ 2026-11-28 16:52 UTC (permalink / raw)
To: Andrew Lunn, Vladimir Oltean, netdev
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Willem de Bruijn, Simon Horman, Alvin Šipraga, Linus Walleij,
Florian Fainelli, Pawel Dembicki, Tobias Waldekranz, Daniel Golle,
Russell King, linux-kernel
A frame received on a port that offloads a bridge carries
offload_fwd_mark (dsa_default_offload_fwd_mark()). A tc mirred redirect
or mirror, or an nft netdev fwd or dup, from that port to a standalone
port of the same switch keeps the mark, and vsc73xx_xmit() and
sja1105_imprecise_xmit() then look up the bridge of the standalone port:
dsa_port_bridge_dev_get() returns NULL and br_vlan_enabled() dereferences
it, in softirq, for every such frame. The same happens when a port leaves
its bridge while a frame that the bridge marked is still queued for it.
Both taggers also read dp->bridge twice, once for the device and once
for the number.
Read dp->bridge once. When the port is not in a bridge, it is a
standalone port, so send the frame in its standalone VLAN, to the port
alone, with the PCP of its TX queue, as for a frame without
offload_fwd_mark.
Both drivers are fixed in one commit because they share the mechanism.
Found by an LLM review (Claude), and reproduced in QEMU with dsa_loop.
Fixes: b6ad86e6ad6c ("net: dsa: sja1105: add bridge TX data plane offload based on tag_8021q")
Fixes: 6c87e1a47928 ("net: dsa: vsc73xx: introduce tag 8021q for vsc73xx")
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
net/dsa/tag_sja1105.c | 21 ++++++++++++++-------
net/dsa/tag_vsc73xx_8021q.c | 14 +++++++++-----
2 files changed, 23 insertions(+), 12 deletions(-)
diff --git a/net/dsa/tag_sja1105.c b/net/dsa/tag_sja1105.c
index bfe1f746f55..6c267a2a232 100644
--- a/net/dsa/tag_sja1105.c
+++ b/net/dsa/tag_sja1105.c
@@ -209,27 +209,34 @@ static u16 sja1105_xmit_tpid(struct dsa_port *dp)
}
static struct sk_buff *sja1105_imprecise_xmit(struct sk_buff *skb,
- struct net_device *netdev)
+ struct net_device *netdev, u8 pcp)
{
struct dsa_port *dp = dsa_user_to_port(netdev);
- unsigned int bridge_num = dsa_port_bridge_num_get(dp);
- struct net_device *br = dsa_port_bridge_dev_get(dp);
+ const struct dsa_bridge *bridge = READ_ONCE(dp->bridge);
u16 tx_vid;
+ /* The bridge marked the frame, then the port left it: the port is
+ * standalone now, send the frame to it alone.
+ */
+ if (unlikely(!bridge))
+ return dsa_8021q_xmit(skb, netdev, sja1105_xmit_tpid(dp),
+ (pcp << VLAN_PRIO_SHIFT) |
+ dsa_tag_8021q_standalone_vid(dp));
+
/* If the port is under a VLAN-aware bridge, just slide the
* VLAN-tagged packet into the FDB and hope for the best.
* This works because we support a single VLAN-aware bridge
* across the entire dst, and its VLANs cannot be shared with
* any standalone port.
*/
- if (br_vlan_enabled(br))
+ if (br_vlan_enabled(bridge->dev))
return skb;
/* If the port is under a VLAN-unaware bridge, use an imprecise
* TX VLAN that targets the bridge's entire broadcast domain,
* instead of just the specific port.
*/
- tx_vid = dsa_tag_8021q_bridge_vid(bridge_num);
+ tx_vid = dsa_tag_8021q_bridge_vid(bridge->num);
return dsa_8021q_xmit(skb, netdev, sja1105_xmit_tpid(dp), tx_vid);
}
@@ -273,7 +280,7 @@ static struct sk_buff *sja1105_xmit(struct sk_buff *skb,
u16 tx_vid = dsa_tag_8021q_standalone_vid(dp);
if (skb->offload_fwd_mark)
- return sja1105_imprecise_xmit(skb, netdev);
+ return sja1105_imprecise_xmit(skb, netdev, pcp);
/* Transmitting management traffic does not rely upon switch tagging,
* but instead SPI-installed management routes. Part 2 of this
@@ -304,7 +311,7 @@ static struct sk_buff *sja1110_xmit(struct sk_buff *skb,
int trailer_pos;
if (skb->offload_fwd_mark)
- return sja1105_imprecise_xmit(skb, netdev);
+ return sja1105_imprecise_xmit(skb, netdev, pcp);
/* Transmitting control packets is done using in-band control
* extensions, while data packets are transmitted using
diff --git a/net/dsa/tag_vsc73xx_8021q.c b/net/dsa/tag_vsc73xx_8021q.c
index f4736a1a7a0..d65e5ddaa8c 100644
--- a/net/dsa/tag_vsc73xx_8021q.c
+++ b/net/dsa/tag_vsc73xx_8021q.c
@@ -17,13 +17,17 @@ vsc73xx_xmit(struct sk_buff *skb, struct net_device *netdev)
u8 pcp;
if (skb->offload_fwd_mark) {
- unsigned int bridge_num = dsa_port_bridge_num_get(dp);
- struct net_device *br = dsa_port_bridge_dev_get(dp);
+ const struct dsa_bridge *bridge = READ_ONCE(dp->bridge);
- if (br_vlan_enabled(br))
- return skb;
+ /* The port may have left the bridge since the bridge marked
+ * the frame: then it goes to the port alone.
+ */
+ if (bridge) {
+ if (br_vlan_enabled(bridge->dev))
+ return skb;
- tx_vid = dsa_tag_8021q_bridge_vid(bridge_num);
+ tx_vid = dsa_tag_8021q_bridge_vid(bridge->num);
+ }
}
pcp = netdev_txq_to_tc(netdev, queue_mapping);
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH net 3/6] net: dsa: tag_dsa: send a marked frame of an unbridged port from the CPU
2026-11-28 16:51 [PATCH net 0/6] net: dsa: offload_fwd_mark on unbridged ports, bridge numbers across switches Julius Bairaktaris
2026-11-28 16:52 ` [PATCH net 1/6] net: dsa: free struct dsa_bridge after an RCU grace period Julius Bairaktaris
2026-11-28 16:52 ` [PATCH net 2/6] net: dsa: tag_sja1105, tag_vsc73xx_8021q: read the bridge once in xmit Julius Bairaktaris
@ 2026-11-28 16:52 ` Julius Bairaktaris
2026-12-06 3:55 ` willemb
2026-11-28 16:52 ` [PATCH net 4/6] net: dsa: do not hand a switch a bridge number above its limit Julius Bairaktaris
` (3 subsequent siblings)
6 siblings, 1 reply; 12+ messages in thread
From: Julius Bairaktaris @ 2026-11-28 16:52 UTC (permalink / raw)
To: Andrew Lunn, Vladimir Oltean, netdev
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Willem de Bruijn, Simon Horman, Alvin Šipraga, Linus Walleij,
Florian Fainelli, Pawel Dembicki, Tobias Waldekranz, Daniel Golle,
Russell King, linux-kernel
dsa_xmit_ll() sends a frame with offload_fwd_mark as a FORWARD frame on
behalf of the port's bridge, with the bridge number taken from
dsa_port_bridge_num_get(). The port need not be in a bridge: a frame
received on a bridged port keeps the mark through a tc mirred redirect
or an nft netdev fwd to a standalone port of the same switch, and a
frame that the bridge marked can still be queued for a port that has
left the bridge. The bridge number is 0 then, and the frame goes out as
FORWARD from device dst->last_switch, port 0, instead of FROM_CPU to the
port. The function also reads dp->bridge twice, once for the number and
once for the device.
Read dp->bridge once, and send FORWARD only while the port is in a
bridge; otherwise the frame goes FROM_CPU to the port, as a frame
without the mark does.
Found by an LLM review (Claude), and reproduced in QEMU with dsa_loop.
Fixes: d82f8ab0d874 ("net: dsa: tag_dsa: offload the bridge forwarding process")
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
net/dsa/tag_dsa.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/net/dsa/tag_dsa.c b/net/dsa/tag_dsa.c
index d5ffee35fbb..9a89508e451 100644
--- a/net/dsa/tag_dsa.c
+++ b/net/dsa/tag_dsa.c
@@ -130,13 +130,17 @@ static struct sk_buff *dsa_xmit_ll(struct sk_buff *skb, struct net_device *dev,
u8 extra)
{
struct dsa_port *dp = dsa_user_to_port(dev);
- struct net_device *br_dev;
+ const struct dsa_bridge *bridge = READ_ONCE(dp->bridge);
+ struct net_device *br_dev = bridge ? bridge->dev : NULL;
u8 tag_dev, tag_port;
enum dsa_cmd cmd;
u8 *dsa_header;
- if (skb->offload_fwd_mark) {
- unsigned int bridge_num = dsa_port_bridge_num_get(dp);
+ /* A frame keeps offload_fwd_mark through a redirect to a standalone
+ * port, and the port may have left its bridge since the bridge marked
+ * the frame: only a bridged port forwards for its bridge.
+ */
+ if (skb->offload_fwd_mark && bridge) {
struct dsa_switch_tree *dst = dp->ds->dst;
cmd = DSA_CMD_FORWARD;
@@ -145,7 +149,7 @@ static struct sk_buff *dsa_xmit_ll(struct sk_buff *skb, struct net_device *dev,
* packets on behalf of a virtual switch device with an index
* past the physical switches.
*/
- tag_dev = dst->last_switch + bridge_num;
+ tag_dev = dst->last_switch + bridge->num;
tag_port = 0;
} else {
cmd = DSA_CMD_FROM_CPU;
@@ -153,8 +157,6 @@ static struct sk_buff *dsa_xmit_ll(struct sk_buff *skb, struct net_device *dev,
tag_port = dp->index;
}
- br_dev = dsa_port_bridge_dev_get(dp);
-
/* If frame is already 802.1Q tagged, we can convert it to a DSA
* tag (avoiding a memmove), but only if the port is standalone
* (in which case we always send FROM_CPU) or if the port's
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH net 4/6] net: dsa: do not hand a switch a bridge number above its limit
2026-11-28 16:51 [PATCH net 0/6] net: dsa: offload_fwd_mark on unbridged ports, bridge numbers across switches Julius Bairaktaris
` (2 preceding siblings ...)
2026-11-28 16:52 ` [PATCH net 3/6] net: dsa: tag_dsa: send a marked frame of an unbridged port from the CPU Julius Bairaktaris
@ 2026-11-28 16:52 ` Julius Bairaktaris
2026-12-06 3:55 ` willemb
2026-11-28 16:52 ` [PATCH net 5/6] net: dsa: do not take a bridge number past the end of the bitmap Julius Bairaktaris
` (2 subsequent siblings)
6 siblings, 1 reply; 12+ messages in thread
From: Julius Bairaktaris @ 2026-11-28 16:52 UTC (permalink / raw)
To: Andrew Lunn, Vladimir Oltean, netdev
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Willem de Bruijn, Simon Horman, Alvin Šipraga, Linus Walleij,
Florian Fainelli, Pawel Dembicki, Tobias Waldekranz, Daniel Golle,
Russell King, linux-kernel
Bridge numbers are unique across all DSA trees, and each switch tells
dsa_bridge_num_get() the largest number it can use (max_num_bridges).
The limit is checked only when the bridge gets its number. A switch
that joins a bridge which another switch, with a larger limit, has
numbered already gets that number unchecked. With an mv88e6xxx tree
(limit up to 31) or an mxl862xx tree (48) beside a sja1105 or vsc73xx
tree (DSA_TAG_8021Q_MAX_NUM_BRIDGES, 7) and eight or more offloaded
bridges, the tag_8021q switch encodes number 9 in the three VBID bits of
its bridge VLAN (dsa_tag_8021q_bridge_vid()), so bridge 9 gets the VLAN
of bridge 1 and the two share a broadcast domain in the switch. An
mxl862xx tree beside an mv88e6xxx one with 32 or more bridges overflows
the device field of the DSA header in the same way.
Return 0 for a number beyond the limit in that case too. Refuse the
same in dsa_port_bridge_create() when the bridge is found in the tree,
where another switch of the tree may have numbered it beyond this
switch's limit, or not at all: an mv88e6xxx chip without a PVT has
max_num_bridges 0 and leaves the bridge at number 0, which a chip with
a PVT would take. The port is then bridged in software ("Range of
offloadable bridges exceeded"), as a port that joins a new bridge
beyond the limit already is.
Found by an LLM review (Claude), and reproduced in QEMU with dsa_loop.
Fixes: f5e165e72b29 ("net: dsa: track unique bridge numbers across all DSA switch trees")
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
net/dsa/dsa.c | 5 +++++
net/dsa/port.c | 10 ++++++++++
2 files changed, 15 insertions(+)
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 2771c34e840..1c2a29678ac 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -163,6 +163,11 @@ unsigned int dsa_bridge_num_get(const struct net_device *bridge_dev, int max)
return 0;
set_bit(bridge_num, &dsa_fwd_offloading_bridges);
+ } else if (bridge_num > max) {
+ /* A switch with a larger limit, maybe in another tree, numbered
+ * this bridge already, beyond what this switch can encode
+ */
+ return 0;
}
return bridge_num;
diff --git a/net/dsa/port.c b/net/dsa/port.c
index 997e68cd215..9cb441d16de 100644
--- a/net/dsa/port.c
+++ b/net/dsa/port.c
@@ -426,6 +426,16 @@ static int dsa_port_bridge_create(struct dsa_port *dp,
bridge = dsa_tree_bridge_find(ds->dst, br);
if (bridge) {
+ /* Another switch of the tree numbered the bridge beyond this
+ * switch's limit, or left it without a number
+ */
+ if (ds->max_num_bridges &&
+ (!bridge->num || bridge->num > ds->max_num_bridges)) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Range of offloadable bridges exceeded");
+ return -EOPNOTSUPP;
+ }
+
refcount_inc(&bridge->refcount);
/* Pairs with the READ_ONCE() of the datapath */
smp_store_release(&dp->bridge, bridge);
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH net 5/6] net: dsa: do not take a bridge number past the end of the bitmap
2026-11-28 16:51 [PATCH net 0/6] net: dsa: offload_fwd_mark on unbridged ports, bridge numbers across switches Julius Bairaktaris
` (3 preceding siblings ...)
2026-11-28 16:52 ` [PATCH net 4/6] net: dsa: do not hand a switch a bridge number above its limit Julius Bairaktaris
@ 2026-11-28 16:52 ` Julius Bairaktaris
2026-11-28 16:52 ` [PATCH net 6/6] net: dsa: keep a bridge number while another tree uses it Julius Bairaktaris
2026-12-06 3:54 ` [PATCH net 0/6] net: dsa: offload_fwd_mark on unbridged ports, bridge numbers across switches willemb
6 siblings, 0 replies; 12+ messages in thread
From: Julius Bairaktaris @ 2026-11-28 16:52 UTC (permalink / raw)
To: Andrew Lunn, Vladimir Oltean, netdev
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Willem de Bruijn, Simon Horman, Alvin Šipraga, Linus Walleij,
Florian Fainelli, Pawel Dembicki, Tobias Waldekranz, Daniel Golle,
Russell King, linux-kernel
The bridge numbers in use are bits of dsa_fwd_offloading_bridges, one
unsigned long, and dsa_bridge_num_get() searches it with
find_next_zero_bit() over DSA_MAX_NUM_OFFLOADING_BRIDGES, which is
BITS_PER_LONG. When every bit is taken, find_next_zero_bit() returns
the size of the bitmap, and only "bridge_num > max" stands between that
and set_bit(). mxl862xx sets max_num_bridges to 48
(MXL862XX_MAX_BRIDGES), so on a 32-bit kernel the 32nd offloaded bridge
gets number 32 and set_bit() writes past dsa_fwd_offloading_bridges.
Refuse a number at or past the size of the bitmap; the port is then
bridged in software, as one beyond the switch's limit is.
Found by an LLM review (Claude).
Fixes: f5e165e72b29 ("net: dsa: track unique bridge numbers across all DSA switch trees")
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
net/dsa/dsa.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 1c2a29678ac..67b5d2c42fb 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -159,7 +159,8 @@ unsigned int dsa_bridge_num_get(const struct net_device *bridge_dev, int max)
bridge_num = find_next_zero_bit(&dsa_fwd_offloading_bridges,
DSA_MAX_NUM_OFFLOADING_BRIDGES,
1);
- if (bridge_num > max)
+ if (bridge_num >= DSA_MAX_NUM_OFFLOADING_BRIDGES ||
+ bridge_num > max)
return 0;
set_bit(bridge_num, &dsa_fwd_offloading_bridges);
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH net 6/6] net: dsa: keep a bridge number while another tree uses it
2026-11-28 16:51 [PATCH net 0/6] net: dsa: offload_fwd_mark on unbridged ports, bridge numbers across switches Julius Bairaktaris
` (4 preceding siblings ...)
2026-11-28 16:52 ` [PATCH net 5/6] net: dsa: do not take a bridge number past the end of the bitmap Julius Bairaktaris
@ 2026-11-28 16:52 ` Julius Bairaktaris
2026-12-06 3:57 ` willemb
2026-12-06 3:54 ` [PATCH net 0/6] net: dsa: offload_fwd_mark on unbridged ports, bridge numbers across switches willemb
6 siblings, 1 reply; 12+ messages in thread
From: Julius Bairaktaris @ 2026-11-28 16:52 UTC (permalink / raw)
To: Andrew Lunn, Vladimir Oltean, netdev
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Willem de Bruijn, Simon Horman, Alvin Šipraga, Linus Walleij,
Florian Fainelli, Pawel Dembicki, Tobias Waldekranz, Daniel Golle,
Russell King, linux-kernel
Bridge numbers are unique across all DSA trees, and a bridge spanning
ports of two trees gets one number, which both trees use.
dsa_port_bridge_destroy() puts the number when the last port of its
own tree leaves the bridge, and dsa_bridge_num_put() clears the bit
unconditionally, so the number is free while the other tree still
offloads the bridge under it. The next bridge that gets a number then
gets the same one: on a tag_8021q switch both bridges share a VLAN, on
mv88e6xxx a cross-chip PVT row, and frames of one reach the ports of
the other.
Clear the bit only when no tree offloads the bridge any more.
Found by an LLM review (Claude), and reproduced in QEMU with dsa_loop.
Fixes: f5e165e72b29 ("net: dsa: track unique bridge numbers across all DSA switch trees")
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
net/dsa/dsa.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 67b5d2c42fb..bcb398615fc 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -177,10 +177,13 @@ unsigned int dsa_bridge_num_get(const struct net_device *bridge_dev, int max)
void dsa_bridge_num_put(const struct net_device *bridge_dev,
unsigned int bridge_num)
{
- /* Since we refcount bridges, we know that when we call this function
- * it is no longer in use, so we can just go ahead and remove it from
- * the bit mask.
+ /* The bridge is no longer offloaded by the tree that calls this, but
+ * the number is global: another tree may still offload the bridge
+ * under it.
*/
+ if (dsa_bridge_num_find(bridge_dev) == bridge_num)
+ return;
+
clear_bit(bridge_num, &dsa_fwd_offloading_bridges);
}
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH net 0/6] net: dsa: offload_fwd_mark on unbridged ports, bridge numbers across switches
2026-11-28 16:51 [PATCH net 0/6] net: dsa: offload_fwd_mark on unbridged ports, bridge numbers across switches Julius Bairaktaris
` (5 preceding siblings ...)
2026-11-28 16:52 ` [PATCH net 6/6] net: dsa: keep a bridge number while another tree uses it Julius Bairaktaris
@ 2026-12-06 3:54 ` willemb
6 siblings, 0 replies; 12+ messages in thread
From: willemb @ 2026-12-06 3:54 UTC (permalink / raw)
To: Julius Bairaktaris, Andrew Lunn, Vladimir Oltean, netdev
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Willem de Bruijn, Simon Horman, Alvin Šipraga, Linus Walleij,
Florian Fainelli, Pawel Dembicki, Tobias Waldekranz, Daniel Golle,
Russell King, linux-kernel
Julius Bairaktaris wrote:
> Patches 1-3 are about a frame with offload_fwd_mark that reaches the
> xmit of a port which is not in a bridge. Patches 4-6 are about bridge
> numbers, which DSA hands out across all trees.
> 1-2. vsc73xx-8021q and sja1105: a frame received on a bridged port keeps
> offload_fwd_mark through a tc mirred redirect or mirror, or an nft
> netdev fwd or dup, to a standalone port of the same switch, and the
> tagger calls br_vlan_enabled() on the standalone port's bridge, which is
> NULL.
> - Trigger: a local administrator (CAP_NET_ADMIN) adds such a redirect;
> then every frame that a remote host sends to the bridged port and that
> the rule matches oopses the kernel in softirq. Less often, a port
> leaving its bridge while a frame the bridge marked is queued for it.
> - Reachability: vsc73xx-8021q or sja1105/sja1110 with
> CONFIG_BRIDGE_VLAN_FILTERING=y.
> - Impact: kernel oops (NULL pointer dereference); with the race, also a
> read of a freed struct dsa_bridge.
> - CVSS 3.1: 4.4 AV:L/AC:L/PR:H/UI:N/S:U/C:N/I:N/A:H (the redirect).
> - Workaround: no redirect, mirror or netdev fwd from a bridged port to a
> standalone port of the same switch; nothing short of the fix closes
> the race.
> - Patch 1 frees struct dsa_bridge after an RCU grace period and reads
> dp->bridge once wherever the datapath reads it; patch 2 makes the two
> taggers send such a frame in the port's standalone VLAN.
> 3. tag_dsa: the same redirect makes mv88e6xxx's tagger send the frame as
> FORWARD on behalf of bridge 0, i.e. from switch device dst->last_switch,
> port 0, instead of FROM_CPU to the port.
> - Trigger, reachability (mv88e6xxx with dsa or edsa tagging) and
> workaround as for 1-2; impact: the frame goes where the switch sends a
> FORWARD frame of that device instead of out of the port; no crash.
> - CVSS 3.1: 2.3 AV:L/AC:L/PR:H/UI:N/S:U/C:N/I:L/A:N.
> 4. A switch gets a bridge number above its own max_num_bridges when
> another switch, with a larger limit, numbered the bridge first: an
> mv88e6xxx (up to 31) or mxl862xx (48) tree beside a sja1105 or vsc73xx
> tree (7) and eight or more offloaded bridges give the tag_8021q switch
> bridge 9 in the VLAN of bridge 1, so two bridges share a broadcast domain
> in that switch.
> 5. On 32-bit, an mxl862xx switch can take bridge number 32, past the end
> of the one unsigned long that tracks them, and set_bit() writes past it.
> 6. A bridge spanning two trees loses its number when its last port in one
> tree leaves, while the other tree still uses it; the next bridge then
> gets the same number, with the same sharing as in 4.
> - Trigger (4-6): a local administrator creating bridges with ports of
> those switches; reachability: the switch combinations named; impact:
> frames of one bridge reach the ports of another (4, 6), memory
> corruption of the adjacent variable (5).
> - CVSS 3.1: 3.4 AV:L/AC:L/PR:H/UI:N/S:U/C:L/I:L/A:N (4, 6);
> 4.4 AV:L/AC:L/PR:H/UI:N/S:U/C:N/I:N/A:H (5).
> - Workaround: fewer offloaded bridges than the smallest limit (4, 5);
> do not remove the last port of one tree from a bridge that spans two
> (6).
> All six were found by an LLM review (Claude). 1-4 and 6 were reproduced
> in QEMU (x86_64, KASAN and lockdep) with dsa_loop given the tag_8021q
> ops, a second switch in a second tree and per-switch bridge limits (a
> test-only change, not part of this series), on veth conduits, one run
> each:
> - redirect: tc ingress matchall mirred redirect from a port of a
> vsc73xx-8021q bridge to a standalone port, one frame sent in the
> bridge's tag_8021q VLAN: on net 28a371228 "Oops: general protection
> fault ... KASAN: null-ptr-deref" in br_vlan_enabled() from
> vsc73xx_xmit() and tcf_mirred_act(); with the series the frame leaves
> in the standalone port's VLAN;
> - leave: two ports with a 400 ms netem delay leave the bridge with 20
> broadcasts queued: on net "BUG: KASAN: null-ptr-deref in
> br_vlan_enabled"; with the series 18
> of the 20 leave in a standalone VLAN and dmesg is clean;
> - edsa, the same redirect: on net the frame leaves with a FORWARD tag
> (first tag byte 0xc0); with the series FROM_CPU to the port (0x40,
> port 2);
> - two trees with limits 31 and 1: on net the second is handed bridge
> number 2; with the series its port is bridged in software with "Range
> of offloadable bridges exceeded";
> - a bridge with one port in each tree, the port of the first tree taken
> out, a new bridge created there: on net the new bridge gets the number
> the second tree still uses; with the series the next free one.
> 5 is from reading: dsa_loop has too few ports to reach 32 bridges.
> I used Claude (Anthropic) to help write these patches.
> Julius Bairaktaris (6):
> net: dsa: free struct dsa_bridge after an RCU grace period
> net: dsa: tag_sja1105, tag_vsc73xx_8021q: read the bridge once in xmit
> net: dsa: tag_dsa: send a marked frame of an unbridged port from the
> CPU
> net: dsa: do not hand a switch a bridge number above its limit
> net: dsa: do not take a bridge number past the end of the bitmap
> net: dsa: keep a bridge number while another tree uses it
> include/net/dsa.h | 14 ++++++++++++--
> net/dsa/dsa.c | 17 +++++++++++++----
> net/dsa/port.c | 21 +++++++++++++++++----
> net/dsa/tag.h | 4 ++--
> net/dsa/tag_8021q.c | 6 ++++--
> net/dsa/tag_dsa.c | 14 ++++++++------
> net/dsa/tag_sja1105.c | 21 ++++++++++++++-------
> net/dsa/tag_vsc73xx_8021q.c | 14 +++++++++-----
> 8 files changed, 79 insertions(+), 32 deletions(-)
> base-commit: 28a371228d4eb4857cc31eeb1a0d7d01e9c3ea2f
> --
> 2.53.0
Patch 1/6 (RCU lifetime for struct dsa_bridge) and Patch 5/6 (bitmap
upper-bound
check before set_bit()) are sound on their own, and Patch 4/6 addresses a
real
cross-switch limit bug. However, the series is NOT ready to merge:
independent
verification against netdev-net/main confirms two non-preexisting High bugs
(Patch 3/6 leaves non-PVT mv88e6xxx chips broken; Patch 6/6 leaves
cross-tree
bridge-number reuse broken whenever a tree with max_num_bridges == 0
precedes
another tree in dsa_tree_list, and the same dsa_bridge_num_find() defect
also
breaks dsa_bridge_num_get()/Patch 4/6), two non-preexisting Medium bugs
(Patch
2/6 bypasses SJA1105/SJA1110 link-local/PTP handling on !bridge; Patches
2-3 do
not address RX offload_fwd_mark leaking across tc/nft redirects onto bridged
ports), an inaccurate Fixes trailer on Patch 6/6, and bundling of two
unrelated
DSA topics targeting post-rc4 net.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net 2/6] net: dsa: tag_sja1105, tag_vsc73xx_8021q: read the bridge once in xmit
2026-11-28 16:52 ` [PATCH net 2/6] net: dsa: tag_sja1105, tag_vsc73xx_8021q: read the bridge once in xmit Julius Bairaktaris
@ 2026-12-06 3:54 ` willemb
0 siblings, 0 replies; 12+ messages in thread
From: willemb @ 2026-12-06 3:54 UTC (permalink / raw)
To: Julius Bairaktaris, Andrew Lunn, Vladimir Oltean, netdev
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Willem de Bruijn, Simon Horman, Alvin Šipraga, Linus Walleij,
Florian Fainelli, Pawel Dembicki, Tobias Waldekranz, Daniel Golle,
Russell King, linux-kernel
Julius Bairaktaris wrote:
> A frame received on a port that offloads a bridge carries
> offload_fwd_mark (dsa_default_offload_fwd_mark()). A tc mirred redirect
> or mirror, or an nft netdev fwd or dup, from that port to a standalone
> port of the same switch keeps the mark, and vsc73xx_xmit() and
> sja1105_imprecise_xmit() then look up the bridge of the standalone port:
> dsa_port_bridge_dev_get() returns NULL and br_vlan_enabled() dereferences
> it, in softirq, for every such frame. The same happens when a port leaves
> its bridge while a frame that the bridge marked is still queued for it.
> Both taggers also read dp->bridge twice, once for the device and once
> for the number.
> Read dp->bridge once. When the port is not in a bridge, it is a
> standalone port, so send the frame in its standalone VLAN, to the port
> alone, with the PCP of its TX queue, as for a frame without
> offload_fwd_mark.
> Both drivers are fixed in one commit because they share the mechanism.
> Found by an LLM review (Claude), and reproduced in QEMU with dsa_loop.
> Fixes: b6ad86e6ad6c ("net: dsa: sja1105: add bridge TX data plane offload
> based on tag_8021q")
> Fixes: 6c87e1a47928 ("net: dsa: vsc73xx: introduce tag 8021q for vsc73xx")
> Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
- net/dsa/tag_sja1105.c:221-224 (sja1105_imprecise_xmit):
When skb->offload_fwd_mark is set and !bridge, the new fallback inside
sja1105_imprecise_xmit() immediately sends the frame through
dsa_8021q_xmit()
in the port's standalone tag_8021q VLAN, bypassing
sja1105_is_link_local(skb)
in both sja1105_xmit() (lines 289-295, SPI management routes via
sja1105_defer_xmit()) and sja1110_xmit() (lines 320-351, in-band control
extension header/trailer). SJA1105/SJA1110 hardware matches
01:80:C2:xx:xx:xx
and PTP 01:1B:19:xx:xx:xx (include/linux/dsa/sja1105.h:22-26) in its
management filters, so link-local or PTP frames carrying offload_fwd_mark
(e.g., redirected from another switch's bridged port or bridge-forwarded
with
group_fwd_mask / PTP multicast right before port leave) must take the
control
path, not dsa_8021q_xmit(). Fix cleanly by checking READ_ONCE(dp->bridge)
in
sja1105_xmit() and sja1110_xmit() and only calling
sja1105_imprecise_xmit(skb,
netdev, bridge) when bridge != NULL, letting !bridge fall through to the
normal
standalone path (which also removes the extra pcp parameter).
- tag_vsc73xx_8021q) net/dsa/tag_sja1105.c:282,313,
net/dsa/tag_vsc73xx_8021q.c:19:
Same root architectural gap as Patch 3/6: tc mirred and nft netdev
fwd/dup do
not clear RX skb->offload_fwd_mark on egress redirect, so redirecting
from a
bridged ingress port to a *bridged* sja1105/vsc73xx port (e.g. in another
bridge) still enters imprecise bridge-wide TX forwarding (or returns an
untagged/wrong-VLAN frame
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net 3/6] net: dsa: tag_dsa: send a marked frame of an unbridged port from the CPU
2026-11-28 16:52 ` [PATCH net 3/6] net: dsa: tag_dsa: send a marked frame of an unbridged port from the CPU Julius Bairaktaris
@ 2026-12-06 3:55 ` willemb
0 siblings, 0 replies; 12+ messages in thread
From: willemb @ 2026-12-06 3:55 UTC (permalink / raw)
To: Julius Bairaktaris, Andrew Lunn, Vladimir Oltean, netdev
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Willem de Bruijn, Simon Horman, Alvin Šipraga, Linus Walleij,
Florian Fainelli, Pawel Dembicki, Tobias Waldekranz, Daniel Golle,
Russell King, linux-kernel
Julius Bairaktaris wrote:
> dsa_xmit_ll() sends a frame with offload_fwd_mark as a FORWARD frame on
> behalf of the port's bridge, with the bridge number taken from
> dsa_port_bridge_num_get(). The port need not be in a bridge: a frame
> received on a bridged port keeps the mark through a tc mirred redirect
> or an nft netdev fwd to a standalone port of the same switch, and a
> frame that the bridge marked can still be queued for a port that has
> left the bridge. The bridge number is 0 then, and the frame goes out as
> FORWARD from device dst->last_switch, port 0, instead of FROM_CPU to the
> port. The function also reads dp->bridge twice, once for the number and
> once for the device.
> Read dp->bridge once, and send FORWARD only while the port is in a
> bridge; otherwise the frame goes FROM_CPU to the port, as a frame
> without the mark does.
> Found by an LLM review (Claude), and reproduced in QEMU with dsa_loop.
> Fixes: d82f8ab0d874 ("net: dsa: tag_dsa: offload the bridge forwarding
> process")
> Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
net/dsa/tag_dsa.c:143 (dsa_xmit_ll):
The new guard `if (skb->offload_fwd_mark && bridge)` only verifies that
the
egress port belongs to a bridge; it fails to check bridge->tx_fwd_offload
(or
bridge->num != 0). In drivers/net/dsa/mv88e6xxx/chip.c:4008-4010 and
3071-3077, mv88e6xxx_setup() only sets ds->max_num_bridges and
mv88e6xxx_port_bridge_join() only sets *tx_fwd_offload = true when
mv88e6xxx_has_pvt(chip) is true. On all 7 non-PVT mv88e6xxx chips
(MV88E6020,
MV88E6071, MV88E6095, MV88E6131, MV88E6185, MV88E6220, MV88E6250), a
bridged
port has dp->bridge != NULL with bridge->num == 0 and
bridge->tx_fwd_offload
== false. Under the exact same tc mirred / nft netdev fwd redirect from
any
bridged ingress port (where dsa_default_offload_fwd_mark() sets
skb->offload_fwd_mark = 1), dsa_xmit_ll() STILL takes the DSA_CMD_FORWARD
branch and sets tag_dev = dst->last_switch + 0 (dst->last_switch),
tag_port =
0, impersonating physical switch dst->last_switch port 0. Additionally,
during
dsa_port_bridge_join() on PVT chips, dp->bridge is published before
mv88e6xxx_map_virtual_bridge_to_pvt() sets dp->bridge->tx_fwd_offload =
true.
dsa_xmit_ll() must check bridge && READ_ONCE(bridge->tx_fwd_offload) (and
bridge->num != 0, with WRITE_ONCE() in dsa_port_bridge_join()).
net/dsa/tag_dsa.c:139-143 (dsa_xmit_ll):
skb->offload_fwd_mark carries no bridge/hwdom identity and is overloaded
between RX ("already hardware-forwarded in ingress hwdom") and TX ("bridge
requests TX forwarding offload"). Neither tcf_mirred_to_dev()
(net/sched/act_mirred.c:254-335) nor nf_do_netdev_egress()
(net/netfilter/nf_dup_netdev.c:17-41) clears skb->offload_fwd_mark when
redirecting/mirroring to egress. Consequently, redirecting an RX frame
from a
bridged port on br0 (or any other switchdev NIC) to a bridged port on br1
causes dsa_xmit_ll() to transmit DSA_CMD_FORWARD on behalf of br1
(flooding
and learning SA on br1) instead of DSA_CMD_FROM_CPU to the target port.
Clearing skb->offload_fwd_mark on egress redirect (while keeping tagger
RCU
and tx_fwd_offload checks for concurrent bridge leave) fixes the root
cause
rather than only standalone targets.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net 4/6] net: dsa: do not hand a switch a bridge number above its limit
2026-11-28 16:52 ` [PATCH net 4/6] net: dsa: do not hand a switch a bridge number above its limit Julius Bairaktaris
@ 2026-12-06 3:55 ` willemb
0 siblings, 0 replies; 12+ messages in thread
From: willemb @ 2026-12-06 3:55 UTC (permalink / raw)
To: Julius Bairaktaris, Andrew Lunn, Vladimir Oltean, netdev
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Willem de Bruijn, Simon Horman, Alvin Šipraga, Linus Walleij,
Florian Fainelli, Pawel Dembicki, Tobias Waldekranz, Daniel Golle,
Russell King, linux-kernel
Julius Bairaktaris wrote:
> Bridge numbers are unique across all DSA trees, and each switch tells
> dsa_bridge_num_get() the largest number it can use (max_num_bridges).
> The limit is checked only when the bridge gets its number. A switch
> that joins a bridge which another switch, with a larger limit, has
> numbered already gets that number unchecked. With an mv88e6xxx tree
> (limit up to 31) or an mxl862xx tree (48) beside a sja1105 or vsc73xx
> tree (DSA_TAG_8021Q_MAX_NUM_BRIDGES, 7) and eight or more offloaded
> bridges, the tag_8021q switch encodes number 9 in the three VBID bits of
> its bridge VLAN (dsa_tag_8021q_bridge_vid()), so bridge 9 gets the VLAN
> of bridge 1 and the two share a broadcast domain in the switch. An
> mxl862xx tree beside an mv88e6xxx one with 32 or more bridges overflows
> the device field of the DSA header in the same way.
> Return 0 for a number beyond the limit in that case too. Refuse the
> same in dsa_port_bridge_create() when the bridge is found in the tree,
> where another switch of the tree may have numbered it beyond this
> switch's limit, or not at all: an mv88e6xxx chip without a PVT has
> max_num_bridges 0 and leaves the bridge at number 0, which a chip with
> a PVT would take. The port is then bridged in software ("Range of
> offloadable bridges exceeded"), as a port that joins a new bridge
> beyond the limit already is.
> Found by an LLM review (Claude), and reproduced in QEMU with dsa_loop.
> Fixes: f5e165e72b29 ("net: dsa: track unique bridge numbers across all
> DSA switch trees")
> Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
net/dsa/dsa.c:130-143, 147, 167 (dsa_bridge_num_find /
dsa_bridge_num_get):
Patch 4/6 relies on dsa_bridge_num_find(bridge_dev) returning the existing
non-zero bridge_num before checking `else if (bridge_num > max)`. Because
dsa_bridge_num_find() returns bridge->num on the *first* tree in
dsa_tree_list
that contains bridge_dev — even if bridge->num == 0 — a system with
dsa_tree_list ordered [Tree 0 (max_num_bridges=0), Tree 1 (max=31), Tree 2
(max=7)] where Tree 0 joins br0 first causes Tree 2's
dsa_bridge_num_find(br0)
to return 0 instead of Tree 1's number, bypassing Patch 4/6's limit check
and
allocating a second distinct bridge number for br0. Fixing
dsa_bridge_num_find()
to check `if (bridge && bridge->num)` fixes both Patch 4/6 and Patch 6/6.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net 6/6] net: dsa: keep a bridge number while another tree uses it
2026-11-28 16:52 ` [PATCH net 6/6] net: dsa: keep a bridge number while another tree uses it Julius Bairaktaris
@ 2026-12-06 3:57 ` willemb
0 siblings, 0 replies; 12+ messages in thread
From: willemb @ 2026-12-06 3:57 UTC (permalink / raw)
To: Julius Bairaktaris, Andrew Lunn, Vladimir Oltean, netdev
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Willem de Bruijn, Simon Horman, Alvin Šipraga, Linus Walleij,
Florian Fainelli, Pawel Dembicki, Tobias Waldekranz, Daniel Golle,
Russell King, linux-kernel
Julius Bairaktaris wrote:
> Bridge numbers are unique across all DSA trees, and a bridge spanning
> ports of two trees gets one number, which both trees use.
> dsa_port_bridge_destroy() puts the number when the last port of its
> own tree leaves the bridge, and dsa_bridge_num_put() clears the bit
> unconditionally, so the number is free while the other tree still
> offloads the bridge under it. The next bridge that gets a number then
> gets the same one: on a tag_8021q switch both bridges share a VLAN, on
> mv88e6xxx a cross-chip PVT row, and frames of one reach the ports of
> the other.
> Clear the bit only when no tree offloads the bridge any more.
> Found by an LLM review (Claude), and reproduced in QEMU with dsa_loop.
> Fixes: f5e165e72b29 ("net: dsa: track unique bridge numbers across all
> DSA switch trees")
> Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
net/dsa/dsa.c:130-143, 184 (dsa_bridge_num_find / dsa_bridge_num_put):
The new guard `if (dsa_bridge_num_find(bridge_dev) == bridge_num) return;`
fails to enforce the commit message's invariant ("clear the bit only when
no
tree offloads the bridge any more") because dsa_bridge_num_find() returns
immediately on the first tree in dsa_tree_list with a struct dsa_bridge
for
bridge_dev, even when that tree has bridge->num == 0 (any switch driver
with
ds->max_num_bridges == 0, which is most DSA drivers).
Concrete failure with 3 trees in dsa_tree_list = [Tree 0 (max=0), Tree 1
(max=7), Tree 2 (max=7)]:
1. Tree 1 joins br0 -> bridge->num = 1 (bit 1 set).
2. Tree 2 joins br0 -> dsa_bridge_num_find(br0) finds Tree 1 ->
bridge->num = 1.
3. Tree 0 joins br0 -> max == 0 -> bridge->num = 0.
4. Tree 1's last port leaves br0 -> dsa_port_bridge_destroy() calls
dsa_bridge_num_put(br0, 1) -> dsa_bridge_num_find(br0) hits Tree 0
first
and returns 0 without inspecting Tree 2 -> 0 == 1 is false ->
clear_bit(1,
&dsa_fwd_offloading_bridges) releases bit 1 while Tree 2 still
offloads br0
under number 1!
5. Next bridge br1 allocates bit 1, colliding with br0 on Tree 2 (shared
tag_8021q VLAN / mv88e6xxx PVT row / mxl862xx bridge slot).
Root cause: commit d3eed0e57d5d accidentally dropped `&& dp->bridge_num`
when
rewriting dsa_bridge_num_find() to call dsa_tree_bridge_find(). Changing
line
138 of net/dsa/dsa.c from `if (bridge)` to `if (bridge && bridge->num)`
fixes
both dsa_bridge_num_put() and dsa_bridge_num_get().
net/dsa/dsa.c:177 (Fixes trailer):
Patch 6/6 cites `Fixes: f5e165e72b29 ("net: dsa: track unique bridge
numbers
across all DSA switch trees")`, but f5e165e72b29 (and 3f9bb0301d50)
guarded
clear_bit() with dsa_bridge_num_find(). It was commit d3eed0e57d5d ("net:
dsa:
keep the bridge_dev and bridge_num as part of the same structure") that
removed
the dsa_bridge_num_find() check in dsa_bridge_num_put() (and dropped
`&& bridge->num` in dsa_bridge_num_find()). Update to `Fixes:
d3eed0e57d5d`.
net/dsa/dsa.c:184 (dsa_bridge_num_put -> dsa_bridge_num_find):
dsa_tree_list and dst->ports are mutated under dsa2_mutex without
rtnl_lock()
(dsa_register_switch()/dsa_unregister_switch()), whereas
dsa_bridge_num_get()
and now dsa_bridge_num_put() walk dsa_tree_list under rtnl_lock() without
dsa2_mutex (and taking dsa2_mutex under rtnl_lock() would invert lock
order
versus dsa_switch_shutdown()). Pre-existing race, not introduced here.
pw-bot: cr
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2026-12-06 3:57 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-28 16:51 [PATCH net 0/6] net: dsa: offload_fwd_mark on unbridged ports, bridge numbers across switches Julius Bairaktaris
2026-11-28 16:52 ` [PATCH net 1/6] net: dsa: free struct dsa_bridge after an RCU grace period Julius Bairaktaris
2026-11-28 16:52 ` [PATCH net 2/6] net: dsa: tag_sja1105, tag_vsc73xx_8021q: read the bridge once in xmit Julius Bairaktaris
2026-12-06 3:54 ` willemb
2026-11-28 16:52 ` [PATCH net 3/6] net: dsa: tag_dsa: send a marked frame of an unbridged port from the CPU Julius Bairaktaris
2026-12-06 3:55 ` willemb
2026-11-28 16:52 ` [PATCH net 4/6] net: dsa: do not hand a switch a bridge number above its limit Julius Bairaktaris
2026-12-06 3:55 ` willemb
2026-11-28 16:52 ` [PATCH net 5/6] net: dsa: do not take a bridge number past the end of the bitmap Julius Bairaktaris
2026-11-28 16:52 ` [PATCH net 6/6] net: dsa: keep a bridge number while another tree uses it Julius Bairaktaris
2026-12-06 3:57 ` willemb
2026-12-06 3:54 ` [PATCH net 0/6] net: dsa: offload_fwd_mark on unbridged ports, bridge numbers across switches willemb
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.