🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #9840

Re: [PATCH net v3] net: bgmac: fix RX frame length check

#9840
From: netdev-bot+sashiko
Date: Mon, 02 Nov 2026 17:33
136 lines
13452 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 1 · 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] When bgmac_dma_rx_read() rejects an oversized frame, it only
  drops the current slot.
- [Medium] The new upper bound in bgmac_dma_rx_read()
  (drivers/net/ethernet/broadcom/bgmac.c:463-464, `len >…

--

net: bgmac: fix RX frame length check

This patch tightens the RX length check in bgmac_dma_rx_read(). It now
compares against BGMAC_RX_MAX_FRAME_SIZE instead of BGMAC_RX_ALLOC_SIZE,
adds a lower bound of ETH_HLEN + ETH_FCS_LEN, and prints the bad length.

> diff --git a/drivers/net/ethernet/broadcom/bgmac.c b/drivers/net/ethernet/broadcom/bgmac.c
> index 669eb7ce7d40b..b5e1d3c0003d6 100644
> --- a/drivers/net/ethernet/broadcom/bgmac.c
> +++ b/drivers/net/ethernet/broadcom/bgmac.c
> @@ -460,10 +460,11 @@ static int bgmac_dma_rx_read(struct bgmac *bgmac, struct bgmac_dma_ring *ring,
>  				break;
>  			}
>  
> -			if (len > BGMAC_RX_ALLOC_SIZE) {
> +			if (len < ETH_HLEN + ETH_FCS_LEN ||
> +			    len > BGMAC_RX_MAX_FRAME_SIZE) {

[Severity: Medium]
This caps the whole L2 frame at 1536 bytes, Ethernet header and FCS
included. Do the other limits in the driver still agree with that?

bgmac_enet_probe() still advertises:

	net_dev->max_mtu = BGMAC_RX_MAX_FRAME_SIZE - ETH_FCS_LEN;

That allows an MTU of 1532 and does not account for ETH_HLEN or VLAN/DSA
tags.

bgmac_chip_init() programs the MAC with this, which is 1550:

	bgmac_umac_write(bgmac, UMAC_MAX_FRAME_LEN, 32 + ETHER_MAX_LEN);

bgmac_change_mtu() programs 32 + mtu, which can be up to 1564.

So the MAC can accept and DMA frames of 1537 to 1564 bytes, or 1537 to
1550 bytes with the default settings. Won't the new check always drop
these frames? Each drop bumps rx_length_errors and rx_errors and logs
"DMA issue", even though the MAC was configured to accept the frame.

With an MTU between 1519 and 1522, frames of 1537 to 1540 bytes used to
be delivered intact. Only FCS bytes spilled past frame byte 1536, and the
FCS is stripped. These frames are now always dropped, and the commit
message doesn't mention this change in behaviour.

The commit message also says:

    A corrupted length between those two limits passes the check, and the
    following skb_put() runs past the skb tailroom and calls
    skb_over_panic() instead of dropping the frame.

Is that accurate for the whole range? Lengths up to about 1570 (32 byte
cache lines) or about 1602 (64 byte cache lines) seem to fit in the
SKB_DATA_ALIGN tailroom. Those frames were delivered, not panicked on.

Should max_mtu and UMAC_MAX_FRAME_LEN be brought in line with how many
frame bytes an RX buffer can hold, as part of this fix?

>  				if (net_ratelimit())
> -					netdev_err(bgmac->net_dev, "Found oversized packet at slot %d, DMA issue!\n",
> -						   ring->start);
> +					netdev_err(bgmac->net_dev, "Found packet with invalid length %u at slot %d, DMA issue!\n",
> +						   len, ring->start);
>  				put_page(virt_to_head_page(buf));
>  				bgmac->net_dev->stats.rx_length_errors++;
>  				bgmac->net_dev->stats.rx_errors++;

[Severity: High]
When an oversized frame is rejected here, only the current slot is
dropped. What happens to the continuation descriptors that hold the rest
of that frame?

bgmac_dma_rx_enable() sets:

	ctl |= BGMAC_DMA_RX_OVERFLOW_CONT;

As noted above, the MAC accepts frames of up to 1550 bytes by default.
Each buffer only holds 1536 frame bytes after BGMAC_RX_FRAME_OFFSET.

Other drivers for the same Broadcom DMA engine show that such frames
spill into the next descriptor, with the rest written from offset 0.
brcmsmac's dma_rx() computes resid = len - (rxbufsize - rxoffset) and
walks the extra buffers. b43's dma_rx() recycles the continuation
descriptors:

	/* The data did not fit into one descriptor buffer
	 * and is split over multiple buffers.
	 ...

After the break, ring->start moves to the next slot. The loop then reads
rx->len and rx->flags from offset 0 of that buffer. Those would be bytes
1536 to 1539 of the oversized frame, which the remote sender controls.

Any len from 18 to 1536 passes the new check, and flags won't be 0xbeef.
The code then calls build_skb(), skb_put(), eth_type_trans() and
napi_gro_receive() with up to 1532 bytes.

For a 1550 byte frame the hardware writes only 14 bytes into that second
buffer. All of them land before the skb data start at offset 30, and
bgmac_dma_rx_skb_for_slot() poisons only the 4 byte rx header.

Wouldn't this pass stale netdev_alloc_frag() memory, such as old packet
data or other freed kernel memory, up the stack as a received packet?

The commit message says the change stops eth_type_trans() from parsing
"bytes the hardware never wrote". This path still seems reachable.

Before this patch, the same continuation slot could also reach the
skb_over_panic() the commit message describes. The new bounds remove the
panic, but the stale memory is still passed up.

Could the continuation descriptors be consumed the way b43 does, or
SOF/EOF be checked? Another option is to cap UMAC_MAX_FRAME_LEN and
max_mtu so that no frame can exceed BGMAC_RX_MAX_FRAME_SIZE.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261029173122.29636-1-rosenp%40gmail.com
Technical Details
Message-ID: <179364083073.3131.3402405376014910148@kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-354971-linux-kernel-netdev=dewy.ru
References: <20261029173122.29636-1-rosenp@gmail.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-354971-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v3] net: bgmac: fix RX frame length check
Date: Mon, 02 Nov 2026 17:33:50 +0000
Organization: Usenet Network
Message-ID: <179364083073.3131.3402405376014910148@kernel.org>
References: <20261029173122.29636-1-rosenp@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2994573"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:gyJBmfZCSwqqA/DqOUueK/mkzRc= sha256:Hkfe7qF2WXaWlmoJqUDDEkooUbdW6LGpohJivvDfQwo=
	sha1:n9x3Vtu3kQmHs04MyPi254TgT9o= sha256:xC7tV/viRN5PGS3AZf9w91gHsir4hqqP62Dl7ULdMY4=
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 386D81125F9; Mon,  2 Nov 2026 21:16:05 +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 PjZSYYVYqeuT;
	Mon,  2 Nov 2026 21:16:02 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-354971-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id CCA9A1125F1; Mon,  2 Nov 2026 21:15:53 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 8B91247656; Mon,  2 Nov 2026 17:47:23 +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=1793640837;
	b=qAQd2Snv4dPtE7l/7qysZLDot3JyIdyvkluciZhSpfns2LuPcfyUnxDobQVsWbHWu+5I
	 u0YTDHEvJhtDeFC0OSI1ZNbHqPDuwbrwTGXFoxGyXFBkLZANvioa/pYqpMnFhumXhnVAt
	 3xj8hg8q73pvTu92FXzGU8SDOlOm+3fbHwtp1nAJBnyX14dREXyR8bSTrdKaOtkyZCten
	 ZLhgJAVq09YzLPi9gn5hPw9WX1GFbKa4Cfi4n5u3qiDgDhsCbcbY6QQuNb+vKdvLFQxoC
	 +y5aNFJXXWIpbkwToonvnYDqVzjeGeyEUSZveWvr8oCRjkx1kTmsU17dPDvzkGskmrA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793640837;
	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=NW8ZU0sBpbVBOi33hW0BCgeDRWT6riQdrCZk2EpkxOw=;
	b=b/oLIXS3F0wFmjsL0N9gIl1joG27po0hkObMGAQPiEgT6IVvs1d2wn9l86IYbtYGWLTn
	 /OqR1McxFNgvXano4llCRavpb0QNXn57N8RYMNernNd85SSe+DJ497udrSH9qRBaQFndQ
	 13yFD5BAEXmUKm2l9+wgRG4IZqM4mJUWkQzI6z9eNSakvKkEGMmWwrsJtfZQXzDIu6sEp
	 +MlxOfsclOJMn85zwrEjj2lIJYsMKdzjQ77GcqzosUHliC8L7EkCGS+cBnXnxSKLtxucs
	 kBirekvDPMEkIApkb25Vg+kQ0KU3BRVKSxNctiYOaTcKea/b5ee6WftoxP2DMNKXlPg==
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=C1O8e8lm;
	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 1EAD3606A327;
	Mon,  2 Nov 2026 17:33:57 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=C1O8e8lm
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=1793640832;
	b=a09jh+91uUI+S8x2cAmqJQe7xmWWFnkdGJt7jtp0Kx/ttugHUPQflZ37N7qcpEitdApF
	 tP46pXUYo9Y7FjuF/G07jVIu0KYcaHEosIOdrZEqWVG5AZGJ6fQ5vREXcIJma0GqtfHnG
	 RAFbWsVvcrKl192a88lQWBQ9KUvRxU2bqPZvV0l49GsZnAn2KbfgkaBquOfS1nipMJ8aO
	 HlzveglkoMl7+no+OBuK7qdcXibILvtKwGpWnVzCMVlOkGFPcE6IBzjWgi9gXBxrcwJlF
	 CUDe3rhhGlO3Fh2eQg45oNJ3xLPIIKL4FR0yOZG6YlJq+NWtou00eZm+9ovQ1m9idvg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793640832;
	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=NW8ZU0sBpbVBOi33hW0BCgeDRWT6riQdrCZk2EpkxOw=;
	b=WqGt7JecWsUwzOvkfBWStV7Jq6I9JJMNoEG45pMW1aqhOy9HGkBXxBjfI6WX+mBJ2EXg
	 K58ncSHbRjR0uBdIXG9X6utjG1CWkMFrBiYwkxbBknZ+qnroCsyC9iENkNvmOFAE8nzfp
	 lx7h2i4Pz3CG1PCFDfJmuBIc2hWeJGfn6gm+FFZD1vhVNUgv+XC97wagt+YxFEpEWXAkv
	 GPHS10N85NBhZ+uIym8ayfEUJKT7PUSo+NaytKgWK5oMbD7obSZRdWKLmfCtBwQtyfB9N
	 imymQPcZlBE56ocuoFQ6+RdRwPo9XqMjwu1YrCO3VjuRLAYvTNmDEVYbfdRMmivE/wA==
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=C1O8e8lm;
	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 3F3AA606A326;
	Mon,  2 Nov 2026 17:33:52 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C7B41F00A16;
	Mon,  2 Nov 2026 17:33:51 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1793640831;
	bh=NW8ZU0sBpbVBOi33hW0BCgeDRWT6riQdrCZk2EpkxOw=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=C1O8e8lmOwb8wMV8hZ7tS1FAol7Ms9KBziEIwSqZ0qBWIfb4DXAvbjEkkFw0TWldd
	 G8YeyTCpCxwus+gpT/Veq5Sfr9FByNm8akxZ1sE3+wrfAW+6bpQyFyv3BNzb3crMQ+
	 uzgO5oxfC4+7CpjkScv2OQ9uzBMHjm5OA+zVXmjXh8lh8V6BCqTU3fa5rE1SbSvUuW
	 hSqkFBkxoltUlmzLeZeAH/UTR+rmEe9bYhO/zPxhhoRNuy+BnzTYFJTRI1xFgwKs00
	 CX5Q/1YBL5iS1uFvcvZKNnlwv30833xlHWWJzI8Pl1okkmc+uldCSUhEU88FzrZmaZ
	 jxJvsMP3US+Ig==
X-Cc: netdev@vger.kernel.org, rafal@milecki.pl,
 bcm-kernel-feedback-list@broadcom.com, andrew+netdev@lunn.ch,
 davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
 nbd@openwrt.org, linux-kernel@vger.kernel.org
X-In-Reply-To: <20261029173122.29636-1-rosenp@gmail.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