🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #19170

[PATCH net-next v4 4/4] net: dsa: qca8k: bound the data of a management ack frame

#19170
From: Stanislaw Pal
Date: Thu, 19 Nov 2026 13:41
103 lines
15106 bytes
qca8k_rw_reg_ack_handler() answers a management read by copying the
data that follows the Ethernet header into mgmt_eth_data->data. It
trusts the frame for both the length and the layout: the length field
of the frame allows up to 32 bytes while the buffer holds 16, so a
frame announcing more than three registers writes past the buffer into
the fields that follow it in qca8k_priv; and qca_tag_rcv() made only
the 2 byte tag linear, so the copy reads skb->data without checking
that the frame has the bytes it announces. The handler runs for every
ack frame, whatever its sequence number.

Size the buffer to what a management frame can carry, and pull the
announced data into the linear area before reading it. The pull can
move the head, so take the Ethernet header again after it. A frame
that is too short is left unacknowledged, so the read fails and the
caller falls back to MDIO.

An LLM assistant (Claude, claude-fable-5-1 and claude-opus-5-5) helped
write the change and this description; I reviewed both and built them
with W=1 on arm64. The management path was exercised on a QCA8337
behind an IPQ5018 (GL.iNet GL-B3000) with tag_qca.

Fixes: 90386223f44e ("net: dsa: qca8k: add support for larger read/write size with mgmt Ethernet")
Signed-off-by: Stanislaw Pal <kuncy7@gmail.com>
---
 drivers/net/dsa/qca/qca8k-8xxx.c | 24 +++++++++++++++++++-----
 drivers/net/dsa/qca/qca8k.h      |  3 ++-
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/drivers/net/dsa/qca/qca8k-8xxx.c b/drivers/net/dsa/qca/qca8k-8xxx.c
index 76c0f7c97b..9a7e90f48d 100644
--- a/drivers/net/dsa/qca/qca8k-8xxx.c
+++ b/drivers/net/dsa/qca/qca8k-8xxx.c
@@ -170,6 +170,7 @@ static void qca8k_rw_reg_ack_handler(struct dsa_switch *ds, struct sk_buff *skb)
 	struct qca8k_mgmt_eth_data *mgmt_eth_data;
 	struct qca8k_priv *priv = ds->priv;
 	struct qca_mgmt_ethhdr *mgmt_ethhdr;
+	int data_len = 0;
 	u32 command;
 	u8 len, cmd;
 	int i;
@@ -190,6 +191,20 @@ static void qca8k_rw_reg_ack_handler(struct dsa_switch *ds, struct sk_buff *skb)
 	/* We can ignore odd value, we always round up them in the alloc function. */
 	len *= sizeof(u16);
 
+	if (cmd == MDIO_READ && len > QCA_HDR_MGMT_DATA1_LEN)
+		data_len = min_t(int, QCA_HDR_MGMT_DATA2_LEN,
+				 len - QCA_HDR_MGMT_DATA1_LEN);
+
+	/* The tagger made only the tag linear. Leave a frame that is too
+	 * short for the data it announces unacknowledged: the read fails
+	 * and the caller falls back to MDIO.
+	 */
+	if (data_len && !pskb_may_pull(skb, data_len))
+		goto complete;
+
+	/* pskb_may_pull() may have moved the head */
+	mgmt_ethhdr = (struct qca_mgmt_ethhdr *)skb_mac_header(skb);
+
 	/* Make sure the seq match the requested packet */
 	if (get_unaligned_le32(&mgmt_ethhdr->seq) == mgmt_eth_data->seq)
 		mgmt_eth_data->ack = true;
@@ -199,13 +214,11 @@ static void qca8k_rw_reg_ack_handler(struct dsa_switch *ds, struct sk_buff *skb)
 
 		*val = get_unaligned_le32(&mgmt_ethhdr->mdio_data);
 
-		/* Get the rest of the 12 byte of data.
-		 * The read/write function will extract the requested data.
+		/* Get the rest of the data.
+		 * The read function extracts what it asked for.
 		 */
