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=1796382625; b=dZ0s9axSSMGhzHHgJhbuXDIU0C1uLWYCr86ewNBuz9gYb1dG521ldACujsAV80JVOsjR XySRYXvg758azZ5Zeie+8Qj4DnVBKDHNH8KY/dURDQn03Mwdb54gcU9SaKdPngCCvieG/ pzJUY4A22kQKHxnpGpbXT3VxJx5mO5zFe+PkcXflHuNGGI+g4RsE0zYqQT4gUSkCF7HAU lKLh74j32mC++YjonhyQq+VFjbrOa9VGKfAmHqBX+zMVqO6hqIfqsRi8LRaWv0jsn6ZfQ QbZotN7uuOjXF3OrOydNa8sUCkfCHFh7Bki3ki0JyeqnFjQMNAqnKqXTlXxTKx87xlA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382625; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=nm0DrvQ7s6eVey7hf+sC6+WZ5uGpj86L83BMlCnexts=; b=O8/KBC5c/Ze93kMXhj6SGJS9H9sDUIfXnmDfCXZ6sSryTv0DwJRTow4dNl/OJku8Hrxb A8Ryzq2tg7UAqWYaaxZsEI0qU08Soa4S0JTyyIErPifT14XAXq/ZXzUysg+zyQB8Rxdad PvH5em/+SSePtHZ2SfyEqU67NbHzpWriPpbjdCmwjtoppkgnivlnZxLYmAnpx7spHyp+e pASaYHEoeb23S13kbX97ulxmzIfSDE5JrXZDWcVhmXQznPE2I7bgWIUThDq1NRVzvjGfo I7h7fG882m/bBgM0Uwthx3iVUrB58wDObyJfUXVQYOYfgq1XVKQ0B7XDCam4JRASbEw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=kxjYjn2b; 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 56A37606A322; Fri, 4 Dec 2026 11:10:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=kxjYjn2b Received: by smtp.kernel.org (Postfix) with ESMTPSA id C267A1F000C2; Fri, 4 Dec 2026 11:10:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382625; bh=nm0DrvQ7s6eVey7hf+sC6+WZ5uGpj86L83BMlCnexts=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=kxjYjn2bnVUgOMX748aNjT62jGGUVQUg3Ln2U6P8X9vPYCRqgXLvvHeHbT49rPU3+ Z2MS+7eQ04zkXgvm1ybdoTOZLXXFLChp7dTkpgXKYcWn8Vw9bug/GIyhsVYlFvUR0s FIEXMUDt81PGTFU1leA92hnwqHxwcdSnUsuvSusk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Eric Dumazet , Stefano Brivio , Justin Iurman , Paolo Abeni Subject: [PATCH 6.18 533/703] udp: use skb_set_transport_header_careful() in __udp6_lib_err_encap() Date: Fri, 4 Dec 2026 19:07:12 +0900 Message-ID: <20261204100641.969238958@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Dumazet commit 02f578b736f1524ed73ef879fb1cf1ba4a875aa4 upstream. 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: Greg Kroah-Hartman --- net/ipv6/udp.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -662,12 +662,13 @@ static struct sock *__udp6_lib_err_encap 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);