🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
2 messages
2 total messages Started by memoriaru Fri, 13 Nov 2026 12:45
[PATCH net] net: dsa: mxl862xx: bound FDB dump walk with a read limit
#15826
Author: memoriaru
Date: Fri, 13 Nov 2026 12:45
76 lines
12031 bytes
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)
Re: [PATCH net] net: dsa: mxl862xx: bound FDB dump walk with a read limit
#19517
Author: Jakub Kicinski
Date: Fri, 20 Nov 2026 00:40
9 lines
8021 bytes
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.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads