🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #7206

Re: [PATCH net] skbuff: keep accesses through unset transport header in bounds

#7206
From: netdev-bot+sashiko
Date: Sun, 25 Oct 2026 13:45
180 lines
14472 bytes
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 2 · Medium: 0 · 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).

- [High] The fix is incomplete because the length helpers that read the
  same fields were not changed.
- [High] The new guards in skb_transport_header() and
  skb_inner_transport_header() only fire when the field equals exactly…
- [Low] skb_inner_transport_header() checks inner_transport_header
  against ~0U.

--

skbuff: keep accesses through unset transport header in bounds

This commit changes skb_transport_header() and skb_inner_transport_header()
so that they warn under CONFIG_DEBUG_NET when the transport header offset
holds the ~0 unset value. In that case they fall back to the network header
position. The aim is to keep accesses through an unset transport header
inside the packet instead of at skb->head + 0xffff.

> diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
> index 6787fcf6ac3e4..e0e2f925f7299 100644
> --- a/include/linux/skbuff.h
> +++ b/include/linux/skbuff.h
> @@ -3002,6 +3002,12 @@ static inline void skb_reset_mac_len(struct sk_buff *skb)
>  static inline unsigned char *skb_inner_transport_header(const struct sk_buff
>  							*skb)
>  {
> +	if (unlikely(skb->inner_transport_header ==
> +		     (typeof(skb->inner_transport_header))~0U)) {

[Severity: Low]
This isn't a bug, but is ~0U the right unset value to test for the inner
transport header? The rest of the inner header code uses 0 to mean unset:

include/linux/skbuff.h:skb_inner_network_header_was_set() {
	return skb->inner_network_header > 0;
}

net/core/skbuff.c:skb_carve_reset_headers() {
	...
	/* Inner offsets have no "unset" marker, zero them so that
	 * skb_inner_network_header_was_set() becomes false and no
	 * consumer mistakes them for a real (and long gone) header.
	 */
	skb->inner_mac_header = 0;
	skb->inner_network_header = 0;
	skb->inner_transport_header = 0;
	...
}

The ~0U case can still happen, because skb_reset_inner_headers() copies an
unset outer transport_header into inner_transport_header. An inner
transport header that was never set (0) is not caught by this check,
though. It still returns skb->head. That pointer is in bounds, and the
behaviour is the same as before the patch.

> +		DEBUG_NET_WARN_ON_ONCE(1);
> +		return skb->head + skb->inner_network_header;
> +	}
> +
>  	return skb->head + skb->inner_transport_header;
>  }
>  
> @@ -3081,7 +3087,11 @@ static inline void skb_unset_transport_header(struct sk_buff *skb)
>  
>  static inline unsigned char *skb_transport_header(const struct sk_buff *skb)
>  {
> -	DEBUG_NET_WARN_ON_ONCE(!skb_transport_header_was_set(skb));
> +	if (unlikely(!skb_transport_header_was_set(skb))) {

[Severity: High]
Does the unset value always survive until this check? The new test only
matches 0xffff exactly. skb_headers_offset_update() shifts both transport
offsets unconditionally, while it does guard mac_header:

net/core/skbuff.c:skb_headers_offset_update() {
	...
	skb->transport_header += off;
	skb->network_header   += off;
	if (skb_mac_header_was_set(skb))
		skb->mac_header += off;
	skb->inner_transport_header += off;
	...
}

pskb_expand_head() calls it with a positive nhead, so 0xffff wraps to
nhead - 1. skb_copy_expand() calls it with newheadroom - oldheadroom. That
value is negative when the new headroom is smaller, which gives 0xffff - k.

In both cases skb_transport_header_was_set() returns true, so no warning
fires. In the second case skb_transport_header() still returns a pointer
about 64K past skb->head.

One RX path that looks like it can reach this is vl600_rx_fixup() in
drivers/net/usb/lg-vl600.c:

	s->current_rx_buf = skb_copy_expand(skb, 0,
			le32_to_cpup(&frame->len), GFP_ATOMIC);

That buffer is later passed up with usbnet_skb_return(). Because was_set()
now returns true, __netif_receive_skb_core() also skips its reset:

	if (!skb_transport_header_was_set(skb))
		skb_reset_transport_header(skb);

Should skb_headers_offset_update() leave unset transport offsets alone, as
it already does for mac_header?

> +		DEBUG_NET_WARN_ON_ONCE(1);
> +		return skb->head + skb->network_header;
> +	}

[Severity: High]
Should the length helpers that read the same fields use the same fallback?
skb_transport_offset() picks it up through skb_transport_header(), but
skb_network_header_len() and skb_inner_network_header_len() still use the
raw offsets:

include/linux/skbuff.h:
static inline u32 skb_network_header_len(const struct sk_buff *skb)
{
	DEBUG_NET_WARN_ON_ONCE(!skb_transport_header_was_set(skb));
	return skb->transport_header - skb->network_header;
}

static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
{
	return skb->inner_transport_header - skb->inner_network_header;
}

With an unset header, both still return about 0xffff minus the network
offset. skb_inner_network_header_len() has no check at all. Callers that
use these values for pulls, copies or offset arithmetic would still get a
length of about 64K.

Code that reads skb->transport_header directly, such as
virtio_net_hdr_tnl_from_skb(), also bypasses the fallback.

Does this match the commit message's "accesses stay within the packet"?

There is also a new mismatch. Before this patch,
skb_transport_header() - skb_network_header() always equalled
skb_network_header_len(). With an unset header they now differ.
ipv6_mc_may_pull() mixes the two:

include/net/addrconf.h:ipv6_mc_may_pull() {
	if (skb_transport_offset(skb) + ipv6_transport_len(skb) < len)
		return false;

	return pskb_may_pull(skb, len);
}

include/linux/ipv6.h:ipv6_transport_len() {
	return ntohs(ipv6_hdr(skb)->payload_len) + sizeof(struct ipv6hdr) -
	       skb_network_header_len(skb);
}

Before the patch the raw offsets cancelled out. Now the first term is
clamped to the network offset, but ipv6_transport_len() still subtracts the
raw ~64K value.

Can the unsigned sum wrap here and skip the advertised length check,
leaving pskb_may_pull() as the only bound?

> +
>  	return skb->head + skb->transport_header;
>  }

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/0bdcbe2ab5ffc86ba7190fe25476bcebcb967310.1792844270.git.mst%40redhat.com
Technical Details
Message-ID: <179293590392.3134.1010737398551488334@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-351560-linux-kernel-netdev=dewy.ru
References: <0bdcbe2ab5ffc86ba7190fe25476bcebcb967310.1792844270.git.mst@redhat.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-351560-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] skbuff: keep accesses through unset transport header
 in bounds
