๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #21106

Re: [PATCH net-next v3 5/9] net: sparx5/lan969x: size the FDMA buffers from the port MTUs

#21106
From: netdev-bot+sashiko
Date: Mon, 23 Nov 2026 14:58
162 lines
14448 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 (1) ยท High: 1 ยท Medium: 0 ยท Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] net: sparx5: UAF of two-step PTP skb on TX drop in
  sparx5_port_xmit_impl()

Pre-existing issues:
- [Critical] Use-after-free and double free of two-step PTP skbs on the
  Sparx5 TX drop path.

--

net: sparx5/lan969x: size the FDMA buffers from the port MTUs

This commit sizes the Sparx5 and lan969x FDMA buffers from the largest port
MTU plus the Ethernet header, FCS, IFH and two VLAN tags, rather than a
fixed single page. On Sparx5 the RX and TX DB size is that length rounded
up to 128 bytes, and sparx5_fdma_xmit() now drops frames that do not fit.
On lan969x the page_pool page order is derived from the max frame size.

> diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c b/drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c
> index 537c945409bba..b92d249777f0b 100644
> --- a/drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c
> +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c

[ ... ]

> @@ -224,6 +223,10 @@ int sparx5_fdma_xmit(struct sparx5 *sparx5, u32 *ifh, struct sk_buff *skb,
>  	struct fdma *fdma = &tx->fdma;
>  	void *virt_addr;
>  
> +	/* Drop frames that do not fit in the TX buffers */
> +	if (unlikely(IFH_LEN * 4 + skb->len + ETH_FCS_LEN > fdma->db_size))
> +		return -EMSGSIZE;
> +

[Severity: High]
This is a pre-existing problem in sparx5_port_xmit_impl(), but the
new -EMSGSIZE return makes it much easier to hit. What happens to a
two-step PTP skb that fails here?

sparx5_port_xmit_impl() calls sparx5_ptp_txtstamp_request() before
ops->fdma_xmit(). For two-step PTP, that puts the skb on
port->tx_skbs with skb_queue_tail() without taking an extra
reference. It also increments sparx5->ptp_skbs and port->ts_id.

If fdma_xmit() then returns anything other than -EBUSY, the code
jumps to the drop label, which only calls dev_kfree_skb_any(skb).
Only the busy label calls sparx5_ptp_txtstamp_release(port, skb). The
freed skb is therefore still linked on port->tx_skbs.

Later walks of port->tx_skbs happen in
sparx5_ptp_txtstamp_old_release(), in the sparx5 and lan969x PTP IRQ
handlers, and in sparx5_ptp_deinit(). These read SPARX5_SKB_CB() from
freed memory, call __skb_unlink() through stale list pointers, and
call dev_kfree_skb_any() on the same skb again. Isn't that a
use-after-free and a double free?

sparx5->ptp_skbs is also never decremented for these skbs. After
SPARX5_MAX_PTP_ID such drops, sparx5_ptp_txtstamp_request() returns
-EBUSY forever, and two-step TX timestamping on the switch stalls.

Before this patch the Sparx5 TX DB was PAGE_SIZE. The drop path could
only be reached through the -EINVAL ring-full return here, or through
the -ENOMEM DMA mapping failure in lan969x_fdma_xmit(). With the
default MTU of 1500, db_size is now
ALIGN(1518 + 36 + 8, 128) = 1664. Any two-step frame with skb->len
above 1624 now takes the drop path every time.

Such frames can still reach a 1500 MTU port, for example through tc
mirred or bpf_redirect from a device with a larger MTU. They can also
arrive when the MTU is lowered while larger skbs are already queued,
which becomes possible later in this series.

The commit message relies on this drop path. Should the drop label in
sparx5_port_xmit_impl() release two-step PTP skbs the same way the
busy label does? Or would you rather check the length before
sparx5_ptp_txtstamp_request() is called?

[Severity: Critical]
This is a pre-existing issue, but this new return gives a second,
deterministic way to hit it. What happens to a two-step PTP skb that gets
-EMSGSIZE here?

By this point, sparx5_port_xmit_impl()->sparx5_ptp_txtstamp_request() has
already put the skb on port->tx_skbs without taking a reference:

sparx5_ptp.c:sparx5_ptp_txtstamp_request() {
    ...
	skb_queue_tail(&port->tx_skbs, skb);
	SPARX5_SKB_CB(skb)->ts_id = port->ts_id;
	SPARX5_SKB_CB(skb)->jiffies = jiffies;

	sparx5->ptp_skbs++;
	port->ts_id++;
    ...
}

Back in sparx5_port_xmit_impl(), only -EBUSY goes through
sparx5_ptp_txtstamp_release(). Any other negative return frees the skb
while it is still on the list:

sparx5_packet.c:sparx5_port_xmit_impl() {
    ...
	if (ret == -EBUSY)
		goto busy;
	if (ret < 0)
		goto drop;
    ...
drop:
	stats->tx_dropped++;
	sparx5->tx.dropped++;
	dev_kfree_skb_any(skb);
	return NETDEV_TX_OK;
busy:
	if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP &&
	    SPARX5_SKB_CB(skb)->rew_op == IFH_REW_OP_TWO_STEP_PTP)
		sparx5_ptp_txtstamp_release(port, skb);
	return NETDEV_TX_BUSY;
}

