🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26130

Re: [PATCH net v2 1/2] net/ncsi: validate response packet lengths against skb

#26130
From: netdev-bot+sashiko
Date: Thu, 03 Dec 2026 03:38
229 lines
16274 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 (2) · Medium: 1 · Low: 1

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 fix is incomplete on the AEN branch of ncsi_rcv_rsp().
- [Low] The commit message says 'ALIGN(payload, 4) on an unsigned short
  wraps to 0 for payload values 65533..65535' and gives that as the…

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the variable-
  length response handlers the commit message names (GP, OEM) still read…
- [High] This problem wasn't introduced by this patch, but
  ncsi_rsp_handler_gp(), one of the variable-length handlers named in…

--

net/ncsi: validate response packet lengths against skb

This patch unshares the NCSI response skb and pulls the common header in
ncsi_rcv_rsp(). It also makes ncsi_validate_rsp_pkt() require a minimum
payload and pull the full header, the aligned payload and the checksum
before reading them. Log messages after validation now use nrh->type
instead of hdr->type.

> Additionally, ALIGN(payload, 4) on an unsigned short wraps to 0
> for payload values 65533..65535, and dereferencing hdr->type after

[Severity: Low]
Is this part of the commit message accurate?

ALIGN(x, a) expands to __ALIGN_KERNEL_MASK(x, (__typeof__(x))(a) - 1),
which is ((x) + (mask)) & ~(mask). When x is an unsigned short, both
operands are promoted to int. For 65533..65535, x + 3 gives 65536..65538,
and & ~3 gives 65536, not 0.

The old code used the result directly in pointer arithmetic. The new code
stores it in a size_t. So there was no wrap with or without the size_t
cast. The 65533..65535 KUnit cases appear to be rejected only because the
skb is shorter than pkt_len.

Could the commit message drop or reword the wraparound claim? Since the
patch carries a Fixes: tag, it would help backporters to know exactly
what is being fixed.

