[PATCH net] ipv4: do not trust ICMP-locked PMTU while forwarding
From: James Sawyer via B4 Relay
Date: Thu Dec 03 2026 - 06:59:19 EST
From: James Sawyer <james@xxxxxxxxxxxxxxxxx>
Commit f87c10a8aa1e ("ipv4: introduce ip_dst_mtu_maybe_forward and
protect forwarding path against pmtu spoofing") made the forwarding
path ignore path MTUs learned from ICMP, because they can be forged,
and only honour an MTU the administrator locked on the route.
Commit d52e5a7e7ca4 ("ipv4: lock mtu in fnhe when received PMTU <
net.ipv4.route.min_pmtu") made ICMP-learned values below min_pmtu
"locked" as well, so the host stops setting DF on its own packets, and
switched ip_dst_mtu_maybe_forward() to ip_mtu_locked(). As a result the
only learned PMTU that forwarding still trusts is a value below
min_pmtu, which is the value an off-path attacker would pick.
One ICMP fragmentation-needed message sent to a router, quoting a UDP
packet from the router to a destination D with an MTU below 552, makes
the router clamp to 552 every DF packet it forwards to D, for 600 s,
renewable. Hosts behind the router get frag-needed (mtu = 552) from
their gateway, and DF traffic larger than that (for example QUIC, which
needs 1200 bytes) to D fails; their TCP MSS to D drops to 500. No socket
has to match the quoted packet: a quoted ICMP echo reply reaches
ipv4_update_pmtu() through icmp_err(), and a quoted UDP packet does so
through udp_err_update_exception().
While forwarding, trust only the administrative lock again, in both
places the helper tests it; the 576-byte clamp for gateway routes
further down must not apply to an ICMP-induced lock either. Local
traffic keeps the 2018 behaviour (no DF on its own packets).
Reproduced on 7.0.0-43-generic (Ubuntu 26.04) with network namespaces:
a NAT gateway with two inside hosts, an attacker that can reach only
the gateway's public address and D, and UDP 1200-byte payloads with
IP_PMTUDISC_DO and IP_PMTUDISC_PROBE from both inside hosts: 0 of 3
delivered after one forged message with MTU 551 (3 runs); delivered
after a forged MTU of 1000 (unlocked) and with net.ipv4.route.min_pmtu=68
(the same value stored unlocked). Quoting an echo reply instead of UDP
gave the same result. The same worked from an inside host against a
gateway whose input policy trusts its LAN. An independent reproduction
on a second VM with separately written scripts matched every case.
Tested on v7.4-rc1 in QEMU with the same setup: unpatched, one forged
MTU 551 left 0 of 3 DF datagrams delivered from each inside host; with
this patch the exception is still stored ("mtu lock 552") but forwarded
traffic is unaffected (3 of 3, ping -M do 1400 passes), and the
router's own output still honours the stored PMTU. Built with W=1
(ip_forward.o, ip_output.o) without warnings.
The netfilter flowtable uses the same helper and is covered by this
change. IPVS (dst_mtu() in ip_vs_xmit.c) and ipmr have their own MTU
logic and are not changed here. A reproducer is available on request.
This issue was found and the fix written with AI assistance.
Fixes: d52e5a7e7ca4 ("ipv4: lock mtu in fnhe when received PMTU < net.ipv4.route.min_pmtu")
Signed-off-by: James Sawyer <james@xxxxxxxxxxxxxxxxx>
---
Notes for reviewers (not for the commit):
- Found and fixed with AI assistance. All measurements were run by me in a
lab on 7.0.0-43-generic (Ubuntu 26.04) in network namespaces; the same
code is in 7.4-rc1. A reproducer (namespace rig + forged ICMP) is
available privately on request and is not being published.
- Related, sent separately: an ip_tunnel patch for IPv6 payload when the
tunnel MTU drops below IPV6_MIN_MTU.
- Not covered here: IPVS (ip_vs_xmit.c uses dst_mtu()) and ipmr have their
own MTU logic; I have not tested them.
---
include/net/ip.h | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/include/net/ip.h b/include/net/ip.h
index 0acc4ba5e5b3..86244604fee6 100644
--- a/include/net/ip.h
+++ b/include/net/ip.h
@@ -478,13 +478,21 @@ static inline unsigned int ip_dst_mtu_maybe_forward(const struct dst_entry *dst,
const struct net_device *dev;
unsigned int mtu, res;
struct net *net;
+ bool locked;
+
+ /* While forwarding, trust only an administratively locked route
+ * MTU. rt_mtu_locked is also set when an ICMP-learned PMTU is below
+ * min_pmtu, and such ICMP messages can be forged off-path.
+ */
+ locked = forwarding ? dst_metric_locked(dst, RTAX_MTU) :
+ ip_mtu_locked(dst);
rcu_read_lock();
dev = dst_dev_rcu(dst);
net = dev_net_rcu(dev);
if (READ_ONCE(net->ipv4.sysctl_ip_fwd_use_pmtu) ||
- ip_mtu_locked(dst) ||
+ locked ||
!forwarding) {
mtu = rt->rt_pmtu;
if (mtu && time_before(jiffies, READ_ONCE(rt->dst.expires)))
@@ -498,7 +506,7 @@ static inline unsigned int ip_dst_mtu_maybe_forward(const struct dst_entry *dst,
mtu = READ_ONCE(dev->mtu);
- if (unlikely(ip_mtu_locked(dst))) {
+ if (unlikely(locked)) {
if (rt->rt_uses_gateway && mtu > 576)
mtu = 576;
}
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261203-ipv4-fwd-icmp-locked-pmtu-0c179dc82b44
Best regards,
--
James Sawyer <james@xxxxxxxxxxxxxxxxx>