Re: [PATCH net 4/6] net: dsa: do not hand a switch a bridge number above its limit

From: willemb

Date: Sat Dec 05 2026 - 22:55:53 EST


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@xxxxxxxxxxxxxx>

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.