> diff --git a/net/ncsi/ncsi-rsp.c b/net/ncsi/ncsi-rsp.c
> index 84cc8ac0ca2f8..e917cefd408b1 100644
> --- a/net/ncsi/ncsi-rsp.c
> +++ b/net/ncsi/ncsi-rsp.c
> @@ -35,9 +35,25 @@ static u8 decode_bcd_u8(u8 x)
>  static int ncsi_validate_rsp_pkt(struct ncsi_request *nr,
>  				 unsigned short payload)
>  {
> +	size_t payload_len, pkt_len;
>  	struct ncsi_rsp_pkt_hdr *h;
> -	u32 checksum;
>  	__be32 *pchecksum;
> +	u32 checksum;
> +
> +	if (payload < sizeof(*h) - sizeof(h->common)) {
> +		netdev_dbg(nr->ndp->ndev.dev,
> +			   "NCSI: response payload too short (%u)\n", payload);
> +		return -EINVAL;
> +	}
> +
> +	payload_len = ALIGN((size_t)payload, 4);
> +	pkt_len = sizeof(h->common) + payload_len + sizeof(*pchecksum);
> +	if (!pskb_may_pull(nr->rsp, pkt_len)) {
> +		netdev_dbg(nr->ndp->ndev.dev,
> +			   "NCSI: response packet truncated (len %u, need %zu)\n",
> +			   nr->rsp->len, pkt_len);
> +		return -EINVAL;
> +	}

[Severity: High]
This is a pre-existing issue and was not introduced by this patch. The
GP and OEM variable-length handlers named in the commit message still read
past the region this validation guarantees.

For payload == -1 types, the payload comes from hdr->length. A response
with hdr->length = 4 passes this check, and only 24 bytes are pulled. After
that, ncsi_rsp_handler_gp() reads link_mode, bc_mode, valid_modes and
aen_mode up to offset 48. It then walks the filter tables:

ncsi_rsp_handler_gp() {
    ...
	pdata = (unsigned char *)rsp + 48;
	enable = rsp->mac_enable;
    ...
	for (i = 0; i < rsp->mac_cnt; i++, pdata += 6) {
    ...
	for (i = 0; i < rsp->vlan_cnt; i++, pdata += 2) {
    ...
}

None of these reads are compared with hdr->length or skb->len. With
mac_cnt = vlan_cnt = 255, the handler reads about 2088 bytes past the
network header. That is beyond the 1536-byte RX buffer used by ftgmac100.

ncsi_rsp_handler_oem_gma() has the same pattern:

	memcpy(saddr->__data, &rsp->data[mac_addr_off], ETH_ALEN);

For Broadcom, rsp->data starts at offset 24 and mac_addr_off is 28, so
this reads bytes 52..57 without checking hdr->length. The bytes it reads
end up in ndp->pending_mac and are applied as the interface MAC.

Because ncsi_rcv_rsp() does not check the response type against nr->cmd,
any outstanding request id is enough to reach these handlers.

The second patch in this series ("net/ncsi: validate GMCMA address_count
against packet length") adds a check based on hdr->length to
ncsi_rsp_handler_gmcma() only. Should GP and OEM get the same treatment?

[Severity: High]
This is also a pre-existing issue, not something this patch introduced.
ncsi_rsp_handler_gp() can write past heap allocations, because its loops
are bounded only by the u8 counts in the packet:

	for (i = 0; i < rsp->mac_cnt; i++, pdata += 6) {
		assign_bit(i, bitmap, enable & (0x1 << i));

		memcpy(&ncmf->addrs[i * ETH_ALEN], pdata, ETH_ALEN);
	}
    ...
	for (i = 0; i < rsp->vlan_cnt; i++, pdata += 2) {
		assign_bit(i, bitmap, enable & (0x1 << i));

		ncvf->vids[i] = ntohs(*(__be16 *)pdata);
	}

ncmf->addrs and ncvf->vids were allocated in ncsi_rsp_handler_gc() using
counts from an earlier, independent GC response:

	size = (rsp->uc_cnt + rsp->mc_cnt + rsp->mixed_cnt) * ETH_ALEN;
	nc->mac_filter.addrs = kzalloc(size, GFP_ATOMIC);

GP never compares mac_cnt with n_uc + n_mc + n_mixed. It never compares
vlan_cnt with n_vids, or either count with the width of the u64 bitmap.

In struct ncsi_channel_mac_filter, the u64 bitmap is followed directly by
the addrs pointer:

struct ncsi_channel_mac_filter {
	u8	n_uc;
	u8	n_mc;
	u8	n_mixed;
	u64	bitmap;
	unsigned char	*addrs;
};

Can assign_bit() with i >= 64 overwrite ncmf->addrs, so the next memcpy()
writes through a corrupted pointer? The vlan filter struct has the same
layout.

If GC reported zero filters, addrs is ZERO_SIZE_PTR. If no GC was handled
for the channel, addrs and vids are NULL.

GP is unchanged at the end of this series.

[ ... ]

> @@ -1184,6 +1200,15 @@ int ncsi_rcv_rsp(struct sk_buff *skb, struct net_device *dev,
>  		goto err_free_skb;
>  	}
>  
> +	skb = skb_share_check(skb, GFP_ATOMIC);
> +	if (!skb)
> +		return -ENOMEM;
> +
> +	if (!pskb_may_pull(skb, sizeof(*hdr))) {
> +		ret = -EINVAL;
> +		goto err_free_skb;
> +	}
> +
>  	/* Check if it is AEN packet */
>  	hdr = (struct ncsi_pkt_hdr *)skb_network_header(skb);
>  	if (hdr->type == NCSI_PKT_AEN)

[Severity: Medium]
Is the AEN branch still exposed to the same short or non-linear skb
problem?

This pull guarantees only sizeof(struct ncsi_pkt_hdr), which is 16 bytes.
The skb is then passed to ncsi_aen_handler(), which reads further:

ncsi_aen_handler() {
    ...
	h = (struct ncsi_aen_pkt_hdr *)skb_network_header(skb);
	for (i = 0; i < ARRAY_SIZE(ncsi_aen_handlers); i++) {
		if (ncsi_aen_handlers[i].type == h->type) {
    ...
}

struct ncsi_aen_pkt_hdr is 20 bytes, and h->type sits at offset 19.

ncsi_validate_aen_pkt() only compares h->common.length with the fixed
payload. After that comparison it reads the checksum and computes the
checksum over the packet:

	pchecksum = (__be32 *)((void *)(h + 1) + payload - 4);
	if (ntohl(*pchecksum) == 0)
		return 0;

	checksum = ncsi_calculate_checksum((unsigned char *)h,
					   sizeof(*h) + payload - 4);

None of this is checked against skb->len or skb_headlen(). The patch
removes this same dereference and computation from
ncsi_validate_rsp_pkt().

With ftgmac100's linear 1536-byte buffers, these reads return stale data
from inside the allocation. A driver that produces short or non-linear
heads, which is the case this patch says it handles, would read out of
bounds.

Would it make sense to add pskb_may_pull(skb, sizeof(struct
ncsi_aen_pkt_hdr)) before the AEN type lookup, and to pull sizeof(*h) +
payload in ncsi_validate_aen_pkt()?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202033609.1934503-1-yuxiaozhang%40google.com
Technical Details
Message-ID: <179626909307.3146.3436162201353839351@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376265-linux-kernel-netdev=dewy.ru
References: <20261202033609.1934503-2-yuxiaozhang@google.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376265-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v2 1/2] net/ncsi: validate response packet lengths against skb
Date: Thu, 03 Dec 2026 03:38:13 +0000
Organization: Usenet Network
Message-ID: <179626909307.3146.3436162201353839351@kernel.org>
References: <20261202033609.1934503-2-yuxiaozhang@google.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network; logging-data="2133464"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:3Ia8JY+PdFRldVEVeZWVbr/0CI0= sha256:f9ngDd9c/czQpywgjNjbKjWSyns69H36vNTF0zRMOE8= sha1:GhZH/Ie/GVrDjLx4wXYIXwFIpck= sha256:bfJHNkFQLpaqoZHIYaMSvDF0qCVRXxfGrvP9GXLLo44=
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 61731117807; Thu,  3 Dec 2026 06:38:42 +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 GI7x0MVd6ERN; Thu,  3 Dec 2026 06:38:38 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-376265-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 25F0B117806; Thu,  3 Dec 2026 06:38:29 +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 E8E2929DAF; Thu,  3 Dec 2026 03:38:20 +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=1796269100; b=GbBl2qITQISyZSsADoQ4p/8RDr5vRs812JjGJ61UEU6dpb6/gubfmzClxNgL20gTEY7B oSjqP0Kts9UcxRef9TzGumpVkWkWZg/Gcwaan6jUs4zDiI/FPGjXRvLmUxEBndWCdvdd3 5/VFbk+kdd7v4nowDhbMuPxJSB6RtfiFy8N8QmXzUX7wdQsBuesVrdXQa/TAuuUvHHMPu 8CJFvrQCAD0DYdr1o+cWfjcymwZuZtBGMvS2wxuDP7ckou/xsrQFLu5RzjsSzA9j0Osjh 7Y0Lu6KguSLcOZX22s2J3664at9ANjBDU4/SZAjHWSJQ94vUIbJ4QX+tvUsFRRgr5bg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796269100; 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=s14Wjy22zNKg8ULmDZeNroCZn4C8G7/8VQHPmHb5lTU=; b=t2ShjJbCD02eIH8X6R+N+jIqHcMikSk3zEA2/faaWF/PDWHI9yDE3gi42vvpsXOfCptI FCkx2GeQ/P11M7SrQTD973IWPXGvX85er1H4e9HMk0u0gLh2u9kFF4nyvgO9+bDvUpy+b WyRmIzyFaVNvAacN61dvJjnnPYFYoWtEZoV4uzZeftSrR0DWgNoJ2wAyDlkewuqBB6+Kd 6rjclR5mzASZfKMX8B1DeArCv+naj++IM121NiocAqgHN3c3U+d4CGRoLtInDoZTkiquL QIZ8lhxky+my6m/lr4yQQlJnxUo96f0LUBSzzaWV7PO29tbr8oDXHyVNS/FcnY4GgNg==
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=ZMbP+W8V; 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 727E4606A685; Thu,  3 Dec 2026 03:38:20 +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=ZMbP+W8V
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=1796269094; b=3CnRPbMeDtG+TtOJJPTPYXCAu19rPgG82plMS/K3KmxOx9JTvQ22FR9KG4gKKTIlgkLi Bqu+s9xRgTlhaGGa9oe1iv68ZW22d+B92m8tswFm98b2nsqPXKxe/2bYeyTyVNRiMXMyM 4BhkzdXbhZVi/o/MEDJdOEWP1xgul+SKg/GcV/OouLl0xYcoNw68LL5wwcJUFRcjNrOVw +j3/HaSIkQyFc9YXM/8hJb4VG07ndr3aRYAHhAvmpPRsFd+89tOvX9FIqeLPATldYocFJ uKuyqk/Pq66cduRFQRyTNb5o9S/AOQ14jwk4jwzoTBJ/B9VmqB3oGpieOCJuvI/vCkg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796269094; 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=s14Wjy22zNKg8ULmDZeNroCZn4C8G7/8VQHPmHb5lTU=; b=5MnZ5ZJOWYgLmue87DA4NHNC7Bed+PEjK4RSIphZ8MVXT2P2C0ye/V0umVXUwpEisfit dWF//pe4OV+v2/V4Myxkpf8uvSTbvD2jBEHpD0q4UlawqGXX1nJn9D209e4f9e51ruE8z lJ4FedWLk4ZiT27i51Yh7eDwrvHzOd3EP5ebvOGsgL12uBfSjW5VV6QvFyZafxOaLv1Kn /cEb1PInifBaqN+X+dF1Ae4lSYDhe0gVUoZxb3T4OyKykCd0JJ64nnvp1J3nrtlNRIfy4 weY89Qxek4ABdxba1U0V5pCnsJIqi5ktxjtjW9oeEHM5+ahQtbCuqn4CXUduQXtEy3w==
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=ZMbP+W8V; 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 89BCA606A33F for <netdev@vger.kernel.org>; Thu,  3 Dec 2026 03:38:14 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77A4B1F000C1; Thu,  3 Dec 2026 03:38:13 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796269094; bh=s14Wjy22zNKg8ULmDZeNroCZn4C8G7/8VQHPmHb5lTU=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=ZMbP+W8VkKd/eDHmLJEmTjQTBiIWDszFMyZP75lp/VoSRlDNnUhdqIlVfGO5rvr2P +SmrPcjRb7CzfhrZwOYsXZS1IJLga3y7mE3CnWbgQw7DOvu7PMBchFMlW5EhCcgHTp jhA14i1gqFbN3dolznVWKJQdF02SA65VYFqAqjF0PQ/CLvPvAIJ4wk5JjuNFp5DLh+ +drjjfBK6B97uVnw4Mahm/3d+YKnTqulV+LQpfxAll2px6BKYrdF5gg+M5IKD7Hi0N aKbjL9d/Yn9SFQCJyGIBUMXAj3RUUD0/aa9VfmEZaT6qdRa3plkfLaDMV+ln9lo+Sr A2A6q703EsvAw==
X-Cc: sam@mendozajonas.com, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, willemb@google.com, fercerpav@gmail.com, horms@kernel.org, joel@jms.id.au, peter@pjd.dev, patrick@stwcx.xyz, netdev@vger.kernel.org
X-In-Reply-To: <20261202033609.1934503-2-yuxiaozhang@google.com>
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
X-Received-Bytes: 15873