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=1792689744; b=qi+cjrfa5s+BPTz+e5T5OB6TTqsspQe0F+ubOCkHBUOpEwAslLd+w6usVukA1WvYdToH Y6XED7bGldngvRe0/nfdayO80UDGTuWvHHVcFU35w0H0+HBpHPRVEjeqeKs8kGYBlmgdH BrCUsp6dv4z0zDPU8wRhLFUd2N2++AZyZtefwnCpjpACkz1zE6F4i9z2/hImB0nkPHUCb Fg+5WrbjOF2qcFOHDI+NEiDwKE8dgemG9cyd9sv+meizFlwc215JRszh9uUU+hyzFZaCA XMlr84QJthq2zRVZ4vU0v0671ZI7pHZutX2xXlq0Eno3eHoS/g/m2BR/C9d5ZFkfjZQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792689744; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=jvLxyUemcZ6OHmW/vOaMN2ACELM8HQ5bLXTBKTJqhDQ=; b=mnuVRJYe94ALELPkKClNgQVtydr5ZINymW4s3okBOr4Oxkivrsu5siJ1dOJGvuvSYpUQ AgTJFYoLo1bh5JaAw2MnM6/cORLCe/paG1mbz8xNHVH69TXsgRIRknLzAdN/IHheCBeTK mIGxYtguVSyeVM8x1DxcqbgMtlDZOVxckEbOEtM3JCA1K5mBdGtCFibk3PFB+Wyl1qLLa d0QkLmANWBOUM0dyQTXRI+rhb21jH5G+uuvZOfXgBRp+3Mmwcpe0UtehKoTSmD6bfzLky 83EdU+IHOmxcvJg0l2cPl8Aubpar4xQAHI/9Luehh2QjlaL8fwtFN+IGNj5CrZBomrA== 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=RjjpL0nF; 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 AC670606A319 for ; Thu, 22 Oct 2026 17:22:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=RjjpL0nF Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7407F1F01828; Thu, 22 Oct 2026 17:22:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1792689743; bh=jvLxyUemcZ6OHmW/vOaMN2ACELM8HQ5bLXTBKTJqhDQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=RjjpL0nFr2HP7yqBfnHGmWBeGBeBKw9alpcosxQX5pMcXWJ4DViOGvCkasOGN+gA0 W+fhcY8Jn9Pf8oisTq099cV0oKUbYdIbnrn+oQvat7qyzpvmI+bVnLoKfF/RoSiU/S 9agKBl8o6THQJg6HbNus/+DU2cfn/nC4ZYZTzPVfIRYhB26B/55XE9x40KMONgwPys jQLBV0KtiopeUc/h7yoLU96iqoOj0wunP0jsFCajZazihef3tML5SCaJHabEo4YOF0 2k5ZzxzIVJtM3ziJhYXlfgrUPxfb1eCE9xr6AetohidlN58M1DzskTDyxBL51zlNzy dG6fN6Gh3T6kA== From: Sasha Levin To: stable@vger.kernel.org Cc: Ido Schimmel , Amit Klein , Noam Caspi , David Ahern , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.18.y] ipv4: udp: Create exceptions before socket matching Date: Thu, 22 Oct 2026 13:22:21 -0400 Message-ID: <20261022172149.1756491-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026102115-squabble-mossy-a3ac@gregkh> References: <2026102115-squabble-mossy-a3ac@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: Ido Schimmel [ Upstream commit 4c3499f79f8c7e8561266bcc220a18538cec0458 ] Currently, when ICMP Fragmentation Needed and Redirect Message packets are locally delivered and quote a UDP packet, a FIB nexthop exception (FNHE) is only created if the kernel can match the UDP packet to an existing socket. This behavior allows off-path attackers to conduct a side-channel attack on the FNHE cache in order to discover the ephemeral port used by a connected UDP socket. Commit 6457378fe796 ("ipv4: use siphash instead of Jenkins in fnhe_hashfun()") and commit 67d6d681e15b ("ipv4: make exception cache less predictible") tried to mitigate such attacks by making it harder for attackers to discover hash collisions in the FNHE cache and by randomizing the number of exceptions a hash bucket can hold, respectively. Unfortunately, both of the mitigations can be bypassed. Instead, mitigate such attacks by always creating a FNHE, even before trying to find a matching socket. Do that by calling ipv4_update_pmtu() and ipv4_redirect(), the helpers used when the quoted packet did not originate from a socket. This means that guesses (right or wrong) from an off-path attacker will always result in a FNHE being created or updated in the cache that the attacker can observe. Pass an oif of 0, in a similar fashion to icmp_err(). This is also the oif used by the socket path for sockets that are not bound to a device. Note that this does not allow attackers to create FNHEs that they could not create before, as both helpers can already be reached with little to no validation. For example, by sending an ICMP error that quotes an ICMP Echo Reply or one that quotes a UDP source port that matches a wildcard socket. Also note that in the good case (matched socket) the above scheme comes at the cost of an extra route lookup, as the no socket helpers perform their own lookup before the one performed by ipv4_sk_update_pmtu() / ipv4_sk_redirect(). When the two resolve to different nexthops, it also results in two exceptions being created for the same destination IP. One in the FNHE cache of the nexthop resolved by the no socket helpers and another in the FNHE cache of the nexthop used by the socket. Fixes: 4895c771c7f0 ("ipv4: Add FIB nexthop exceptions.") Cc: stable@vger.kernel.org Reported-by: Amit Klein Reported-by: Noam Caspi Signed-off-by: Ido Schimmel Reviewed-by: David Ahern Link: https://patch.msgid.link/20260828192344.2596928-3-idosch@nvidia.com Signed-off-by: Jakub Kicinski [ sashal: inlined udp_err_update_exception() logic into the existing udp_err() wrapper to accommodate the separate __udp4_lib_err() handler. ] Signed-off-by: Sasha Levin --- net/ipv4/udp.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 341786983d42e..a7ae0d098f2c6 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -1033,7 +1033,16 @@ int __udp4_lib_err(struct sk_buff *skb, u32 info, struct udp_table *udptable) int udp_err(struct sk_buff *skb, u32 info) { - return __udp4_lib_err(skb, info, dev_net(skb->dev)->ipv4.udp_table); + const int type = icmp_hdr(skb)->type; + const int code = icmp_hdr(skb)->code; + struct net *net = dev_net(skb->dev); + + if (type == ICMP_DEST_UNREACH && code == ICMP_FRAG_NEEDED) + ipv4_update_pmtu(skb, net, info, 0, IPPROTO_UDP); + else if (type == ICMP_REDIRECT) + ipv4_redirect(skb, net, 0, IPPROTO_UDP); + + return __udp4_lib_err(skb, info, net->ipv4.udp_table); } /* -- 2.53.0