🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #9114

[PATCH net v4 2/3] net: dsa: mxl862xx: validate the bridge id returned by BRIDGE_ALLOC

#9114
From: 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)
Technical Details
Message-ID: <tencent_D44024D3F44A0AEBD55B1ACB4D0C3F14A308@qq.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-354056-linux-kernel-netdev=dewy.ru
References: <20261031081813.64518-1-memoriaru@foxmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-354056-linux-kernel-netdev=dewy.ru
From: memoriaru@foxmail.com
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v4 2/3] net: dsa: mxl862xx: validate the bridge id returned by BRIDGE_ALLOC
Date: Sat, 31 Oct 2026 16:18:12 +0800
Organization: Usenet Network
Message-ID: <tencent_D44024D3F44A0AEBD55B1ACB4D0C3F14A308@qq.com>
References: <20261031081813.64518-1-memoriaru@foxmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2408985"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:FT+M/20I/laV6H7SKfipjR70FFg= sha256:lKXQqZ8TmGOl6NZfuu5qIENYU8tra+66Wa+s0Dk37NI=
	sha1:8I0K71gaSwZWoIIvGQZKo8k5OTE= sha256:as+TJT/2F93PcOWFShtf3wIWSY2Q+S6sHApL/QBN/7s=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 023F8125CB5; Sat, 31 Oct 2026 11:19:18 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.148
X-Spam-Status: No, score=-3.148 tagged_above=-9999 required=6.31
	tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
	FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001,
	HEADER_FROM_DIFFERENT_DOMAINS=0.25, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
	autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key)
	header.d=foxmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id pcC1PPuLYtno;
	Sat, 31 Oct 2026 11:19:16 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-354056-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=foxmail.com
X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id A31D2125CB2; Sat, 31 Oct 2026 11:19:07 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id 633BC24697; Sat, 31 Oct 2026 08:18:43 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1793434722;
	b=qoMLpPDw9mHykS4jMb7C3EpKSnnVH/nIVSndZaNh03LtFTOvO2BQmHfIzbUVrIeCRgJt
	 9dzFqCmbDKcoQXS1ESWvU9tClCZ03NX8hyAwcpyBcsgDxf6A91APKz9GQOjydDpna+J4h
	 OuO5w3twDpwYY0yGwRZ4tY2ZLiCy+V0bxZlv8jNmLSKzF0MyDPjTnvi3HZ2P7ZyZcZADh
	 DA1rtIqnqKVwCqpzz9s1zCeJNf38Mm3JmBBbNTe1ZvWI54jlOd9bA0fM1wXKkUvC1g4RE
	 lclMekL3gSzp3PxSjg+wjfu4jfSWlrrF9imhQDgbJ+X1OivKfylPizDiyg8dcKfKNIQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793434722;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Received:X-QQ-mid:
	 Message-ID:X-QQ-XMAILINFO:X-QQ-XMRINFO:From:To:Cc:Subject:Date:
	 X-OQ-MSGID:X-Mailer:In-Reply-To:References:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version:Content-Transfer-Encoding;
	bh=PVFuo8DbMy9Fqwdre1xQiPEF5EJOHp5QAIiV+UV03ak=;
	b=OLOIsmaCv1g1StvWhrEXt7oAelX0oWgFbA42Vk1UgskqTAxmscCcHiHQD2dElsR6cNqN
	 RyGdfVNnnyEGMYCHacbVtVM7Jnob7H/LUuST8Csk9iELTAkVyTTDeIYgRrJy/+Ii4jw5w
	 qMpo5yxMfYDRgk0aJua2Rx5l4lvJLCPh7fw9sY+RQMQOTbug4Z0FO4SYbsW63ggcR18I1
	 WI7l79aDlCkN7JspbZBiHuF3GQgj8zxeMXiU8juDv51dzzGMd7gYSbOvQtxs3UgcX85SY
	 SDsatMUXAJOwAP8Her/X4DwDDCfPePlSauFKj89d9PXDiOmlzkruA3Pn9wY6E29eYeg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=foxmail.com header.i=@foxmail.com header.a=rsa-sha256 header.s=s201512 header.b=vLrO30q2;
	dmarc=pass header.from=foxmail.com;
	spf=pass smtp.mailfrom=foxmail.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id F41B2606A329;
	Sat, 31 Oct 2026 08:18:41 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key, unprotected) header.d=foxmail.com header.i=@foxmail.com header.a=rsa-sha256 header.s=s201512 header.b=vLrO30q2
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=162.62.57.49
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793434711;
	b=WnU6P2e6fSKvtC93w5sQqXw2PP+D0JKkjzFb/++DoBdUyg+SswiP5WAryWJGX0ImQy1q
	 dW9NnbHs2aN31CkC7xibooqJr+5O14+HWk2rJiEFUXWr7N16VZqymXusAyhqQlalhbpbv
	 S+QkKH3zne2vv+KUkQPxGajo2vj+6KxKAY83vcrV8k0mREQO0Ib5jCBhGy2/6MAUImInk
	 185Dg62xjjJ0oa0+Jsvd1/kEzv4Kw3mdJWw1NrHHhhxwyk6ElBlgt8ZcbJpfEv8xkThCJ
	 NrxL61sqluKNi+sva+XuGujtEGKNbgRHREcQQDix8rT4xfIoM3mSxx+mtz2PnNpQveg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793434711;
	h=DMARC-Filter:DKIM-Signature:Received:X-QQ-mid:Message-ID:
	 X-QQ-XMAILINFO:X-QQ-XMRINFO:From:To:Cc:Subject:Date:X-OQ-MSGID:
	 X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Transfer-Encoding;
	bh=PVFuo8DbMy9Fqwdre1xQiPEF5EJOHp5QAIiV+UV03ak=;
	b=yRwmwUhyxHhyCLfGop0E22DWtnRdTLcSYqKrrvkV5knaJv3Ukhc62s6kfMWy+slQJHO6
	 sPnQ5VwjdJyORdxmGhgdGpLSS2si4vu44k5xXACx/bMXWx1CBGm7z6r/E6jthRd2iVNuS
	 2OFLVaJgv0CiNrA3jiFxS6O6iJWqkmYJWz4HRZcQytS95VMcjRNJbgyDQH11aQ07TXozm
	 Soce2X0HiH68AD7jgCiGVRnALDEBXK9rY+0Da3jGipcRIogn1P5S7AOBkpKq10JTmlIS/
	 MYF6uaz6J7lSicdRkziq7tx3JGLO+1A04Vj+yYH2eUfWyWT1T240nMd7GIVIl0t1YkA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=foxmail.com;
	spf=pass smtp.mailfrom=foxmail.com;
	dkim=pass header.d=foxmail.com header.i=@foxmail.com header.a=rsa-sha256 header.s=s201512 header.b=vLrO30q2;
	arc=none smtp.remote-ip=162.62.57.49