-		if (len > QCA_HDR_MGMT_DATA1_LEN) {
+		if (data_len) {
 			__le32 *data2 = (__le32 *)skb->data;
-			int data_len = min_t(int, QCA_HDR_MGMT_DATA2_LEN,
-					     len - QCA_HDR_MGMT_DATA1_LEN);
 
 			val++;
 
@@ -217,6 +230,7 @@ static void qca8k_rw_reg_ack_handler(struct dsa_switch *ds, struct sk_buff *skb)
 		}
 	}
 
+complete:
 	complete(&mgmt_eth_data->rw_done);
 }
 
diff --git a/drivers/net/dsa/qca/qca8k.h b/drivers/net/dsa/qca/qca8k.h
index 79754755f1..b7aa0d832e 100644
--- a/drivers/net/dsa/qca/qca8k.h
+++ b/drivers/net/dsa/qca/qca8k.h
@@ -396,7 +396,8 @@ struct qca8k_mgmt_eth_data {
 	struct mutex mutex; /* Enforce one mdio read/write at time */
 	bool ack;
 	u32 seq;
-	u32 data[4];
+	/* The data a management frame can carry */
+	u32 data[(QCA_HDR_MGMT_DATA1_LEN + QCA_HDR_MGMT_DATA2_LEN) / sizeof(u32)];
 };
 
 struct qca8k_mib_eth_data {
-- 
2.43.0
Technical Details
Message-ID: <20261119134110.15048-5-kuncy7@gmail.com>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367043-linux-kernel-netdev=dewy.ru
References: <20261119134110.15048-1-kuncy7@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367043-linux-kernel-netdev=dewy.ru
From: kuncy7@gmail.com (Stanislaw Pal)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v4 4/4] net: dsa: qca8k: bound the data of a management ack frame
Date: Thu, 19 Nov 2026 14:41:10 +0100
Organization: Usenet Network
Message-ID: <20261119134110.15048-5-kuncy7@gmail.com>
References: <20261119134110.15048-1-kuncy7@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2884531"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:nHDWXHz52po1yVYZqDy5ECKGaDU= sha256:b6XprQgExrX1ovRITszjZEYM2swLtBf5kzi+fuTprKc=
	sha1:+maXHla24sfrGHQ+7l4S2Xps90w= sha256:tEOse9KEvlJZxuS7Pr0PD2P0749XnBTgYPV8geWRi/0=
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 890B9115675; Thu, 19 Nov 2026 16:41:54 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, 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.249,
	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 (2048-bit key)
	header.d=gmail.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 eMX7xD3GJoSM;
	Thu, 19 Nov 2026 16:41:51 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-367043-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 2372E115669; Thu, 19 Nov 2026 16:41:43 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id C51CAE1D06; Thu, 19 Nov 2026 13:41:37 +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=1795095682;
	b=3yHzhRL6ygpRee6iH3/UrPG1WbNsRQMpBP9ELJj459XOwwKjoOlP8a5XQ/mbQ7DDheRB
	 IZ/GHWG0abm+a9b6syu/x055piNYKxhEkYA1/5mHeO+iUAzxTYDSI8R9CDSG4FIueps68
	 ivbItOdnzwdP7Sh7ZeYCA0J5h+yhJUc6jHxtrLos8GAHfMvcV/WUOH6Xxvm46EaLvpUrJ
	 PIX14VlmDet8iEsHJ/fbzLlyAW4u4MuthtTXLvjhcLQhwqgF9MKZLW8EYBxP1LPKf2DmZ
	 UefuM3kQZNLq1HU0ZILVzyJ2d5bCyvZ4YOXAF5I/aNojWqG33xevMjVEACOL3HcKTNg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795095682;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
	 X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:Date:Message-ID:
	 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=epsMv7ubUMbNGL97hoQb0bSNJhUxNTty6N7abdxd6yc=;
	b=T8MppGY1iVvUK56R+RKsvdGtg/uUMNVUjjq127QSzPVkprYSes9B6CzFIuhUtxpKTRRQ
	 5FEvYvMxHJk2FYZm7e4VssFva3Dc5CbMxio0Ru0Gkn1GJBC4yVlj4hJUNIVyBiS0HKqsX
	 MYz+UanIqSs3rxX+J2Q2+56tEaQnuIsVz34sxc0SvL5eNAUKLreMplS2dGx8jS2gDB8v1
	 oTY2h/qn2FWGkUrtotxz7KiEs5k/BZR7rcdewyrm18z/LlO0O0//pLrnRVs7AHvfPWqIH
	 QFj6lhJP/ghnZMcSN4ur8jSvYm0j7j4o3R9xT1bvxGIIageCetMOOJS+yIjTfxEC+Jg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=oseP62wl;
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.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 ACC0360A3813;
	Thu, 19 Nov 2026 13:41:22 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=oseP62wl
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.218.46
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795095681;
	b=noJdXdPNjXvcvFxv7JIbrmY5B/J9/Fy3fLkQVKjk6kHNHy0GsOKYdr+BB8ksYAg2s6i4
	 klTn4YgoirbtG7J0LG4wWEYHWNcr6/eX5oQ2/Gse4st0nXXyfX9PmM8j1MU29lha33e/k
	 SFxR3rTEDFWCeupJlZleeqgHR7v2Ic8kwCfe2Z76iLUALS313Bbi3mSmIoaQUdU9gOShK
	 ctVLfqS8gsUJVTe7YD1q5YjgrwVHvFH3Wa4WkygNCaR6n2aTmAXE3I3YHhPh3PRVctqLQ
	 vThf9cNEbeXdJZK/OnVN1Pn0bWDFYZ+3duRPDHow410rvVljA4bmzPEepWVOnOTn4rg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795095681;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
	 From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:
	 MIME-Version:Content-Transfer-Encoding;
	bh=epsMv7ubUMbNGL97hoQb0bSNJhUxNTty6N7abdxd6yc=;
	b=E7KE/FUo0EwTQ0Rps3GVKj+5epGuOIffPthiWOZ1wNYf46QYYUm4pwOWanBAUFuQxd42
	 lHP2Du7f4p3qq7KSvrTWtFhaptYE2a1xXPQ/Lk3wjcaThrNVtMjbrAstvvsupYkPnz5E3
	 fmXcJEfYpltFmKaDurxymTMGpeD16FCKsfDYHPwnAK7PC205rskB2YSIeAYpzdKBXLLaM
	 /kJiQmBxqAE+5xo1JzjfoskTNkAu6ZZ+KDei/1YYvCNepJzgr0kdulrrdGSLiAbSuigq6
	 TJIPY9JnKCYTiwXsixxF4/dDQ8rf9MuONJeikDAmmOMz68+S4Ho2j6zpB31UjfmPLSQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=oseP62wl;
	arc=none smtp.remote-ip=209.85.218.46
