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=1796387299; b=zckrR3zf8mN3Y8vAhzYhziq9qO4LZZMCSqdSG4p3egOQ/XQ+Zja99QzF2P9rukpe5LxP UQBEXVhQFyo5fEUouCPgALLdrYTUuZ7puM/sYzK7RDFEd/cT//D0waNc1Ns4iTHz09RNb sH341O8N6EV5BWOnziogOBrWWvu0aqEiagRoKq7JUWrOz6xY8XZwtNfwXRMDsoDQ/Vmdn cSAXqhRbIXYbENyoHRFuMis3jaGbfRwULD5nxKg5eX4EH3ZGUjA+tkOkSnIIb/13126l0 II1Jui4mXYOnhoJO+vYTVHrJyxWnzeYEBYvPAEXLZXR/hiOXLWfnVAOdYNpIgVZ9/6g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387299; 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=HUFaTmFwEaXuMV2VVf6ZD2byu7ggaQrgRMbBGE4HBtE=; b=U3xAo7PA+VGg4OgrSs9A4GryBUX9/gHE/wSKH2bhsmOFcKo9bsrhXL6+rS6cyEA47FjV Bn8Nn/PLkITOdpts5lnZNSY0H43hr5IQE2HRXWAcOWurqTokITH5wceOBIYL2AtdH44GN l8cu80bHIXImsW2YSKPzbz6vlZEEoL0da1L/D/semEzexAJoOlbZZkdpeRZP4PJzy/A/E ohk6Lb4a5toRf+AcNHo3Va/OKsqooXd0FESut7wHA6Q4Msr49Qmiz958yScpki4h3JBEx DOCSjSRAPQK6CW2CXP7o0M/kN/5cb1jJ5jLuxaO28WWKN4p9h/F04AnrfuRnmbUzApw== 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=V88yLB8k; 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 EAF23606A322; Fri, 4 Dec 2026 12:28:18 +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=V88yLB8k Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E5C21F000C2; Fri, 4 Dec 2026 12:28:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387298; bh=HUFaTmFwEaXuMV2VVf6ZD2byu7ggaQrgRMbBGE4HBtE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=V88yLB8klfZzqoyaIlyqi1ggv2/c9moLP2fHDi0SfRl+5NP6YUsEGZO1qNg03K2m/ 2tycqCZKI8w/V4YTiWW4KlsxCqHz4TjlN0HyWxye1KDj3+Uct2i+z7rUaHY+UiAGoX N5yr2uw8NeIChuTxJviEsOTF94/KwPr5908f7i+E= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Eric Dumazet , Kuniyuki Iwashima , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.1 0185/1059] udp: do not use a cross-family sk_rx_dst in early demux Date: Fri, 4 Dec 2026 18:55:16 +0900 Message-ID: <20261204100649.073190174@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore 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 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Dumazet [ Upstream commit 5636e67320563be743d47706ef4914078c27edb2 ] A dual-stack UDP socket connected to a v4-mapped address can receive both IPv4 packets and IPv6 packets using v4-mapped addresses: ip6_rcv_core() no longer rejects a v4-mapped source since commit dcc32f4f183a ("ipv6: weaken the v4mapped source check"), which kept that check only in tcp_v6_conn_request(). ipv6_portaddr_hash() hashes v4-mapped addresses like IPv4 ones, so both early demux handlers find the socket, and both __udp4_lib_rcv() and __udp6_lib_rcv() store their input dst in the same sk->sk_rx_dst. udp_v6_early_demux() validates the cached dst with dst_check(), but ipv4_dst_check() ignores the cookie, so an IPv4 dst gets attached to an IPv6 skb. ip6_rcv_finish_core() then skips the route lookup and ip_local_deliver() parses the IPv6 header as an IPv4 one: the IPv6 next header and hop limit are read as a fragment offset, and the IPv4 protocol is taken from a source address byte. The reverse direction looks possible too: per-cpu dsts of IPv6 routes using nexthop objects have rt->sernum set, and ip6_dst_check() then ignores the cookie, so udp_v4_early_demux() can attach an IPv6 dst to an IPv4 skb. Kyle Zeng reported that such a packet can reach XFRM input still holding the prefetched, non refcounted, socket set by early demux, which can then outlive its RCU grace period. Only use the cached dst if its family matches the packet. Otherwise fall back to a regular route lookup. TCP does not have the same problem: sk_ehashfn() hashes a v4-mapped socket with inet_ehashfn(), while IPv6 lookups use inet6_ehashfn(), so IPv6 packets do not normally find a v4-mapped TCP socket. Fixes: 5425077d73e0 ("net: ipv6: Add early demux handler for UDP unicast") Fixes: c9f2c1ae123a ("udp6: fix socket leak on early demux") Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20261106110135.2161204-1-edumazet@kernel.org Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/ipv4/udp.c | 5 ++++- net/ipv6/udp.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 3c41aed3788c0..7777568c612b9 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -2686,8 +2686,11 @@ int udp_v4_early_demux(struct sk_buff *skb) skb->destructor = sock_efree; dst = rcu_dereference(sk->sk_rx_dst); - if (dst) + /* A dual-stack socket can cache an IPv6 dst. */ + if (dst && dst->ops->family == AF_INET) dst = dst_check(dst, 0); + else + dst = NULL; if (dst) { u32 itag = 0; diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index d335e4ff35cb3..565a0fc8f7cc1 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -1188,8 +1188,11 @@ void udp_v6_early_demux(struct sk_buff *skb) skb->destructor = sock_efree; dst = rcu_dereference(sk->sk_rx_dst); - if (dst) + /* A dual-stack socket can cache an IPv4 dst. */ + if (dst && dst->ops->family == AF_INET6) dst = dst_check(dst, sk->sk_rx_dst_cookie); + else + dst = NULL; if (dst) { /* set noref for now. * any place which wants to hold dst has to call -- 2.53.0