From: Ido Schimmel <idosch@nvidia.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
edumazet@google.com, dsahern@kernel.org, horms@kernel.org,
willemdebruijn.kernel@gmail.com, aksecurity@gmail.com,
noam.caspi@mail.huji.ac.il, Ido Schimmel <idosch@nvidia.com>,
stable@vger.kernel.org
Subject: [PATCH net 3/4] ipv6: udp: Create exceptions when socket matching failed
Date: Wed, 26 Aug 2026 17:37:34 +0300 [thread overview]
Message-ID: <20260826143735.1819315-4-idosch@nvidia.com> (raw)
In-Reply-To: <20260826143735.1819315-1-idosch@nvidia.com>
Currently, when ICMPv6 Packet Too Big and Redirect Message packets are
locally delivered and quote a UDP packet, an exception is created in the
IPv6 exception cache only 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 exception cache in order to discover the ephemeral port used by a
connected UDP socket.
Commit 4785305c05b2 ("ipv6: use siphash in rt6_exception_hash()") and
commit a00df2caffed ("ipv6: make exception cache less predictible") tried
to mitigate such attacks by making it harder for attackers to discover
hash collisions in the exception 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 an exception, even if
socket matching failed. Do that by calling ip6_update_pmtu() and
ip6_redirect(), the helpers used when the quoted packet did not
originate from a socket. The resulting exception is indistinguishable
from the one created when socket matching succeeded, both in terms of
cache occupancy and in terms of its contents.
Pass the ifindex of the ingress device and the default uid, in a similar
fashion to icmpv6_err(). Unlike IPv4, an oif of 0 would not match any
nexthop in ip6_redirect_nh_match() and no exception would be created in
response to a Redirect Message.
Note that this does not allow attackers to create exceptions that they
could not create before, as both helpers can already be reached with
little to no validation. For example, by sending an ICMPv6 error that
quotes an ICMPv6 Echo Reply or one that quotes a UDP source port that
matches a wildcard socket.
Also create an exception when a socket does not wish to accept PMTU
updates (e.g., by setting 'IPV6_PMTUDISC_OMIT'). Otherwise, the fact
that an exception was not created can indicate to an off-path attacker
that a socket exists. Unlike IPv4, the check is performed in udpv6_err()
and not in ip6_sk_update_pmtu(), as its only other caller, rawv6_err(),
does not consult ip6_sk_accept_pmtu() and therefore already creates an
exception unconditionally.
Fixes: 2b760fcf5cfb ("ipv6: hook up exception table to store dst cache")
Cc: stable@vger.kernel.org
Reported-by: Amit Klein <aksecurity@gmail.com>
Reported-by: Noam Caspi <noam.caspi@mail.huji.ac.il>
Reviewed-by: David Ahern <dsahern@kernel.org>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
---
net/ipv6/udp.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index fd875908ac0c..df14fc2afe8a 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -690,6 +690,17 @@ static struct sock *__udp6_lib_err_encap(struct net *net,
return sk;
}
+static void udpv6_err_no_sk(struct net *net, struct sk_buff *skb, u8 type,
+ __be32 info)
+{
+ if (type == ICMPV6_PKT_TOOBIG)
+ ip6_update_pmtu(skb, net, info, skb->dev->ifindex, 0,
+ sock_net_uid(net, NULL));
+ else if (type == NDISC_REDIRECT)
+ ip6_redirect(skb, net, skb->dev->ifindex, 0,
+ sock_net_uid(net, NULL));
+}
+
static int udpv6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
u8 type, u8 code, int offset, __be32 info)
{
@@ -719,6 +730,7 @@ static int udpv6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
sk = ERR_PTR(-ENOENT);
if (IS_ERR(sk)) {
+ udpv6_err_no_sk(net, skb, type, info);
__ICMP6_INC_STATS(net, __in6_dev_get(skb->dev),
ICMP6_MIB_INERRORS);
return PTR_ERR(sk);
@@ -731,8 +743,11 @@ static int udpv6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
np = inet6_sk(sk);
if (type == ICMPV6_PKT_TOOBIG) {
- if (!ip6_sk_accept_pmtu(sk))
+ if (!ip6_sk_accept_pmtu(sk)) {
+ ip6_update_pmtu(skb, net, info, skb->dev->ifindex, 0,
+ sock_net_uid(net, NULL));
goto out;
+ }
ip6_sk_update_pmtu(skb, sk, info);
if (READ_ONCE(np->pmtudisc) != IPV6_PMTUDISC_DONT)
harderr = 1;
--
2.55.0
next prev parent reply other threads:[~2026-08-26 14:39 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-26 14:37 [PATCH net 0/4] Mitigate a side channel in routing exception caches Ido Schimmel
2026-08-26 14:37 ` [PATCH net 1/4] ipv6: Fix redirect exception creation for UDP/RAW sockets Ido Schimmel
2026-08-26 14:37 ` [PATCH net 2/4] ipv4: udp: Create exceptions when socket matching failed Ido Schimmel
2026-08-26 15:50 ` Eric Dumazet
2026-08-27 19:33 ` Ido Schimmel
2026-08-26 14:37 ` Ido Schimmel [this message]
2026-08-26 15:51 ` [PATCH net 3/4] ipv6: " Eric Dumazet
2026-08-26 14:37 ` [PATCH net 4/4] selftests: net: Add exception cache tests Ido Schimmel
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=20260826143735.1819315-4-idosch@nvidia.com \
--to=idosch@nvidia.com \
--cc=aksecurity@gmail.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=noam.caspi@mail.huji.ac.il \
--cc=pabeni@redhat.com \
--cc=stable@vger.kernel.org \
--cc=willemdebruijn.kernel@gmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).