X-Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0DBE460A3804
	for <netdev@vger.kernel.org>; Thu, 19 Nov 2026 13:41:21 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0DBE460A3804
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-c51239b0e3bso178635666b.2
        for <netdev@vger.kernel.org>; Thu, 19 Nov 2026 05:41:20 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20260707; t=1795095679; x=1795700479; darn=vger.kernel.org;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:from:to:cc:subject:date
         :message-id:reply-to:content-type;
        bh=epsMv7ubUMbNGL97hoQb0bSNJhUxNTty6N7abdxd6yc=;
        b=oseP62wlfKUASQ8EyQShWBDIsidX8ySxDvtbL+MsM1me9ZPWI8DKGmkmvKKnYIy0OH
         8zJ7TiMF1ucvWVZEmY6QKtl3/s6o+j+Wv7AGyvRkB+62cEDMysGtmHwzk44UYThpU9Zp
         D47Ai7AJ4yNpY6cNvahucMpRHj8vLRZeNsyAbXyxRkuoXRQifA+hwW1GIQ7C3US3tJ3c
         Cl6Lhb1yvkSC5g8HGZj1bcOC0EbYF+eztpeh/zBylf1uZqDuNpfBV/cc3maJhyhsbPtp
         mcE/FhZlA6n/u/5fW9sKBPDGqVDiSditLdMRuu0GX3XwPFyXDszNXeBpAtEl6+928Zxb
         dXZA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1795095679; x=1795700479;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from
         :to:cc:subject:date:message-id:reply-to:content-type;
        bh=epsMv7ubUMbNGL97hoQb0bSNJhUxNTty6N7abdxd6yc=;
        b=xFo3XuAoW3t/mISh4lbxtm31GdgIy1aMyPWRRRthmELqTOR5k9+jnRvcFCP9jHEUgG
         mtkMFU1fbGIejmYZLwYSXWniGtmwkgaBP/3RKQFvv2tjIOTrgoVhrvobkF/Q+bhra9zy
         ag+iXagMmt5KcGFPgeYCXU81+OUM2Vx2yD3sIwfoxoN3R2TTvPg8vxw9KIOMrTDo+rIc
         0p5WTpVeshM9EBh5OjRDQBP47v0nVPDboAtia/ryYzRVGIiViRP+zqAbp+DvJbHs6q8Q
         l3j+uMiSDq/G3KaDVhv/JJItB+vDWpsJLnMg6VPcY3QdR5E43jjgnRNc2OWW7jN/mYlG
         Mp9g==
