๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #22020

Re: [PATCH net-next v9 11/14] net: ethernet: cortina: Validate RX fragment lengths

#22020
From: netdev-bot+sashiko
Date: Tue, 24 Nov 2026 18:29
162 lines
13722 bytes
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 ยท High: 0 ยท Medium: 1 ยท Low: 2

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).

- [Medium] The patch treats two descriptor layouts inconsistently.
- [Low] The patch fixes descriptor-length bugs that date back to the
  driver's initial commit, but it has no Fixes: tag and no Cc: stable.
- [Low] net: ethernet: cortina: double-counted RX stats on err_drop in
  gmac_rx()

--

net: ethernet: cortina: Validate RX fragment lengths

This patch adds bounds checks on RX descriptor lengths in gmac_rx(), so a
fragment can no longer underflow or run past the posted free queue
fragment or the page. Zero-length non-final descriptors are now dropped.
An EOF descriptor that carries no new data now completes the frame that
has already been assembled.

> diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
> index 8431f0a2e34a4..fe23ef8be9e51 100644
> --- a/drivers/net/ethernet/cortina/gemini.c
> +++ b/drivers/net/ethernet/cortina/gemini.c

[ ... ]

> @@ -1864,6 +1865,9 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget,
>  			if (!skb)
>  				goto err_drop;
>  
> +			if (frag_len < NET_IP_ALIGN)
> +				goto err_drop;
> +
>  			page_offs += NET_IP_ALIGN;
>  			frag_len -= NET_IP_ALIGN;
>  			frag_nr = 0;

[Severity: Low]
Should this patch have a Fixes: tag, and possibly Cc: stable?

According to git blame, all of the following come from the initial driver
commit:

- the unchecked frag_len -= NET_IP_ALIGN above
- the frag_len = frame_len - skb->len underflow at EOF
- the skb_fill_page_desc() append of zero-length or oversized fragments

So the tag would be:

Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")

Without the tag, stable tooling cannot tell which trees need this fix.

> @@ -1872,15 +1876,33 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget,
>  			goto err_drop;
>  		}
>  
> -		if (word3.bits32 & EOF_BIT)
> +		if (word3.bits32 & EOF_BIT) {
> +			if (frame_len < ETH_ZLEN ||
> +			    frame_len < skb->len)
> +				goto err_drop;
>  			frag_len = frame_len - skb->len;
> +		}
> +
> +		if (!frag_len) {
> +			if (word3.bits32 & EOF_BIT) {
> +				put_page(page);
> +				page = NULL;
> +				goto complete_frame;
> +			}

[Severity: Low]
Does this count rejected frames twice in the interface statistics?

gmac_skb_if_good_frame() is called on the SOF descriptor. On success it
falls through to update_exit, which does:

	port->stats.rx_bytes += frame_len;
	port->stats.rx_packets++;

That happens before gmac_rx() runs any of the new checks. The chain can
still be rejected afterwards by one of them:

- frag_len < NET_IP_ALIGN on the SOF descriptor
- frame_len < ETH_ZLEN or frame_len < skb->len at EOF
- a zero-length non-EOF descriptor
- frag_len running past the free queue fragment or the page

In each case the code goes to err_drop. That frees the skb with
napi_free_frags() and increments port->stats.rx_dropped. The earlier
rx_packets and rx_bytes increments are left in place.

So the same frame shows up as both received and dropped. rx_bytes also
includes a byte_count that gmac_rx() has just judged inconsistent.

The commit message says descriptor inconsistencies are now accounted as
drops, but they are still counted as received as well.

Should the rx_packets and rx_bytes accounting move to the complete_frame
path? Then it would only happen once the frame is actually handed to
napi_gro_frags().

The existing MAX_SKB_FRAGS drop and the restarted-SOF drop already have
the same problem. This patch adds several more ways to reach it.

[Severity: Medium]
Are these two EOF cases handled consistently?

The empty EOF path delivers the frame when frame_len == skb->len at EOF.
For a valid frame, this seems possible only if two things are true:

- the GMAC writes trailing bytes that byte_count does not count (probably
  the 4-byte FCS) into the free queue buffers
- buffer_size in the earlier descriptors includes those bytes

If the hardware works that way, the trailing bytes could also straddle a
buffer boundary. gmac_start_dma() sets:

	dma_ctrl.bits.rd_insert_bytes = NET_IP_ALIGN;

Take 2048-byte fragments and a jumbo frame with byte_count 2044. The first
buffer would be full: buffer_size is 2048, and frag_len is 2046 after the
NET_IP_ALIGN adjustment, which includes 2 FCS bytes. The other 2 FCS bytes
land in the EOF buffer.

At EOF, frame_len (2044) < skb->len (2046). Wouldn't this valid, CRC-good
frame then go to err_drop and be counted in rx_dropped?

Could the last appended fragment be trimmed by skb->len - frame_len, and
the frame completed, instead?

Frames only span several descriptors with jumbo MTUs. The driver supports
them: max_mtu is MTU_SIZE_BIT_MASK - VLAN_ETH_HLEN, and
gmac_pick_rx_max_len() allows 9212 and 10236. Testing at the default MTU
would not hit this case.

If the hardware does behave this way, a 3-byte window of frame sizes just
below each 2048-byte boundary would always be dropped. Whether buffer_size
counts bytes that byte_count leaves out is defined only by the Gemini
datasheet.

> +
> +			if (net_ratelimit())
> +				netdev_err(netdev,
> +					   "Received fragment with len = 0\n");
> +			goto err_drop;
> +		}

