[PATCH net 5/6] net: dsa: do not take a bridge number past the end of the bitmap
From: Julius Bairaktaris
Date: Sat Nov 28 2026 - 11:52:46 EST
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@xxxxxxxxxxxxxx>
---
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