X-Forwarded-Encrypted: i=1; AL+hErFC2w/2FlbMjt3SPfsaQyIcb17dwoJUJgLj9LXbfxOk59d9sgeYs3lOOhU9iN1m5clLAeCGtBk=@vger.kernel.org
X-Gm-Message-State: APuU4Z/oXGnw2PxCNcnFm9yB21STPpBTIirbOmldnk7z7DoUhRQUvxVg
	YDaSa6YY86z39/HpKqTRqNVMA2xNly/HHHpFWca8rNbKSZyTvQU9oPb/
X-Gm-Gg: AYBFou2YtcQp7g2LfO6eWkTF3A2qRKt8BgboJklGRvpMf8t//aZq2rW2jN5bDullUTk
	Cn1tv7Y5kHTpZNYhP/YtfzL9hW6Bu+9JR7K0L/ZkANHiMXw7wOOkp8naXWDmiZnLqQQ06pA+CMo
	c5U6Toe0Vm6uU+3YHE8wG+uQCDp5UipzHaU79psJ3EXRNQv1UjdxEOMISJ6pE2LbKVWT1qSC7HF
	MOeDpGrixeLn1KpAYIi7KN2wqOB1okhno9IDB3HOFIJ4ejWc9sAa+jtIskdNb10MeWjHac8spfi
	6TZQ4nXsRjd17EcZhPhz8PPUBweQZM4UMpStZV9sQQp+o+elR54sA0nS2aJ6Sdb80GKPN2zH6p4
	dslRcib6qKqvCKVkPZComTMBsEGxdD9LdRu9mDGKuaTpblna7QkfsViEupza+nhxWTr/z/K0+RG
	i1uW/OqN+gudeywj5Yf0G6k555CLRmxclAwkchzY2najrZ6BiTAQtSGVRB0POlzWvQX1YAYMjnD
	eplqFZMcCseEvbBNKArTKFweWc6q4DmVB+b0i9h3GhznpjH2y7VI7JEWOsKq+M/HMuta+1EdtSP
	RIZnnUgbu+rDxI4IJ1TJtuID2IVm9XfpM3WxRj4tsld+2Ly2VdQvCcv0XkAAvthC9KH/qDjmHR7
	4uaWTf4v1jV9j/w==
X-Received: by 2002:a17:907:c8c8:b0:c49:cf3a:a324 with SMTP id a640c23a62f3a-c510e148c36mr562345166b.22.1795095679437;
        Thu, 19 Nov 2026 05:41:19 -0800 (PST)
X-Received: from VivoBook-ASUS-X712UA-M712UA.lan (user-31-175-182-49.play-internet.pl. [31.175.182.49])
        by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c512346fc3fsm105582666b.59.2026.11.19.05.41.17
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 19 Nov 2026 05:41:18 -0800 (PST)
X-Cc: "David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	Yongzhao Chen <yongzhao.derek@gmail.com>,
	Alexey Immoreev <luixo-public@luixo.me>,
	netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
X-Mailer: git-send-email 2.43.0
X-In-Reply-To: <20261119134110.15048-1-kuncy7@gmail.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