Netdev List
 help / color / mirror / Atom feed
* [PATCH net] ip_tunnel: fragment IPv6 payload when the tunnel MTU is below IPV6_MIN_MTU
@ 2026-12-03 11:59 James Sawyer via B4 Relay
  2026-12-04 12:44 ` netdev-bot+sashiko
  0 siblings, 1 reply; 2+ messages in thread
From: James Sawyer via B4 Relay @ 2026-12-03 11:59 UTC (permalink / raw)
  To: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman
  Cc: netdev, linux-kernel, James Sawyer

From: James Sawyer <james@jamessawyer.co.uk>

When the path MTU to the tunnel peer leaves less than IPV6_MIN_MTU for
an IPv6 payload, tnl_update_pmtu() cannot send a Packet Too Big (IPv6
has no smaller MTU to report) and returns 0 with the outer DF still
set. The encapsulated packet is then dropped by ip_fragment() and the
sender gets no signal at all: IPv6 over GRE silently blackholes every
packet larger than the remaining MTU.

The path MTU can be lowered this way by one forged ICMP
fragmentation-needed message to the tunnel endpoint quoting the
tunnel's outer packet. With plain GRE (24 bytes of overhead) any
unlocked value from 552 to 1303 triggers it. Values below 552 are
stored locked, so iptunnel_xmit() already clears DF in that case.

sit already handles this case by clearing DF ("if (mtu < IPV6_MIN_MTU)
{ mtu = IPV6_MIN_MTU; df = 0; }"). Do the same for ip_tunnel users, so
the outer packet is fragmented instead of dropped. tnl_update_pmtu()
now takes df by reference. For collect_md tunnels this also overrides
IP_TUNNEL_DONT_FRAGMENT_BIT in this one case, as sit does.

Reproduced on 7.0.0-43-generic with network namespaces: after one
forged ICMP with MTU 1000 to the GRE endpoint, 1232-byte UDP payloads
over IPv6 were sent without error and 0 of 3 arrived; a capture on the
sender showed no ICMPv6 Packet Too Big (4 runs).

Tested on v7.4-rc1 in QEMU: unpatched, IPv6 1232-byte payloads over
GRE after a forged MTU of 1000 were 0 of 3 delivered and ping6 lost
3 of 3; with this patch 3 of 3 were delivered and ping6 passed. IPv4
over the same tunnel is unchanged (frag-needed with mtu = 976 is still
returned). Built with W=1 (net/ipv4/ip_tunnel.o) without warnings.

This issue was found and the fix written with AI assistance.

Fixes: c54419321455 ("GRE: Refactor GRE tunneling code.")
Signed-off-by: James Sawyer <james@jamessawyer.co.uk>
---
Notes for reviewers (not for the commit):
- Found and fixed with AI assistance. Measured by me in a lab on
  7.0.0-43-generic in network namespaces; reproducer available privately
  on request.
- Behaviour change to check: for collect_md tunnels with
  IP_TUNNEL_DONT_FRAGMENT_BIT set, this clears DF in the sub-1280 case,
  matching what sit does. If that flag should win, the check can be
  limited to !md.
- Related, sent separately: "ipv4: do not trust ICMP-locked PMTU while
  forwarding".
---
 net/ipv4/ip_tunnel.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c
index 0875474a578a..6ea2bf14047b 100644
--- a/net/ipv4/ip_tunnel.c
+++ b/net/ipv4/ip_tunnel.c
@@ -514,7 +514,7 @@ int ip_tunnel_encap_setup(struct ip_tunnel *t,
 EXPORT_SYMBOL_GPL(ip_tunnel_encap_setup);
 
 static int tnl_update_pmtu(struct net_device *dev, struct sk_buff *skb,
-			    struct rtable *rt, __be16 df,
+			    struct rtable *rt, __be16 *df,
 			    const struct iphdr *inner_iph,
 			    int tunnel_hlen, __be32 dst, bool md)
 {
@@ -526,7 +526,7 @@ static int tnl_update_pmtu(struct net_device *dev, struct sk_buff *skb,
 	pkt_size = skb->len - tunnel_hlen;
 	pkt_size -= dev->type == ARPHRD_ETHER ? dev->hard_header_len : 0;
 
-	if (df) {
+	if (*df) {
 		mtu = dst_mtu(&rt->dst) - (sizeof(struct iphdr) + tunnel_hlen);
 		mtu -= dev->type == ARPHRD_ETHER ? dev->hard_header_len : 0;
 	} else {
@@ -553,6 +553,13 @@ static int tnl_update_pmtu(struct net_device *dev, struct sk_buff *skb,
 					   NULL;
 		daddr = md ? dst : tunnel->parms.iph.daddr;
 
+		/* IPv6 cannot signal a path MTU below IPV6_MIN_MTU, so no
+		 * Packet Too Big can be sent below. Fragment the outer packet
+		 * instead of dropping it, as sit does.
+		 */
+		if (mtu < IPV6_MIN_MTU)
+			*df = 0;
+
 		if (rt6 && mtu < dst_mtu(skb_dst(skb)) &&
 			   mtu >= IPV6_MIN_MTU) {
 			if ((daddr && !ipv4_is_multicast(daddr)) ||
@@ -632,7 +639,7 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
 
 	if (test_bit(IP_TUNNEL_DONT_FRAGMENT_BIT, key->tun_flags))
 		df = htons(IP_DF);
-	if (tnl_update_pmtu(dev, skb, rt, df, inner_iph, tunnel_hlen,
+	if (tnl_update_pmtu(dev, skb, rt, &df, inner_iph, tunnel_hlen,
 			    key->u.ipv4.dst, true)) {
 		ip_rt_put(rt);
 		goto tx_error;
@@ -807,7 +814,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
 	if (payload_protocol == htons(ETH_P_IP) && !tunnel->ignore_df)
 		df |= (inner_iph->frag_off & htons(IP_DF));
 
-	if (tnl_update_pmtu(dev, skb, rt, df, inner_iph, 0, 0, false)) {
+	if (tnl_update_pmtu(dev, skb, rt, &df, inner_iph, 0, 0, false)) {
 		ip_rt_put(rt);
 		goto tx_error;
 	}

---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261203-ip-tunnel-ipv6-min-mtu-df-75896af91973

Best regards,
--  
James Sawyer <james@jamessawyer.co.uk>



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

* Re: [PATCH net] ip_tunnel: fragment IPv6 payload when the tunnel MTU is below IPV6_MIN_MTU
  2026-12-03 11:59 [PATCH net] ip_tunnel: fragment IPv6 payload when the tunnel MTU is below IPV6_MIN_MTU James Sawyer via B4 Relay
@ 2026-12-04 12:44 ` netdev-bot+sashiko
  0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-12-04 12:44 UTC (permalink / raw)
  To: james
  Cc: dsahern, idosch, davem, edumazet, kuba, pabeni, horms, netdev,
	linux-kernel

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 2 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] The commit message and the new comment in tnl_update_pmtu()
  (net/ipv4/ip_tunnel.c:556-561) both say the change matches sit.
