🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
1 messages
1 total messages Started by memoriaru Sat, 31 Oct 2026 08:18
[PATCH net v4 2/3] net: dsa: mxl862xx: validate the bridge id returned by BRIDGE_ALLOC
#9114
Author: memoriaru
Date: Sat, 31 Oct 2026 08:18
99 lines
13205 bytes
From: Zhang Hewei <memoriaru@foxmail.com>

mxl862xx_allocate_bridge() only checks the transport status and
returns the firmware-supplied bridge id verbatim. Two problems:

- MXL862XX_API_READ() returns the firmware result value (>= 0) on
  success, not an errno. A CRC-valid firmware status of 1..1023 comes
  back as a positive value that passes the "if (ret)" guard, skipping
  the bridge_id validation entirely; the callers store that status in
  priv->bridges[] because they only test ret < 0. Split the transport
  result from the payload id: forward negative errnos, turn a non-zero
  firmware status into -EIO, and keep the contract checks on the
  ret == 0 path.

- the returned bridge id itself is never validated: id 0 is reserved
  and doubles as the "not allocated" value in priv->bridges[] and
  priv->ports[].fid (it also collides with MXL862XX_DEFAULT_BRIDGE,
  the CPU port); 0xffff is the INVALID_HANDLE of the MaxLinear GSW
  API; and a duplicate id collapses the FID isolation of two domains
  (FDB and MDB entries are matched by FID, VID and MAC). Firmware
  that follows the API never returns these values; the checks only
  guard against firmware that breaks it.

Fixes: 340bdf984613c4a9 ("net: dsa: mxl862xx: implement bridge offloading")
Reported-by: netdev-bot+sashiko@kernel.org
Signed-off-by: Zhang Hewei <memoriaru@foxmail.com>
---
 drivers/net/dsa/mxl862xx/mxl862xx.c | 47 +++++++++++++++++++++++++++--
 1 file changed, 45 insertions(+), 2 deletions(-)

diff --git a/drivers/net/dsa/mxl862xx/mxl862xx.c b/drivers/net/dsa/mxl862xx/mxl862xx.c
index 37e8c18f1..fe4db9b7f 100644
--- a/drivers/net/dsa/mxl862xx/mxl862xx.c
+++ b/drivers/net/dsa/mxl862xx/mxl862xx.c
@@ -589,16 +589,59 @@ static int mxl862xx_vf_alloc(struct mxl862xx_priv *priv,
 	return mxl862xx_vf_entry_discard(priv, vf->block_id, 0);
 }
 
+/* Firmware bridge ids are stored in priv->bridges[] (bridged ports)
+ * and priv->ports[].fid (standalone ports, which also allocate one),
+ * so a fresh allocation must not collide with either.
+ */
+static bool mxl862xx_bridge_id_in_use(struct mxl862xx_priv *priv, u16 id)
+{
+	int i;
+
+	for (i = 0; i <= MXL862XX_MAX_BRIDGES; i++)
+		if (priv->bridges[i] == id)
+			return true;
+
+	for (i = 0; i < MXL862XX_MAX_PORTS; i++)
+		if (priv->ports[i].fid == id)
+			return true;
+
+	return false;
+}
+
 static int mxl862xx_allocate_bridge(struct mxl862xx_priv *priv)
 {
 	struct mxl862xx_bridge_alloc br_alloc = {};
+	u16 id;
 	int ret;
 
+	/* MXL862XX_API_READ() returns the firmware result value (>= 0) on
+	 * success, not an errno. A non-zero result is a firmware-reported
+	 * error status: return a proper error instead of leaking it to the
+	 * callers, which only test ret < 0 and would otherwise store the
+	 * status as a bridge id.
+	 */
 	ret = MXL862XX_API_READ(priv, MXL862XX_BRIDGE_ALLOC, br_alloc);
-	if (ret)
+	if (ret < 0)
 		return ret;
+	if (ret > 0)
+		return -EIO;
+
+	id = le16_to_cpu(br_alloc.bridge_id);
+
+	/* The API reserves id 0 ("not used for historic reasons"), which
+	 * also doubles as the "not allocated" value in priv->bridges[]
+	 * and priv->ports[].fid, and collides with
+	 * MXL862XX_DEFAULT_BRIDGE (the CPU port). It documents
+	 * INVALID_HANDLE for failed allocations without defining its
+	 * value; the MaxLinear GSW API uses 0xffff, so reject that too.
+	 * A duplicate id would collapse the FID isolation of two domains
+	 * (FDB and MDB entries are matched by FID, VID and MAC).
+	 * Firmware that follows the API never returns these values.
+	 */
+	if (!id || id == 0xffff || mxl862xx_bridge_id_in_use(priv, id))
+		return -EIO;
 
-	return le16_to_cpu(br_alloc.bridge_id);
+	return id;
 }
 
 static void mxl862xx_free_bridge(struct dsa_switch *ds,
-- 
2.39.5 (Apple Git-154)
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