Date: Sun, 25 Oct 2026 13:45:03 +0000
Organization: Usenet Network
Message-ID: <179293590392.3134.1010737398551488334@kernel.org>
References: <0bdcbe2ab5ffc86ba7190fe25476bcebcb967310.1792844270.git.mst@redhat.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1026716"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:ivP+LzrotfMKL1NDGBZoYM851Jg= sha256:DSYVVDc4uQt/QwFuZbQtUcQIn0qcC1oXht1w4i8TISo=
	sha1:sx9u93nd8yZjKePi31k3pJBj2Q8= sha256:kQZK+vBNz/oD3Sp/suTgegGEceI+3vpUL/pvWS5iHD8=
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 39484125B2F; Sun, 25 Oct 2026 16:45:37 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.739
X-Spam-Status: No, score=-3.739 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.339, 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 1OTVLCjPGiGZ;
	Sun, 25 Oct 2026 16:45:28 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-351560-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 51A16125B2E; Sun, 25 Oct 2026 16:45:19 +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 EA1333A733; Sun, 25 Oct 2026 13:45:11 +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=1792935911;
	b=m/EBwsas9z2NUYaodnqUc+KFZB6jzENdgJt3Q5xAwdOXBK9aDQWM866Mf31NC0x4sBfQ
	 yB5xTFXaMEQLRMoB19y2wAHEDU4XBlsH/uRecgHyPZC8SIanDLisBBMagPoG2yDgevn1L
	 flOou6L7/019hXJ0Az7HwPCS27f6TXQO1qqDVmwiBhEmHuFsTTkgH8zzzMZC7RG6EInwG
	 w7LC9bD9cwT1REDFjH1zVWLxQnXtGfPWtDk1AHkT+X4p56WB280JPdxnVdQmCpqno5kFF
	 oUEyYd4Oi2bN832QNoE1ycLmBuPhz6BL8P+8vkILwiWIhnaoXnMUNyGxl8CAGvcRy3g==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792935911;
	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=WzGdwyTIB8OSTT9qV4w81uP2js36URfyJcS9pAsflJU=;
	b=ALMo9qI1myJ3tShoMbYVMQIezs7sUW6Hs9o0wjStoAou7BOsY5+MmLfTuUkAstJNtz/L
	 1+1wzhCjDdCwXkHY75J68owqHy0Wjhl31o6sjMLk3IHbxpRtfYYjYSGUp8N8Zx73HeNZC
	 puW4pXFbuIMOhFh0NAwC/nbs748gm4YdrfpIi2ALs7HQfouEgGVnFd+zgmabPiGTV/kIz
	 Wm1P0A988rCI/8509kvIS6tsLoNweXdHdHNCs3VlsaRGvaE4wgXldJ0IlcPAoVL7PvMi9
	 g3Aydvma2ei6bVSMh9EnznJ7uv7I3qqYX7bwgCawKmPtIW12dkyGyobSc5dk+LnIXhA==
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=NRQRDKmu;
	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 BCD4F606A322;
	Sun, 25 Oct 2026 13:45:11 +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=NRQRDKmu
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=1792935905;
	b=rQO9L8Z+pfD5b0H/VimjlEBodtQ6LSHv9pEkb0YyvvO30rr2fYOJB4A3BsaXfCqGL4pP
	 bCBqkngQ0S9FBceQgvbfMvbcSEDma/NJkFHnfvpAiWcwR3J/T0qyZIRw4+JgBiQ+Rwkf/
	 DXJCXU5VQ8B1OOodmzZBqwlB0j88ETQsSSd0iwbb+whdNXqCL2kzweRWxRYl0wnCtfDnp
	 jo/F6aF8MUdKSunKPNyaJwpyS4Jfb8hy5dzcVv2i4LmgDBhWywE81ylDDTJbU4CiQVc0G
	 m7yWo8RvOIESAW4Xtz1UNGr6TCaYctdXk40GHi9aF3m9LjfqFpnCAtngwPelAwl7aZw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792935905;
	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=WzGdwyTIB8OSTT9qV4w81uP2js36URfyJcS9pAsflJU=;
	b=amB+d9Vf5QdC2p1tHo36lFGW4NEamJEA5hY+vOMdc561/ay/zhcGjzGcj/FK2ZKqUpOF
	 7KZneOy2Rc9iIAX6nlVmrfYU3srx3VCsO2+yzm22UqizzT6JGOsI/qBi42pABOBI0twSQ
	 IUvaKQaqaeHvXw7Ri2zenZbxV+A3mpGMIyHAOZbosWbTHtiWo5/pwVbl5+4JtX1ORAx36
	 hMP7mbJudYXqh/Q4ARZ0LaP05Sd1WB5hXvxGq1C/yronMYradAfdyE7ghpDzvOJztXJsi
	 djobd8gDrySvwfbMyVLsIuk4pEX8aM39xUush1B/JJJOikNrkG7FqVqYJzJV6aquUIQ==
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=NRQRDKmu;
	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) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7EC63606A31B;
	Sun, 25 Oct 2026 13:45:05 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 691671F01825;
	Sun, 25 Oct 2026 13:45:04 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1792935905;
	bh=WzGdwyTIB8OSTT9qV4w81uP2js36URfyJcS9pAsflJU=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=NRQRDKmus9MplXxmlbdnbUu4+03S/jLB5rA2TlVMLbu/jEVISfSfvDKdepE7UnvHx
	 oEkkz2UOHDpQovkPVfvBHqZL0oKFOoM3l/6aGeRn/Src73BUV6+mtedBrc5w9w59WC
	 EzniXUTrdO/pIBYG+W+2os+QpScfAULMnxmDj/JYy5VxNxN9yir9yU+yzapXHvqzef
	 Muwx761HQkMd2VtupRA3yb5J2KG+ObAL2oNveN6X1IZ8WTk9XKLRgfv+pYYewqr5K/
	 0TH7pb3VguPY19WSA30JiSYAsidXHH2L9CWx53xGB9711JIeo8l8qfk/mNYQIZnsBH
	 QhRPSP8jQR/VA==
X-Cc: linux-kernel@vger.kernel.org, edumazet@google.com, noreply@anthropic.com,
 davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
 horms@kernel.org, netdev@vger.kernel.org
X-In-Reply-To:  <0bdcbe2ab5ffc86ba7190fe25476bcebcb967310.1792844270.git.mst@redhat.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