๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #15929

[PATCH net 5/5] udp: use skb_set_transport_header_careful() in __udp6_lib_err_encap()

#15929
From: Eric Dumazet
Date: Fri, 13 Nov 2026 12:46
53 lines
10323 bytes
skb->transport_header is a 16-bit offset from skb->head, and U16_MAX is
reserved as the "not set" value. skb_set_transport_header() silently
truncates an offset that does not fit.

__udp6_lib_err_encap() stores @offset, computed by icmpv6_notify() from
the extension headers of the packet embedded in an ICMPv6 error. Should
the value be truncated, the tunnel encap_err_lookup() and err_handler()
callbacks would read the UDP header at the wrong place.

Since commit 3744b0964d52 ("ipv6: Implement limits on extension header
parsing") a single chain is bounded to IP6_MAX_EXT_HDRS_CNT headers
(24576 bytes), so this needs a large skb->data - skb->head on top of it,
for instance after several nested decapsulations, each of them possibly
pulling its own extension header chain, since @offset is relative to
the IPv6 header embedded in the ICMPv6 error. No reproducer was written,
this is hardening.

Use skb_set_transport_header_careful() and return an error if the
offset can not be stored, in which case udpv6_err() ignores the
ICMPv6 error. Do this before changing the network header, so that
nothing has to be restored on failure.

Fixes: a36e185e8c85 ("udp: Handle ICMP errors for tunnels with same destination port on both endpoints")
Cc: stable@vger.kernel.org
Signed-off-by: Eric Dumazet <edumazet@kernel.org>
---
 net/ipv6/udp.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index 9dcefa162522..a6886a0432f9 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -651,12 +651,13 @@ static struct sock *__udp6_lib_err_encap(struct net *net,
 	network_offset = skb_network_offset(skb);
 	transport_offset = skb_transport_offset(skb);
 
+	/* Transport header needs to point to the UDP header */
+	if (unlikely(!skb_set_transport_header_careful(skb, offset)))
+		return ERR_PTR(-EINVAL);
+
 	/* Network header needs to point to the outer IPv6 header inside ICMP */
 	skb_reset_network_header(skb);
 
-	/* Transport header needs to point to the UDP header */
-	skb_set_transport_header(skb, offset);
-
 	if (sk) {
 		up = udp_sk(sk);
 
-- 
2.53.0
Technical Details
Message-ID: <20261113124625.4010206-6-edumazet@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-362648-linux-kernel-netdev=dewy.ru
References: <20261113124625.4010206-1-edumazet@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-362648-linux-kernel-netdev=dewy.ru
From: edumazet@kernel.org (Eric Dumazet)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net 5/5] udp: use skb_set_transport_header_careful() in __udp6_lib_err_encap()
Date: Fri, 13 Nov 2026 13:46:25 +0100
Organization: Usenet Network
Message-ID: <20261113124625.4010206-6-edumazet@kernel.org>
References: <20261113124625.4010206-1-edumazet@kernel.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1419466"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:6kxL/F35rFEXAMaTF4BeEY1j5Rg= sha256:I+pY9RIRO34JEoSNOY9P53YbIQnitJBl4zGec8M/TeA=
	sha1:iGNnJ29vUEqMto9EGr/QNAlajkw= sha256:cPyKLcIIHdWiYUgrUsbtRN48/AjyQz4aJAel7xWwO1U=
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 5D79011462D; Fri, 13 Nov 2026 22:32:57 +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 FxaXDe7HAHlg;
	Fri, 13 Nov 2026 22:32:54 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-362648-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 4192E11462A; Fri, 13 Nov 2026 22:32:41 +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 243C8324698; Fri, 13 Nov 2026 12:47:10 +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=1794574023;
	b=lSxEoMvR2+sHkX2QqI6s9pRVNqPIKQ/f7GIGBSQCFFPc/Pxovz/bZr2dZvwayU0eiqF/
	 xDg9iowFMioYXZYgE6QhWAdjk4RL/WTRzHhT/pPZPBLcfxkQjDpYsj8gG+KwPZ/VhbLr5
	 VGeH4wdDt79PnxmLBrTYac/g9kH0jejPt+B91/RMP3OMYrhz8GNa6LmxhRTJ/4m21Iwlt
	 3MPQV+AwroRKgTtyj5jzSRBi2h/WFQ4orOmdjKpAZrFrKvX2jgjewYFbT1vF3Z1Jw/EwC
	 zLu6UZ+uilqdfGxRBt/K/QvWzn675K1hGQR8VL9sO/o6NFlxbpLubE8dqaio4AEh5Sw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794574023;
	h=X-Original-To:Received:Received:DKIM-Signature:From:To:Cc:Subject:
	 Date:Message-ID:X-Mailer:In-Reply-To:References:X-Mailing-List:
	 List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe:
	 List-Owner:Precedence:MIME-Version:Content-Transfer-Encoding;
	bh=2duuSZ8Rvfzqo0bXUMYpGryPT4QuFWSDj85f3yc5O5M=;
	b=KU/fZVmDGaK32mGb2hgkMC9LmeNeABRZCHXXwwR4s01BSkB5TT6x8iV8+aBkEuJJmrpT
	 r3xwbgWv7p0IIXHeKs1PbN++m4jvuUEZc985YAghIt3EmKSdGNuEiasbUUtjilmXSxHX5
	 rRyDRxRbA3i1I/eRXJzS1uTqHpdNvZUAPpsrcLKW5PP2z7ePv5ib+pKLeROzbt0Qw+jF8
	 2uYzCsUV6Xb1fFqESUCv4d8brJSIy5WFK0WlZRSB1gwH6nJ2O9wN/lhnJhGatHnXuwrfY
	 +ZAqQ7J0HPimM4jV12CXaGnbnKmDYdIFxxDB9D/geOfoFVCOPebRX+0tCOI120vkklg==
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=Qt7XSlPj;
	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 5DB0F606A889;
	Fri, 13 Nov 2026 12:47:03 +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=Qt7XSlPj
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=1794574022;
	b=2EF6HBk39VvEDA2mw/lBWy4y/nJm4fxLwxNWEjQBZG8+tWDJUyRlHl1EW5dzOIcgHg6x
	 3JlqVF9jzydcvbdWxWA+tr/i2W8lsjdqdi3I+cb58HOeiHESPZpUIIi1ocLSivyzWqx+8
	 QKnJpxUsDglI9LHfRTNbv7thqvHbm1+2zN1b9RDBfPVO/BpdL7Iv8DV4B08fwH4WkpDIA
	 wsgZEtveSTaB8tSPn+NtWVICRPXp5Y+IkJB4Mpr27b++EtEsauVjMWqJYzNVfzGk31Wgf
	 HIfk9nbQnRwq4HkmQGLMqt4tkbpMAVa6x4kjao4Ii9aL9gp3nJ9VZ53acMx7j5co4xA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794574022;
	h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer:
	 In-Reply-To:References:MIME-Version:Content-Transfer-Encoding;
	bh=2duuSZ8Rvfzqo0bXUMYpGryPT4QuFWSDj85f3yc5O5M=;
	b=YW1pO8orCepFlSK44e5I56oC8ib7dIBE6H1PNUtXRF+IAKn8OmwFHKfPjkEEoey2S4X2
	 AgMX8HZ6DemeCrtB7p3B6AbdBUJ6yhI/GRYnsNQyMmM6mP/MOYp+GZRL9dSYFNpcCAHj0
	 UIpuOK21/evG/Gd37sSkfuWt4xpd8jrBeys3lWPPyxlEhueOYF32mPmKb9ETwxws6w+Lv
	 sRKl8MJ42YFB3xJR3k9SLwL62JoBuwTeUCO9AkQV9JpKYKOyzSSkRerulkf6w3dYckRIk
	 mHEJLBmFaoiGMAwKelEK6OMc0IfLDXEmeFrpOtX8PZpwYWqcZLIRGbzJbU3H0nFRozQ==
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=Qt7XSlPj;
	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 7E83C606A338;
	Fri, 13 Nov 2026 12:47:02 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4CC31F000C5;
	Fri, 13 Nov 2026 12:46:57 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794574022;
	bh=2duuSZ8Rvfzqo0bXUMYpGryPT4QuFWSDj85f3yc5O5M=;
	h=From:To:Cc:Subject:Date:In-Reply-To:References;
	b=Qt7XSlPjZlZkjeKFtCgpnobRkK7iHrP/7adBsUrpoIFS+sxCPAu1SJlz4MKEwLuum
	 Uird9sjk2TL6Xn8y757tzNrbYjfv/kjgFTYwhyXMFcqrE1Fc/Hclq5mmLFY2Dgn7H6
	 +i+q1sEJm47TpjBVeMYHu358iN2j80a/UnkLhw0UawssT4r2izVMAcXHheelgZOCth
	 HdbX4tAta+Y5KIZmNIsC6A+V73pLfmfdU2x1FqkwZO3M/LJ4amTQh4AHRAlIvuppuu
	 V3/i7Mlo/oeKYVtDJCMuWbVbuROvgspP7zB6e6WnZ0httKBbS5jeruvZB964eGXWPG
	 I69bHNKfQP54A==
X-Cc: Simon Horman <horms@kernel.org>,
	David Ahern <dsahern@kernel.org>,
	Ido Schimmel <idosch@nvidia.com>,
	Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
	Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>,
	Xin Long <lucien.xin@gmail.com>,
	Aaron Conole <aconole@redhat.com>,
	Eelco Chaudron <echaudro@redhat.com>,
	Ilya Maximets <i.maximets@ovn.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Justin Iurman <justin.iurman@gmail.com>,
	Linus Lรผssing <linus.luessing@c0d3.blue>,
	Sabrina Dubroca <sd@queasysnail.net>,
	Stefano Brivio <sbrivio@redhat.com>,
	Hyunwoo Kim <imv4bel@gmail.com>,
	netdev@vger.kernel.org,
	linux-sctp@vger.kernel.org,
	dev@openvswitch.org,
	Eric Dumazet <edumazet@kernel.org>,
	stable@vger.kernel.org
X-Mailer: git-send-email 2.53.0
X-In-Reply-To: <20261113124625.4010206-1-edumazet@kernel.org>
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