X-Received: from out162-62-57-49.mail.qq.com (out162-62-57-49.mail.qq.com [162.62.57.49])
	(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F1A4606A32A
	for <netdev@vger.kernel.org>; Sat, 31 Oct 2026 08:18:28 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7F1A4606A32A
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foxmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foxmail.com
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com;
	s=s201512; t=1793434699;
	bh=PVFuo8DbMy9Fqwdre1xQiPEF5EJOHp5QAIiV+UV03ak=;
	h=From:To:Cc:Subject:Date:In-Reply-To:References;
	b=vLrO30q2t8jmX+U0SIgcOIEND/wCbtj9cGtGtSQsV1QMzZWcDdcju7rGZX/zmIbk0
	 GLe0uhW9rJhwp/Iyq8hY9tYia5LlCcHeZAMpqEFDFxu3dqnMsis46Fnq4WTV74JPCo
	 i62CcJLI+BuHfRJFhNUWvkaJ1XhWcXrICAEvD0FU=
X-Received: from localhost.localdomain ([240e:3bb:302c:4eb1:751b:856d:f57c:9109])
	by newxmesmtplogicsvrsza63-0.qq.com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DW2sEfhwS5LVvkrhgsHs3Il
	 kmnd0sGVlOr/SMMjr1ggnlXKaT3clgowmcyVGstXmYXz804Yozgjo6/dTT6ujUUq7BDLuhmDWVMD
	 ypAJVkqpHd6fwo97dEzNwgQ1auoZBrKqgNvcg0Aw==
X-QQ-XMRINFO: MPJ6Tf5t3I/ylTmHUqvI8+Wpn+Gzalws3A==
X-Cc: daniel@makrotopia.org,
	andrew@lunn.ch,
	f.fainelli@gmail.com,
	olteanv@gmail.com,
	johan@kernel.org,
	kuba@kernel.org,
	pabeni@redhat.com
X-OQ-MSGID: <20261031081813.64518-3-memoriaru@foxmail.com>
X-Mailer: git-send-email 2.39.5 (Apple Git-154)
X-In-Reply-To: <20261031081813.64518-1-memoriaru@foxmail.com>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list