From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796386677; b=Q/guPT9rnPnObVUuiQ4Ft/0dEZZyMwdeBM9qETDDm5D97OTt9xTsg66RgpeOSCP8I98J 3iYobIdZ3i/BzYXKfNXqooRFr2LcCw4hxsiLVVqggIyZm5plsoUWS6QzMhYy5Po1tpSaV odBw139vHPesBsV9ytW65dwxrS6RQ4jYXyq6YfR/SNipc6sc2NBqVchVa0431kdPqD7OQ z+uJ/fVtsJuYB9LfVHY9jue5Dd/QXrDjp5rBNcHJs9pVFgzbA9d4+cChCIUj0OlnteGcL ZMLNXa/HhHgLvVXrw8YvaQNlHN03Cf3Pi8glFHs5mR3bpIkDnj6Ktwih/gldrAgyG8Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796386677; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=W86WpTMnY4eNkGXAJN1KBTFqYlTXCpaf6oUL0p4WjGc=; b=PKMKUqMxkhHj1ylJ+328ZRO+oB0qbsY+0gKB0GT46a3wS1zIBGrYAdc1bxyO3BGqQI5+ PQAFGHOS4HMGmdtQo1vAH09uPBAyhCpmAfD500FLCaycL4Gklp6LM2ZH1f3LkcEi6fM2J yyL6I+gkYji6n5uAVM4PWy0NxOF7eL8/zExM8PNwvKnYQyFj2GhquyUNtFEbIkUaeP0u/ geZQlz6/xN9PII6rCBSHG2br/HgeCLy0Vq78Dh3p25+n96aS3HacbrQ+nLgsKhd5k3orr EzD6eTqkn0Elgyebedm5dFvsJoNixIuHqRkVXU/eKVNQk/Fm7oFuHUjh23wgajaVzxw== 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=KHOWxbaR; arc=none smtp.remote-ip=100.103.45.18 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 33639606A322 for ; Fri, 4 Dec 2026 12:17:57 +0000 (UTC) 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=KHOWxbaR Received: by smtp.kernel.org (Postfix) with ESMTPSA id 29DD41F000C2; Fri, 4 Dec 2026 12:17:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796386677; bh=W86WpTMnY4eNkGXAJN1KBTFqYlTXCpaf6oUL0p4WjGc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=KHOWxbaR56EJ0rhZgbNbDY/R/4NyPz8nDrBjsGnLNzfd3Kp5MUMclofq6TwnAvDEU bEts7ep5YWze/COTtWO3tsgE41uX6THUzrcezHHbJ7ytoBUcutCAehStx8yTlxx0m7 sC6Qb0Bd/nXNCn6m0IpsN/+1iNy4OLYC93Xa5nlck6LEEiYUhWD7pKQyUCn6ZHv7BJ 8QpNszJeEKG0fQUsSqikl7QT2XFNfqETqzvTl2JyZOn8XEU9vDn/h3W0kBYfaCeAz7 qS1cgdGlYjBxoZop+tbjXgHS6939YqkaO/rGQ/y/1lYMIXaczQ+QVIQ2EGGcC3DnEQ oRrSdHMEDA5DA== From: Sasha Levin To: stable@vger.kernel.org Cc: Eric Dumazet , Stefano Brivio , Justin Iurman , Paolo Abeni , Sasha Levin 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 Message-ID: <20261204121747.3000895-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026120203-snowbound-duration-4fc5@gregkh> References: <2026120203-snowbound-duration-4fc5@gregkh> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Eric Dumazet [ 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 Reviewed-by: Stefano Brivio Link: https://patch.msgid.link/20261113124625.4010206-6-edumazet@kernel.org Reviewed-by: Justin Iurman Signed-off-by: Paolo Abeni Signed-off-by: Sasha Levin --- 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