[ ... ]

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120-gemini-ethernet-fixes-3-v9-0-298671d799d5%40kernel.org
Technical Details
Message-ID: <179554499621.3135.11543355488056577743@kernel.org>
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370676-linux-kernel-netdev=dewy.ru
References: <20261120-gemini-ethernet-fixes-3-v9-11-298671d799d5@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370676-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v9 11/14] net: ethernet: cortina: Validate RX
 fragment lengths
Date: Tue, 24 Nov 2026 18:29:56 +0000
Organization: Usenet Network
Message-ID: <179554499621.3135.11543355488056577743@kernel.org>
References: <20261120-gemini-ethernet-fixes-3-v9-11-298671d799d5@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="9543"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:999QqlQCYfS7k84ubCEW7fltIdA= sha256:iGsOsPpQdEToFIt6R0Ax2uf5K7mB1bm1NWyXRKR1kaA=
	sha1:+6D/r3C8Vv0y7j7gg8MD6FLsCMQ= sha256:gDR2wsMv2w4+XxAZyZlO3c6BiZ0WE+YmmaPhxJn9Y9U=
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 2115E125E2E; Tue, 24 Nov 2026 21:30:28 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 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, URIBL_BLOCKED=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 DqBexlHgNAsp;
	Tue, 24 Nov 2026 21:30:24 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-370676-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 07980125E22; Tue, 24 Nov 2026 21:30:15 +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 01AE23A2E8; Tue, 24 Nov 2026 18:29:59 +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=1795544998;
	b=mqKI8FCrhabwqLMyhPDeIdTwVpUja2IcoWSvdScBRzgG5CNgEXvQ5SuIQHpqMl50yZSu
	 xfxgYISyUG15X9qyREoBIqk5hX4kyrLdCnw7A+KEWnvPEEi0/Y5eo0woVvVYg4se1izXf
	 4Lr6t6fZnN9IF/2F2tIUIWFu2SYUdH9C6aC59CF7URVlfjDhCY2V5emKY5fifYsE+fRSn
	 Zj0b5IGEqMwmA0wjaMYGenjVSg6kYKyxBYrn0ZOYiVoqpJ1JU606CA01C9bxssYhxQ75i
	 +JO3Sem1hvAh8IPQhzosGgJEYT0Tu0upPRWCTK3ephwvmXXfD2w7kXMLgJM+MRbAFcg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795544998;
	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=w654MEZNHX4phJkvMOndPvh3BoZbH198y9l2bP1SyTI=;
	b=Yib2hJIZUAVKwytCalFmn7F06ust+c+5XYYIBV6uYvDshuuSlntJbWKefdBzluiQ0a1q
	 IPfaUiJTdAf5W9+FDfKHDALxdHG2RAlo2+KhvX2qDnGJmd/hStYCy4QSzM61GQ3dmo2Qa
	 T7CgrGeltEa8pmT5fj09wqqqJ6CnWotv8Vap8OBox+Fu8t0rO+xsRaG3BkN17Moe+4ZqW
	 ZQ0rfSnKJmY79M1WOYSLGrEVnk5wLTyOqDgtwWtPlYkez5zDihcXBFzNP8FRktqYL+pRh
	 l7bSMpwDQR52ipJz54Silo4d0k5758B0ATrUeGrj6dEDdRMN1mHUjpkVlEtjEeWlGdQ==
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=hPFlMbZ3;
	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 CE196606A331;
	Tue, 24 Nov 2026 18:29:58 +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=hPFlMbZ3
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=1795544998;
	b=rUktyo6fqNnjtVibVljy1fVeGVI80lHDukG8TE1odvDlPj1nYlvDWeKIyVLnDObzivGW
	 jrsVvxfm2XkCqoUy64/Z/KDrcHCGgrIflJgVWOzwrDbLIG/69h1OBWbfVxtQkeIYYM6J6
	 U3AEIZcSSP+xFu041LjsH3qYRBIcrrFjNt0moVNlAECn2bX06Aa+VBhb2SYNY6oLGip2d
	 Sngy0zQF5rRZzTs6PWzYHM4ZEfETobk+GKXFohmXySTdHmKGHlA5IWZ8yXRVTtTzMGXNJ
	 bHVvixzNNv377+SHoXMQYIjBiYfBot+H5m9j2sonCXN4VdG9fE2HFZQTL3+nYWST27g==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795544998;
	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=w654MEZNHX4phJkvMOndPvh3BoZbH198y9l2bP1SyTI=;
	b=apLkMtJ/4C6AQZdJRcKdAy7jcR3rTuI6AVbTYcKYUwnM1hSri97HGwWqdR6JXYrPoZwy
	 Yuf1XRdrOHwX5ZNJum2RzL+9ka67eR+6igieX41kV7CKRc6ZVstuvwAMwmDfS2ARMvi7r
	 7NvRU0VseE6ZmW167zGmfvcwvMC0KRi3ULMhFQil2Ulxu2YE1bNEpfPSs9j1x/jYtBxBV
	 OHYa0y1MZBRJ6Q/5/cTMUr5fC51/EW4BCvXGFTWhkkTw+lYFzVgZN53/Mbd4VZXUWhbmS
	 Jn+AEnws9FVYMbcQ0KlkfTDFyX4FGES+IYaun2IUnXoJYUIaCu4BrCYaqnKuPMyifGQ==
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=hPFlMbZ3;
	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 EB8B6606A326
	for <netdev@vger.kernel.org>; Tue, 24 Nov 2026 18:29:57 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id AD7461F000C4;
	Tue, 24 Nov 2026 18:29:56 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795544997;
	bh=w654MEZNHX4phJkvMOndPvh3BoZbH198y9l2bP1SyTI=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=hPFlMbZ3FAn093p2N3dBBvlvdFtDe6MtEB/HQSRlpxbUwXaGb5TdcIG5v9WPaI2xT
	 O67OqF0i2qOYE0Y8mKUNiC4VQbjsYr/63iBzlLpm9pB0yQz/uqPpPexHJ5Jo/Z6/Ls
	 gJl5RJWEDaL8FYCUXWLJqinXhSN1k4yf7zDIRJJnezbMBeyGMtzJ2X3v267eNskTOE
	 19PLiEZf1Pbhada1hToc5N/ie6E97xIMggcCdBtzog9KAHKZoNE5LUnYnz0JKUgpL0
	 8ax8M56dbihcBsFMM5LqiEY67BDKxKaoxv+a3qQ0DkNDgU6i0KisF9cDU1bwVMzOt6
	 mmuhj1O6Jkpkg==
X-Cc: ulli.kroll@googlemail.com, andrew+netdev@lunn.ch, davem@davemloft.net,
 kuba@kernel.org, pabeni@redhat.com, mirq-linux@rere.qmqm.pl,
 mhun512@gmail.com, edumazet@kernel.org, netdev@vger.kernel.org
X-In-Reply-To: <20261120-gemini-ethernet-fixes-3-v9-11-298671d799d5@kernel.org>
X-sashiko-severity: Medium
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