mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net] udp: don't apply socketless ICMP PMTU/redirect updates on end hosts
@ 2026-11-26  0:31 Tom
  2026-11-26  0:32 ` netdev-bot+sinfo
  0 siblings, 1 reply; 3+ messages in thread
From: Tom @ 2026-11-26  0:31 UTC (permalink / raw)
  To: netdev
  Cc: David Miller, dsahern, eric.dumazet, kuba, willemdebruijn.kernel, LKML

ICMP error messages are unauthenticated and quote an attacker-chosen
inner header.  udp_err_update_exception() (and its IPv6 twin
udpv6_err_update_exception()) process ICMP Destination Unreachable
messages with Code 4 (fragmentation needed, RFC 792) and ICMP Redirect
messages before any socket lookup, calling ipv4_update_pmtu() /
ipv4_redirect() with no socket and oif = 0.  The resulting change is
stored in a route entry's PMTU, which every user of that route shares;
on a non-forwarding end host with one route to the internet, the
change affects the entire network namespace.

A single forged ICMP Destination Unreachable with Code 4 lets any
remote host pin the victim's PMTU toward an arbitrary destination,
degrading or denying service for flows using that route, depending on
their packet sizes: values below net.ipv4.ip_rt_min_pmtu are clamped
and locked (see __ip_rt_update_pmtu()), so a locked 552-byte PMTU
persists until a route flush and breaks PMTUDISC_DO senders
(EMSGSIZE) and QUIC (RFC 9000 minimum 1200-byte datagrams), among
others.  The in-kernel ICMP
rate limit exempts fragmentation-needed errors from its ratemask, so
attacker-controlled entries can be refreshed unthrottled.

TCP drops errors for packets that match no socket (tcp_v4_err(),
net/ipv4/tcp_ipv4.c); UDP should not be more trusting than TCP on end
hosts, where forwarded flows do not exist: an error that matches no
socket would then change no route state at all.

Fix this by only performing socketless PMTU/redirect updates where they
are actually required -- for forwarded traffic on a router
(net.ipv4.ip_forward enabled on IPv4, net.ipv6.conf.all.forwarding on
IPv6).  On routers, this path keeps its original preconditions and
residual exposure, which transit traffic legitimately requires.  On
end hosts, PMTU updates continue to work for socket-bound
flows through ipv4_sk_update_pmtu() / ip6_sk_update_pmtu(); those
paths are intentionally unchanged -- an error matched to a real socket
updating the route entry for its own path is the accepted PMTUD trust
model (PMTU state is a route property for TCP and UDP alike; the
matched-socket difference is who may trigger the update, not where the
state lives); this patch only removes the evidence-free flow-agnostic
route-wide write.  Errors whose quoted inner header matches no
socket, including those from middleboxes that rewrite or mangle the
flow (NATs without ICMP inner-header translation, for example), are
ignored on end hosts; NAT devices that translate ICMP inner payloads
deliver the original tuple, which continues to match.  Encapsulated
tunnels keep their own error path
(__udp4_lib_err_encap_no_sk() / __udp6_lib_err_encap_no_sk()).

Reproducer (forged ICMP Destination Unreachable with Code 4, inner
header quotes no real socket):
  pre:  1400-byte UDP sendto with IP_PMTUDISC_DO succeeds (local path)
  send: ICMP Destination Unreachable, Code 4, next-hop MTU = 1100,
        inner IP header src=<local>/dst=<peer>,
        inner UDP header (no matching socket)
  post: same sendto returns EMSGSIZE; claims below ip_rt_min_pmtu
        (default 552) additionally install a locked 552-byte floor that
        persists until a route flush; identical result with a packet
        source address that does not match the inner header (nothing
        correlates them).

Verified on two builds of the same kernel (6.12), differing only by
this change: without it, a forged ICMP Destination Unreachable with
Code 4 quoting a UDP flow with no matching socket installs the route
MTU for MTU = 1100 (unlocked, self-heals via aging) and for MTU = 500
a clamped locked 552-byte floor that persists until a route flush; a
forged packet quoting zeroed inner UDP ports behaves identically.  An
error matched to a real connected UDP socket still applies its PMTU to
that socket's path (the unchanged socket-matched PMTUD path,
ipv4_sk_update_pmtu()).  With the patch and ip_forward = 0, forged
packets of both shapes are ignored while the socket-matched path is
unchanged; with ip_forward = 1, socketless updates keep working
(router parity).  A genuine end-to-end PMTU event, generated by a real
forwarding router with an 800-byte-MTU egress interface against a
PMTUDISC_DO sender, still shrinks the sender's route: the sender gets
EMSGSIZE on the oversized datagram and completes delivery at the
reduced size, with and without the change.

Also gates the Redirect half of the same problem pre-lookup
(udp: ipv4_redirect()/ip6_redirect() were reachable from forged ICMP
Redirects without a socket); generic ICMP redirect dispatch is left
untouched for other transports.

Signed-off-by: Tomas Bortoli <tomasbortoli@gmail.com>
---
 net/ipv4/udp.c | 15 +++++++++++-----
 net/ipv6/udp.c |  6 ++++++
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 2e5562f353f8..503575f0cf6c 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -913,10 +913,17 @@
 static void udp_err_update_exception(struct net *net, struct sk_buff *skb,
      int type, int code, u32 info)
 {
- 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);
+ /* ICMP errors are unauthenticated and quote an attacker-chosen
+ * inner header.  Socketless PMTU/redirect updates are only
+ * legitimate for forwarded traffic on routers; end hosts do not
+ * act on UDP errors for non-existent flows.
+ */
+ if (IPV4_DEVCONF_ALL_RO(net, FORWARDING)) {
+ 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);
+ }
 }

 /*
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index a6886a0432f9..d1cf5ce2b00a 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -694,6 +694,12 @@
 static void udpv6_err_update_exception(struct net *net, struct sk_buff *skb,
        u8 type, __be32 info)
 {
+ /* Same hardening as IPv4: only forwarded traffic on routers may
+ * drive socketless PMTU/redirect updates.
+ */
+ if (!net->ipv6.devconf_all->forwarding)
+ return;
+
  if (type == ICMPV6_PKT_TOOBIG)
  ip6_update_pmtu(skb, net, info, skb->dev->ifindex, 0,
  sock_net_uid(net, NULL));
-- 
2.47.3

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-26  0:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-26  0:31 [PATCH net] udp: don't apply socketless ICMP PMTU/redirect updates on end hosts Tom
2026-11-26  0:32 ` netdev-bot+sinfo
2026-11-26  0:33   ` Tom

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®