From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Eric Dumazet <edumazet@kernel.org>,
Stefano Brivio <sbrivio@redhat.com>,
Justin Iurman <justin.iurman@gmail.com>,
Paolo Abeni <pabeni@redhat.com>, Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.6.y] udp: use skb_set_transport_header_careful() in __udp6_lib_err_encap()
Date: Fri, 4 Dec 2026 07:17:54 -0500 [thread overview]
Message-ID: <20261204121747.3000895-1-sashal@kernel.org> (raw)
In-Reply-To: <2026120203-snowbound-duration-4fc5@gregkh>
From: Eric Dumazet <edumazet@kernel.org>
[ Upstream commit 02f578b736f1524ed73ef879fb1cf1ba4a875aa4 ]
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>
Reviewed-by: Stefano Brivio <sbrivio@redhat.com>
Link: https://patch.msgid.link/20261113124625.4010206-6-edumazet@kernel.org
Reviewed-by: Justin Iurman <justin.iurman@gmail.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
Depends on <20261204121247.2991699-1-sashal@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 efda97a61b8b5..bb7030ba5abcf 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -578,12 +578,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
prev parent reply other threads:[~2026-12-04 12:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 15:15 FAILED: patch "[PATCH] udp: use skb_set_transport_header_careful() in" failed to apply to 6.6-stable tree gregkh
2026-12-04 12:17 ` Sasha Levin [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261204121747.3000895-1-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=edumazet@kernel.org \
--cc=justin.iurman@gmail.com \
--cc=pabeni@redhat.com \
--cc=sbrivio@redhat.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.