The next two-step request then walks the list in
sparx5_ptp_txtstamp_old_release():

	skb_queue_walk_safe(&port->tx_skbs, skb, skb_tmp) {
		if time_after(SPARX5_SKB_CB(skb)->jiffies + SPARX5_PTP_TIMEOUT,
			      jiffies)
			break;

		__skb_unlink(skb, &port->tx_skbs);
		dev_kfree_skb_any(skb);

Does this read the cb of the freed skb and then free it again? The TX
timestamp IRQ handler can also find the stale entry. ptp_skbs and ts_id
also stay incremented, so can the PTP ID pool run out?

This path could already be reached through the -EINVAL return when the
next TX DB is not done, i.e. when the TX ring is full.

With this patch and the default MTU of 1500, db_size goes from 4096 to
ALIGN(1518 + 36 + 8, 128) = 1664. A two-step timestamped frame longer
than 1624 bytes used to be sent, but now it always takes the drop path.
Such frames can still reach a 1500 MTU port, for example through tc
mirred or bpf_redirect from a device with a larger MTU.

The commit message says it will "make sparx5_fdma_xmit() drop frames that
do not fit", so it depends on this drop path. Should the drop label in
sparx5_port_xmit_impl() call sparx5_ptp_txtstamp_release() for two-step
PTP skbs, the same way the busy label does? sparx5_port_xmit_impl() is
still unchanged at the end of the series.

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120-sparx5-mtu-change-v3-0-55c272fe1acc%40microchip.com
Technical Details
Message-ID: <179544589573.3135.16010204842375196022@kernel.org>
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369507-linux-kernel-netdev=dewy.ru
References: <20261120-sparx5-mtu-change-v3-5-55c272fe1acc@microchip.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369507-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v3 5/9] net: sparx5/lan969x: size the FDMA
 buffers from the port MTUs