- [Medium] For collect_md GRE/IPIP, ip_md_tunnel_xmit()
  (net/ipv4/ip_tunnel.c:640-646) sets `df = htons(IP_DF)` from…

--

ip_tunnel: fragment IPv6 payload when the tunnel MTU is below IPV6_MIN_MTU

This patch changes tnl_update_pmtu() to take df by reference. For IPv6
payloads it now clears df when the computed tunnel MTU is below
IPV6_MIN_MTU, so the outer IPv4 packet is fragmented instead of dropped.
ip_tunnel_xmit() and ip_md_tunnel_xmit() are both updated to pass &df.

> diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c
> index 0875474a578a4..6ea2bf14047b3 100644
> --- a/net/ipv4/ip_tunnel.c
> +++ b/net/ipv4/ip_tunnel.c

[ ... ]

> @@ -553,6 +553,13 @@ static int tnl_update_pmtu(struct net_device *dev, struct sk_buff *skb,
>  					   NULL;
>  		daddr = md ? dst : tunnel->parms.iph.daddr;
>  
> +		/* IPv6 cannot signal a path MTU below IPV6_MIN_MTU, so no
> +		 * Packet Too Big can be sent below. Fragment the outer packet
> +		 * instead of dropping it, as sit does.
> +		 */
> +		if (mtu < IPV6_MIN_MTU)
> +			*df = 0;

[Severity: Medium]
Does this fully match what sit does? The comment and the commit message
both cite sit, but ipip6_tunnel_xmit() also raises mtu to IPV6_MIN_MTU
before using it:

net/ipv6/sit.c:ipip6_tunnel_xmit() {
    ...
		if (mtu < IPV6_MIN_MTU) {
			mtu = IPV6_MIN_MTU;
			df = 0;
		}

		if (parms->iph.daddr)
			skb_dst_update_pmtu_no_confirm(skb, mtu);

		if (skb->len > mtu && !skb_is_gso(skb)) {
			icmpv6_ndo_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
    ...
}

Here mtu stays below 1280. Earlier in tnl_update_pmtu() this call runs
with that value:

	if (skb_valid_dst(skb))
		skb_dst_update_pmtu_no_confirm(skb, mtu);

__ip6_rt_update_pmtu() returns early when mtu < IPV6_MIN_MTU, so the
inner route PMTU is never lowered.

The rt6 metric update and the ICMPV6_PKT_TOOBIG branch just below this
hunk both require mtu >= IPV6_MIN_MTU, so neither of them runs either.

That seems to leave every inner IPv6 packet from 1281 bytes up to the
tunnel device MTU (about 1476 for plain GRE) going out as outer IPv4
fragments while the reduced PMTU lasts. This includes full-size TCP and
GSO segments, and the sender is never told to use 1280. Is that intended?

With sit, only packets of 1280 bytes or less are fragmented. Larger ones
get a PTB(1280).

The tests in the commit message used 1232-byte UDP payloads, which are
exactly 1280-byte IPv6 packets. At that size the two behaviours are the
same.

Should this also set mtu = IPV6_MIN_MTU before the
skb_dst_update_pmtu_no_confirm() call, so the existing PMTU update and
PTB paths run as they do in sit? If not, the comment and the commit
message should probably not claim parity with sit.

[ ... ]

> @@ -632,7 +639,7 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
>  
>  	if (test_bit(IP_TUNNEL_DONT_FRAGMENT_BIT, key->tun_flags))
>  		df = htons(IP_DF);
> -	if (tnl_update_pmtu(dev, skb, rt, df, inner_iph, tunnel_hlen,
> +	if (tnl_update_pmtu(dev, skb, rt, &df, inner_iph, tunnel_hlen,
>  			    key->u.ipv4.dst, true)) {
>  		ip_rt_put(rt);
>  		goto tx_error;

[Severity: Medium]
For collect_md GRE/IPIP tunnels, can the outer packet now go out without
DF even though the tunnel key asked for it?

When IP_TUNNEL_DONT_FRAGMENT_BIT is set, df becomes htons(IP_DF). For
IPv6 payloads below 1280, the new "*df = 0" in tnl_update_pmtu() then
clears it, and iptunnel_xmit() writes the result into iph->frag_off.

The uAPI for this flag doesn't mention an exception:

include/uapi/linux/openvswitch.h:
	OVS_TUNNEL_KEY_ATTR_DONT_FRAGMENT,      /* No argument, set DF. */

include/uapi/linux/bpf.h:
 *		**BPF_F_DONT_FRAGMENT**
 *			Add a flag to tunnel metadata indicating that the
 *			packet should not be fragmented.

TCA_TUNNEL_KEY_NO_FRAG is also a plain flag.

geneve_xmit_skb() still honours the same key flag as given:

drivers/net/geneve.c:geneve_xmit_skb() {
    ...
		df = test_bit(IP_TUNNEL_DONT_FRAGMENT_BIT, key->tun_flags) ?
		     htons(IP_DF) : 0;
    ...
}

So the same request would now give DF on geneve but no DF on GRE/IPIP.

The commit message says:

    For collect_md tunnels this also overrides
    IP_TUNNEL_DONT_FRAGMENT_BIT in this one case, as sit does.

However, sit has no collect_md path for IPv6 payloads and never reads
IP_TUNNEL_DONT_FRAGMENT_BIT. The sit precedent doesn't seem to cover the
md case.

The notes below the commit message raise this as an open question. Would
it be better to limit the override to !md? The other option is to
document the exception for IPv6 payloads below 1280.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203-ip-tunnel-ipv6-min-mtu-df-v1-1-ef4b415911a5%40jamessawyer.co.uk

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

end of thread, other threads:[~2026-12-04 12:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 11:59 [PATCH net] ip_tunnel: fragment IPv6 payload when the tunnel MTU is below IPV6_MIN_MTU James Sawyer via B4 Relay
2026-12-04 12:44 ` netdev-bot+sashiko

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