* [PATCH net] net: dsa: mxl862xx: bound FDB dump walk with a read limit
@ 2026-11-13 12:45 memoriaru
2026-11-20 0:40 ` Jakub Kicinski
0 siblings, 1 reply; 2+ messages in thread
From: memoriaru @ 2026-11-13 12:45 UTC (permalink / raw)
To: netdev; +Cc: daniel, andrew, f.fainelli, olteanv, kuba, pabeni, memoriaru
From: Zhang Hewei <memoriaru@foxmail.com>
mxl862xx_port_fdb_dump() walks the MAC table in a while (true) loop
whose only exit is the device-reported "last" flag, holding RTNL for
the whole duration. Entries for other ports are skipped without
invoking the DSA callback, so the netlink dump buffer never fills and
the loop has no other way to terminate.
If the firmware crashes or misbehaves mid-walk and never sets the last
flag, the driver spins forever with RTNL held, blocking all netlink
configuration and stack operations on the system.
Bound the walk with a conservative read limit (16k, well above any
documented table size for this family) and return -EIO when it is
exceeded. The limit is checked after the "last" test so that a
correctly ended walk of a full table is not rejected: the walk needs
one read more than the number of entries it reports.
Not tested on real hardware; found by code inspection while auditing
the loop termination conditions.
Fixes: 340bdf984613c4a9 ("net: dsa: mxl862xx: implement bridge offloading")
Signed-off-by: Zhang Hewei <memoriaru@foxmail.com>
---
drivers/net/dsa/mxl862xx/mxl862xx.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/drivers/net/dsa/mxl862xx/mxl862xx.c b/drivers/net/dsa/mxl862xx/mxl862xx.c
index e05ad52cd..37e8c18f1 100644
--- a/drivers/net/dsa/mxl862xx/mxl862xx.c
+++ b/drivers/net/dsa/mxl862xx/mxl862xx.c
@@ -30,6 +30,11 @@
*/
#define MXL862XX_STATS_POLL_INTERVAL (2 * HZ)
+/* Conservative bound for the MAC table read loop: the exact capacity is
+ * not part of the public driver API (see mxl862xx_port_fdb_dump()).
+ */
+#define MXL862XX_MAC_TABLE_WALK_LIMIT 16384
+
struct mxl862xx_mib_desc {
unsigned int size;
unsigned int offset;
@@ -1503,6 +1508,7 @@ static int mxl862xx_port_fdb_dump(struct dsa_switch *ds, int port,
struct mxl862xx_mac_table_read param = { .initial = 1 };
struct mxl862xx_priv *priv = ds->priv;
u32 entry_port_id;
+ int count = 0;
int ret;
while (true) {
@@ -1513,6 +1519,22 @@ static int mxl862xx_port_fdb_dump(struct dsa_switch *ds, int port,
if (param.last)
break;
+ /* The exact MAC table capacity is not part of the public
+ * driver API. Use a conservative read limit: 16k is well
+ * above any documented table size for this family. Checked
+ * after the "last" test so that a correctly ended walk of
+ * a full table is not rejected; if the firmware dies or
+ * misbehaves mid-walk this also stops us from spinning
+ * forever with RTNL held.
+ */
+ if (count++ >= MXL862XX_MAC_TABLE_WALK_LIMIT) {
+ dev_err(ds->dev,
+ "FDB dump walk exceeded %d reads, aborting\n",
+ MXL862XX_MAC_TABLE_WALK_LIMIT);
+ return -EIO;
+ }
+
entry_port_id = le32_to_cpu(param.port_id);
if (entry_port_id == port) {
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net] net: dsa: mxl862xx: bound FDB dump walk with a read limit
2026-11-13 12:45 [PATCH net] net: dsa: mxl862xx: bound FDB dump walk with a read limit memoriaru
@ 2026-11-20 0:40 ` Jakub Kicinski
0 siblings, 0 replies; 2+ messages in thread
From: Jakub Kicinski @ 2026-11-20 0:40 UTC (permalink / raw)
To: memoriaru; +Cc: netdev, daniel, andrew, f.fainelli, olteanv, pabeni
On Fri, 13 Nov 2026 20:45:08 +0800 memoriaru@foxmail.com wrote:
> If the firmware crashes or misbehaves mid-walk and never sets the last
> flag, the driver spins forever with RTNL held, blocking all netlink
> configuration and stack operations on the system.
Patch does not apply, not sure this is worth fixing tho.
I'm sure LLMs can point out 10,000 potentially unbounded loops
in the tree. And you don't even have HW to test this.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-20 0:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-13 12:45 [PATCH net] net: dsa: mxl862xx: bound FDB dump walk with a read limit memoriaru
2026-11-20 0:40 ` Jakub Kicinski
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.