Date: Mon, 23 Nov 2026 14:58:15 +0000
Organization: Usenet Network
Message-ID: <179544589573.3135.16010204842375196022@kernel.org>
References: <20261120-sparx5-mtu-change-v3-5-55c272fe1acc@microchip.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3907457"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:3W8IDUlsgB8XuBB7T1Oxg8eu5sI= sha256:0dlV1x2/pK9qROR7pWo8/GDELw10KX6a5hoR8C/jGyQ=
	sha1:40a+OrEo8Tgoz+U6cxuiHMUa12k= sha256:Fd+XbzYOK7xuJJGQFaTQymtWyByW1IPFgcjBx98FUvg=
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 9E306125DB7; Mon, 23 Nov 2026 17:59:28 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	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=kernel.org
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 HLr5Fnmm0oFf;
	Mon, 23 Nov 2026 17:59:24 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-369507-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 49D6D125DBB; Mon, 23 Nov 2026 17:59:15 +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 DCE3E312F2; Mon, 23 Nov 2026 14:58:34 +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=1795445903;
	b=5bD4FHIANdpb1q5TgCClr0z7K79t7w25XpYbbAL+ep/gQ1Na844akP3/o+hEc91UyALh
	 gjFAeWOCPrzk0/QEMCdvkjWSzRUlDmyrlUMgc4ArmtBTilmAB3ztM+LubdmaJedOcdlyf
	 WT5LUQ8IvpohKTFrVSqODqF4y+4ma9zBw4HY0ia5PItrH5LCjAQEF4N5gtkOHqjdTXx07
	 c9T/KSx4D7tJ6R3evY7vLNzLvHDEM0NBA4rL5K72lqdzhW2cT1OIYdoYA6nBFF5iGsCmL
	 BMr4VPel9dgf40DNn8nKpKtJ2bmD+Q7O9bms/jiRDW6fXh7vkJqnZkmBw5ibZI/sWJw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795445903;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=FPZIAOyVkBpe9724KFBEseTEXrvfOC8DdMEfIRc3mW0=;
	b=vpb/UDDD1feK3Nad7HZ8EjjobGnQaUQ+CPNSrKCtnw3COf47BrBLGhFmeqjE2J0/g7Sy
	 l74WZ23pcYdy5MBPdPl+b5AAcXOaEv3Zht0T6cMEiS7/cdVImvGzjzfiFFSwFSsb0cIPr
	 NXLOD25Yi6yiTsrplbIPwMMr2KA8JLTkUGAHvT0mbQDXFMkwkgvWdaSeerRe/7coE3Gg+
	 l3MRr4PhTEnDr83iKboTNAWUoMBNff7JTbK2mDa8IDUHx8wI28V4O8UdjbobWfc8pDPLd
	 YEvVVkq3adFOQMvIeWFreE0HYdMMUTufe31cw0hQeAGYdHxtrAhsm7SJYsEGAh/JvbA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="V/8w1HJy";
	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 74566606A31E;
	Mon, 23 Nov 2026 14:58:23 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=V/8w1HJy
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795445897;
	b=VRMt+UNAYisSckHz7TBrJGNsR6CZzgX8kOx3QH93YBUVIXJHZTG1NFL7PNZMZC8Abixa
	 Y5b+dopTtAA66SD/whO71IGFiYrzQJujPVQfBVVgFnj1/0Opu++hFZfIO5e9mngi+fDHv
	 V0n3SSJeYqUDsRlRF2Ym9iSWg68IMBBP0gh9P7JEl8L2sj+MaZITXz8B1kLj+Z7RFaJxE
	 ESjcbylalocI8g8ugNYY5dYwRXbabCKRI0JLmSRnBgQBiwXkOwZJYlg8juoYef0ZrPKn8
	 Zl2jJvWltjYIn19BVIBAzwc8OTwQN2GJUv/TiCyEu0nf1WByBXfxYYHdCOzzvdaIp/A==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795445897;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=FPZIAOyVkBpe9724KFBEseTEXrvfOC8DdMEfIRc3mW0=;
	b=bQDDgIySMofO7Lda1zpVeGd/zhOv2BsZO4H6KYgBvtEa97h/X2i2JbOQIjpzyZm+4HJ+
	 X/zpynKFEexf57DQnl/CWZXBeeF9donWNp3tVOV0WXaf5Hp0O2SIgpExQRtQTRnVlveWH
	 mFp9Syd/gAVE2zI1C4K9FaxrIkvJX7HeIHjotWUvSqgipwhxeGHML9kucQVXSNTDzgyNX
	 KhSX8ICyowFLd59GEwYQCINcFzDY/MlM1oO19PQ0ZYViwCKO9vv3YkIEiKAcpAJQaOxdy
	 xPu8QD45IA2vrGRVgHgFeT00NJRm/84cWtyRHoRRidQOC/iKBtcL6XuboN5LRxQKxeQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="V/8w1HJy";
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 94261606A686;
	Mon, 23 Nov 2026 14:58:17 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27E101F000E0;
	Mon, 23 Nov 2026 14:58:16 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795445897;
	bh=FPZIAOyVkBpe9724KFBEseTEXrvfOC8DdMEfIRc3mW0=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=V/8w1HJyKKGk5SG83M1yFhF2ndXhArzdL3D75APUkUnKLwRit1vAWVeOUcwQ4kJ+J
	 92c8Gn/1JCZi+6EtsvYV3dJbUAYzwx1ZxjxHQAZP5RDXokul3bNbYjnOQ7jHZBJedQ
	 ZJKWNVD7cqHjfYzE+KAccOtGFGOFoBIx8BP9lPOZOg834/UaxFYQC0Uuu/O0ircNum
	 E2GM966N6bXdZXh1va5IjDdnOh95Q7w81l4Qhks+1dB1anJMYEsGi65GGH4m2UedNY
	 POlyTNXLYMl2a/Y+2B/pz+TgcoxajLuB6upGoQjds1TRCO4c1rj4fXTwsDgMqEqcCk
	 +PQ1HA+lmDGCg==
X-Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
 kuba@kernel.org, pabeni@redhat.com, Steen.Hegelund@microchip.com,
 UNGLinuxDriver@microchip.com, richardcochran@gmail.com, linux@armlinux.org.uk,
 netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
 linux-kernel@vger.kernel.org, robert.marko@sartura.hr,
 horatiu.vultur@microchip.com, jensemil.schulzostergaard@microchip.com,
 horms@kernel.org
X-In-Reply-To: <20261120-sparx5-mtu-change-v3-5-55c272fe1acc@microchip.com>
X-sashiko-severity: High
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