[PATCH net 4/6] net: dsa: do not hand a switch a bridge number above its limit
From: Julius Bairaktaris
Date: Sat Nov 28 2026 - 11:52:41 EST
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@xxxxxxxxxxxxxx>
---
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