Skip to contentSkip to conversation

Fix UDP length overflow in edge cases

PATCH Superseded Alice Mikityanska 2 participants 8 messages Aug 13 – Aug 18

Subsystems (4)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover Fix UDP length overflow in edge cases

From: Alice Mikityanska <[email protected]>

These are fixes for rare edge cases of 16-bit UDP length field overflow that might happen on netdevs with MTU >= 64k.

Exposed by the new WARN added to udp_set_len_short, reported by syzbot.

v1: https://lore.kernel.org/netdev/[email protected]/

Alice Mikityanska (2):
net: Fix UDP length overflow with PMTU discover and big MTU
net: ipv6: Clamp to IP6_MAX_MTU in ip6_dst_mtu_maybe_forward

 include/net/ip6_route.h                      |  2 +
 net/ipv4/ip_output.c                         |  2 +
 net/ipv6/ip6_output.c                        |  2 +-
 tools/testing/selftests/net/Makefile         |  1 +
 tools/testing/selftests/net/cork_fragsize.py | 77 ++++++++++++++++++++
 5 files changed, 83 insertions(+), 1 deletion(-)
 create mode 100755 tools/testing/selftests/net/cork_fragsize.py
Signature · 1 line
2.55.0
#1 lore raw

PATCH v2 1/2 net: Fix UDP length overflow with PMTU discover and big MTU

From: Alice Mikityanska <[email protected]>

This commit bounds cork->base.fragsize to IP(6)_MAX_MTU to avoid a possible overflow of UDP length that triggers a WARN in udp_set_len_short when setsockopt IP(V6)_MTU_DISCOVER is set to IPV6_PMTUDISC_DO or IP(V6)_PMTUDISC_PROBE, and a large packet is sent over a netdev with an unusually large MTU.

Steps to reproduce (included in the new selftest):

1. Set device MTU bigger than IP6_MAX_MTU (or IP_MAX_MTU + 20). cork->base.fragsize will be set to that MTU in ip(6)_setup_cork.
2. Set IP(V6)_MTU_DISCOVER to IP(V6)_PMTUDISC_PROBE or IPV6_PMTUDISC_DO. It lets maxnonfragsize be set to device MTU (cork->fragsize) in __ip(6)_append_data, rather than to IP(6)_MAX_MTU.
3. Send 65528 bytes of payload (+8 bytes of UDP header, +20/40 bytes of IPv4/IPv6 header). Device MTU allows it (it's only one byte bigger than IP6_MAX_MTU or IP_MAX_MTU + IPv4 header, and the device MTU is bigger than that).
4. The UDP length in the built packet is 65536, which overflows the 16-bit length field and triggers the WARN in udp_set_len_short.

Note: IP_PMTUDISC_DO with IPv4 is safe, because ip_dst_mtu_maybe_forward always clamps at IP_MAX_MTU, unlike ip6_dst_mtu_maybe_forward.

The Fixes tag points at the first commit where I could reproduce the overflow with IPv4 and IP_PMTUDISC_PROBE.

Fixes daba287b299e ("ipv4: fix DO and PROBE pmtu mode regarding local fragmentation with UFO/CORK")
Reported-by [email protected]
Assisted-by Claude:claude-sonnet-4.6
Cc Willem de Bruijn <[email protected]>
---
 net/ipv4/ip_output.c                         |  2 +
 net/ipv6/ip6_output.c                        |  2 +-
 tools/testing/selftests/net/Makefile         |  1 +
 tools/testing/selftests/net/cork_fragsize.py | 77 ++++++++++++++++++++
 4 files changed, 81 insertions(+), 1 deletion(-)
 create mode 100755 tools/testing/selftests/net/cork_fragsize.py
net/ipv4/ip_output.c +2 -0
index e6dd1e5b8c32..2bc997c4fa7b 100644
@@ -1299,6 +1299,8 @@ static int ip_setup_cork(struct sock *sk, struct inet_cork *cork,
 
 	cork->fragsize = ip_sk_use_pmtu(sk) ?
 			 dst4_mtu(&rt->dst) : READ_ONCE(rt->dst.dev->mtu);
+	if (cork->fragsize > IP_MAX_MTU)
+		cork->fragsize = IP_MAX_MTU;
 
 	if (!inetdev_valid_mtu(cork->fragsize))
 		return -ENETUNREACH;
net/ipv6/ip6_output.c +1 -1
index 2c44e5ed6171..81fb61b94759 100644
@@ -1430,7 +1430,7 @@ static int ip6_setup_cork(struct sock *sk, struct inet_cork_full *cork,
 	if (frag_size && frag_size < mtu)
 		mtu = frag_size;
 
-	cork->base.fragsize = mtu;
+	cork->base.fragsize = min(mtu, IP6_MAX_MTU);
 	cork->base.gso_size = ipc6->gso_size;
 	cork->base.tx_flags = 0;
 	cork->base.mark = ipc6->sockc.mark;
tools/testing/selftests/net/Makefile +1 -0
index 708d960ae07d..82a1407f6a69 100644
@@ -24,6 +24,7 @@ TEST_PROGS := \
 	cmsg_so_mark.sh \
 	cmsg_so_priority.sh \
 	cmsg_time.sh \
+	cork_fragsize.py \
 	double_udp_encap.sh \
 	drop_monitor_tests.sh \
 	ecmp_rehash.sh \
tools/testing/selftests/net/cork_fragsize.py new file +77 -0

77 lines not on this page · raw message

Signature · 1 line
2.55.0
#2 lore raw

Re: [PATCH net v2 1/2] net: Fix UDP length overflow with PMTU discover and big MTU

Quoted 28 lines · Alice Mikityanska

From: Alice Mikityanska <[email protected]>

This commit bounds cork->base.fragsize to IP(6)_MAX_MTU to avoid a possible overflow of UDP length that triggers a WARN in udp_set_len_short when setsockopt IP(V6)_MTU_DISCOVER is set to IPV6_PMTUDISC_DO or IP(V6)_PMTUDISC_PROBE, and a large packet is sent over a netdev with an unusually large MTU.

Steps to reproduce (included in the new selftest):

1. Set device MTU bigger than IP6_MAX_MTU (or IP_MAX_MTU + 20). cork->base.fragsize will be set to that MTU in ip(6)_setup_cork.
2. Set IP(V6)_MTU_DISCOVER to IP(V6)_PMTUDISC_PROBE or IPV6_PMTUDISC_DO. It lets maxnonfragsize be set to device MTU (cork->fragsize) in __ip(6)_append_data, rather than to IP(6)_MAX_MTU.
3. Send 65528 bytes of payload (+8 bytes of UDP header, +20/40 bytes of IPv4/IPv6 header). Device MTU allows it (it's only one byte bigger than IP6_MAX_MTU or IP_MAX_MTU + IPv4 header, and the device MTU is bigger than that).
4. The UDP length in the built packet is 65536, which overflows the 16-bit length field and triggers the WARN in udp_set_len_short.

Note: IP_PMTUDISC_DO with IPv4 is safe, because ip_dst_mtu_maybe_forward always clamps at IP_MAX_MTU, unlike ip6_dst_mtu_maybe_forward.

The Fixes tag points at the first commit where I could reproduce the overflow with IPv4 and IP_PMTUDISC_PROBE.

Quoted 6 lines
Fixes daba287b299e ("ipv4: fix DO and PROBE pmtu mode regarding local fragmentation with UFO/CORK")
Reported-by [email protected]
Assisted-by Claude:claude-sonnet-4.6
Cc Willem de Bruijn <[email protected]>

Not sure whether IPv4 and IPv6 should be separate patches. IPv6 will have a different Fixes tag.

Per maintainer-netdev.rst, mixing code and test changes in the same patch is also discouraged.

Quoted 13 lines
---
 net/ipv4/ip_output.c                         |  2 +
 net/ipv6/ip6_output.c                        |  2 +-
 tools/testing/selftests/net/Makefile         |  1 +
 tools/testing/selftests/net/cork_fragsize.py | 77 ++++++++++++++++++++
 4 files changed, 81 insertions(+), 1 deletion(-)
 create mode 100755 tools/testing/selftests/net/cork_fragsize.py
net/ipv4/ip_output.c +0 -0
index e6dd1e5b8c32..2bc997c4fa7b 100644

net/ipv4/ip_output.c static int ip_setup_cork(struct sock *sk, struct inet_cork *cork, · line 1303

Quoted 5 lines
net/ipv4/ip_output.c +2 -0
@@ -1299,6 +1299,8 @@ static int ip_setup_cork(struct sock *sk, struct inet_cork *cork,
 
 	cork->fragsize = ip_sk_use_pmtu(sk) ?
 			 dst4_mtu(&rt->dst) : READ_ONCE(rt->dst.dev->mtu);
+	if (cork->fragsize > IP_MAX_MTU)
+		cork->fragsize = IP_MAX_MTU;

if respinning: use min(), like IPv6? It's even more concise and easier to read.

net/ipv6/ip6_output.c static int ip6_setup_cork(struct sock *sk, struct inet_cork_full *cork, · line 1433

Quoted 13 lines
net/ipv4/ip_output.c +0 -0
 	if (!inetdev_valid_mtu(cork->fragsize))
 		return -ENETUNREACH;
net/ipv6/ip6_output.c +1 -1
index 2c44e5ed6171..81fb61b94759 100644
@@ -1430,7 +1430,7 @@ static int ip6_setup_cork(struct sock *sk, struct inet_cork_full *cork,
 	if (frag_size && frag_size < mtu)
 		mtu = frag_size;
 
-	cork->base.fragsize = mtu;
+	cork->base.fragsize = min(mtu, IP6_MAX_MTU);

Not sure whether a limitation that we seriously have to care about, but:

This restricts all IPv6 protocols, while only UDP has the length field limitation.

With IPv6 jumbo frames and RAW sockets, could there be a valid case for larger fragsize?

Quoted 101 lines
net/ipv6/ip6_output.c +0 -0
 	cork->base.gso_size = ipc6->gso_size;
 	cork->base.tx_flags = 0;
 	cork->base.mark = ipc6->sockc.mark;
tools/testing/selftests/net/Makefile +1 -0
index 708d960ae07d..82a1407f6a69 100644
@@ -24,6 +24,7 @@ TEST_PROGS := \
 	cmsg_so_mark.sh \
 	cmsg_so_priority.sh \
 	cmsg_time.sh \
+	cork_fragsize.py \
 	double_udp_encap.sh \
 	drop_monitor_tests.sh \
 	ecmp_rehash.sh \
tools/testing/selftests/net/cork_fragsize.py new file +77 -0
new file mode 100755
index 000000000000..7a1bb069227a
@@ -0,0 +1,77 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+# Test possible UDP length overflow in udp_send_skb/udp_v6_send_skb.
+
+from lib.py import ksft_run, ksft_exit, ksft_true
+from lib.py import ip, NetNS, NetNSEnter
+import errno
+import socket
+import subprocess
+
+
+IP_MTU_DISCOVER = 10
+IP_PMTUDISC_PROBE = 3
+IPV6_MTU_DISCOVER = 23
+IPV6_PMTUDISC_DO = 2
+
+
+def check_dmesg_clean(func) -> bool:
+    dmesg = subprocess.Popen(['dmesg'], stdout=subprocess.PIPE)
+    result = subprocess.run(['grep', '-q', f'WARNING:.*{func}'], stdin=dmesg.stdout)
+    dmesg.wait()
+    return result.returncode != 0 and dmesg.returncode == 0
+
+
+def test_ipv6() -> None:
+    with NetNS() as ns:
+        ip('link add dummy type dummy', ns=ns)
+        ip('link set dummy mtu 65576', ns=ns)
+        ip('link set dummy up', ns=ns)
+        ip('-6 addr add fd00::1/64 dev dummy nodad', ns=ns)
+        ip('-6 neigh add fd00::2 lladdr 02:00:00:00:00:02 dev dummy nud permanent', ns=ns)
+
+        with NetNSEnter(ns):
+            with socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) as fd:
+                fd.setsockopt(socket.IPPROTO_IPV6, IPV6_MTU_DISCOVER, IPV6_PMTUDISC_DO)
+                try:
+                    fd.sendto(b' ' * 65528, ('fd00::2', 1234))
+                except OSError as e:
+                    # Ignore EMSGSIZE: it happens on kernels with the fix.
+                    if e.errno != errno.EMSGSIZE:
+                        raise
+
+        ip('link del dummy', ns=ns)
+
+    ksft_true(check_dmesg_clean('udp_v6_send_skb'), 'WARNING detected in dmesg')
+
+
+def test_ipv4() -> None:
+    with NetNS() as ns:
+        ip('link add dummy type dummy', ns=ns)
+        ip('link set dummy mtu 65556', ns=ns)
+        ip('link set dummy up', ns=ns)
+        ip('addr add 10.0.0.1/24 dev dummy', ns=ns)
+        ip('neigh add 10.0.0.2 lladdr 02:00:00:00:00:02 dev dummy nud permanent', ns=ns)
+
+        with NetNSEnter(ns):
+            with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as fd:
+                fd.setsockopt(socket.IPPROTO_IP, IP_MTU_DISCOVER, IP_PMTUDISC_PROBE)
+                try:
+                    fd.sendto(b' ' * 65528, ('10.0.0.2', 1234))
+                except OSError as e:
+                    # Ignore EMSGSIZE: the check happens after the WARN is printed.
+                    if e.errno != errno.EMSGSIZE:
+                        raise
+
+        ip('link del dummy', ns=ns)
+
+    ksft_true(check_dmesg_clean('udp_send_skb'), 'WARNING detected in dmesg')
+
+
+if __name__ == "__main__":
+    ksft_run([
+        test_ipv6,
+        test_ipv4,
+    ])
+    ksft_exit()
Signature · 1 line
2.55.0
#3 lore raw

Re: [PATCH net v2 1/2] net: Fix UDP length overflow with PMTU discover and big MTU

Quoted 79 lines · Willem de Bruijn
Quoted 28 lines · Alice Mikityanska

From: Alice Mikityanska <[email protected]>

This commit bounds cork->base.fragsize to IP(6)_MAX_MTU to avoid a possible overflow of UDP length that triggers a WARN in udp_set_len_short when setsockopt IP(V6)_MTU_DISCOVER is set to IPV6_PMTUDISC_DO or IP(V6)_PMTUDISC_PROBE, and a large packet is sent over a netdev with an unusually large MTU.

Steps to reproduce (included in the new selftest):

1. Set device MTU bigger than IP6_MAX_MTU (or IP_MAX_MTU + 20). cork->base.fragsize will be set to that MTU in ip(6)_setup_cork.
2. Set IP(V6)_MTU_DISCOVER to IP(V6)_PMTUDISC_PROBE or IPV6_PMTUDISC_DO. It lets maxnonfragsize be set to device MTU (cork->fragsize) in __ip(6)_append_data, rather than to IP(6)_MAX_MTU.
3. Send 65528 bytes of payload (+8 bytes of UDP header, +20/40 bytes of IPv4/IPv6 header). Device MTU allows it (it's only one byte bigger than IP6_MAX_MTU or IP_MAX_MTU + IPv4 header, and the device MTU is bigger than that).
4. The UDP length in the built packet is 65536, which overflows the 16-bit length field and triggers the WARN in udp_set_len_short.

Note: IP_PMTUDISC_DO with IPv4 is safe, because ip_dst_mtu_maybe_forward always clamps at IP_MAX_MTU, unlike ip6_dst_mtu_maybe_forward.

The Fixes tag points at the first commit where I could reproduce the overflow with IPv4 and IP_PMTUDISC_PROBE.

Quoted 6 lines
Fixes daba287b299e ("ipv4: fix DO and PROBE pmtu mode regarding local fragmentation with UFO/CORK")
Reported-by [email protected]
Assisted-by Claude:claude-sonnet-4.6
Cc Willem de Bruijn <[email protected]>

Not sure whether IPv4 and IPv6 should be separate patches. IPv6 will have a different Fixes tag.

Per maintainer-netdev.rst, mixing code and test changes in the same patch is also discouraged.

Quoted 13 lines
---
 net/ipv4/ip_output.c                         |  2 +
 net/ipv6/ip6_output.c                        |  2 +-
 tools/testing/selftests/net/Makefile         |  1 +
 tools/testing/selftests/net/cork_fragsize.py | 77 ++++++++++++++++++++
 4 files changed, 81 insertions(+), 1 deletion(-)
 create mode 100755 tools/testing/selftests/net/cork_fragsize.py
net/ipv4/ip_output.c +0 -0
index e6dd1e5b8c32..2bc997c4fa7b 100644

net/ipv4/ip_output.c static int ip_setup_cork(struct sock *sk, struct inet_cork *cork, · line 1303

Quoted 5 lines
net/ipv4/ip_output.c +2 -0
@@ -1299,6 +1299,8 @@ static int ip_setup_cork(struct sock *sk, struct inet_cork *cork,
 
 	cork->fragsize = ip_sk_use_pmtu(sk) ?
 			 dst4_mtu(&rt->dst) : READ_ONCE(rt->dst.dev->mtu);
+	if (cork->fragsize > IP_MAX_MTU)
+		cork->fragsize = IP_MAX_MTU;

if respinning: use min(), like IPv6? It's even more concise and easier to read.

net/ipv6/ip6_output.c static int ip6_setup_cork(struct sock *sk, struct inet_cork_full *cork, · line 1433

Quoted 13 lines
net/ipv4/ip_output.c +0 -0
 	if (!inetdev_valid_mtu(cork->fragsize))
 		return -ENETUNREACH;
net/ipv6/ip6_output.c +1 -1
index 2c44e5ed6171..81fb61b94759 100644
@@ -1430,7 +1430,7 @@ static int ip6_setup_cork(struct sock *sk, struct inet_cork_full *cork,
 	if (frag_size && frag_size < mtu)
 		mtu = frag_size;
 
-	cork->base.fragsize = mtu;
+	cork->base.fragsize = min(mtu, IP6_MAX_MTU);

Not sure whether a limitation that we seriously have to care about, but:

Quoted 5 lines

This restricts all IPv6 protocols, while only UDP has the length field limitation.

With IPv6 jumbo frames and RAW sockets, could there be a valid case for larger fragsize?

True; if a valid jumbo UDP (length=0, with IPv6 HBH exthdr) packet is crafted manually with SOCK_RAW, it's dropped after my change. I'll respin, limiting the clamp to UDP sockets only.

I'll also split IPv4/IPv6/selftest into separate patches, also adding a selftest for SOCK_RAW.

Quoted 101 lines
Quoted 101 lines
net/ipv6/ip6_output.c +0 -0
 	cork->base.gso_size = ipc6->gso_size;
 	cork->base.tx_flags = 0;
 	cork->base.mark = ipc6->sockc.mark;
tools/testing/selftests/net/Makefile +1 -0
index 708d960ae07d..82a1407f6a69 100644
@@ -24,6 +24,7 @@ TEST_PROGS := \
 	cmsg_so_mark.sh \
 	cmsg_so_priority.sh \
 	cmsg_time.sh \
+	cork_fragsize.py \
 	double_udp_encap.sh \
 	drop_monitor_tests.sh \
 	ecmp_rehash.sh \
tools/testing/selftests/net/cork_fragsize.py new file +77 -0
new file mode 100755
index 000000000000..7a1bb069227a
@@ -0,0 +1,77 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+# Test possible UDP length overflow in udp_send_skb/udp_v6_send_skb.
+
+from lib.py import ksft_run, ksft_exit, ksft_true
+from lib.py import ip, NetNS, NetNSEnter
+import errno
+import socket
+import subprocess
+
+
+IP_MTU_DISCOVER = 10
+IP_PMTUDISC_PROBE = 3
+IPV6_MTU_DISCOVER = 23
+IPV6_PMTUDISC_DO = 2
+
+
+def check_dmesg_clean(func) -> bool:
+    dmesg = subprocess.Popen(['dmesg'], stdout=subprocess.PIPE)
+    result = subprocess.run(['grep', '-q', f'WARNING:.*{func}'], stdin=dmesg.stdout)
+    dmesg.wait()
+    return result.returncode != 0 and dmesg.returncode == 0
+
+
+def test_ipv6() -> None:
+    with NetNS() as ns:
+        ip('link add dummy type dummy', ns=ns)
+        ip('link set dummy mtu 65576', ns=ns)
+        ip('link set dummy up', ns=ns)
+        ip('-6 addr add fd00::1/64 dev dummy nodad', ns=ns)
+        ip('-6 neigh add fd00::2 lladdr 02:00:00:00:00:02 dev dummy nud permanent', ns=ns)
+
+        with NetNSEnter(ns):
+            with socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) as fd:
+                fd.setsockopt(socket.IPPROTO_IPV6, IPV6_MTU_DISCOVER, IPV6_PMTUDISC_DO)
+                try:
+                    fd.sendto(b' ' * 65528, ('fd00::2', 1234))
+                except OSError as e:
+                    # Ignore EMSGSIZE: it happens on kernels with the fix.
+                    if e.errno != errno.EMSGSIZE:
+                        raise
+
+        ip('link del dummy', ns=ns)
+
+    ksft_true(check_dmesg_clean('udp_v6_send_skb'), 'WARNING detected in dmesg')
+
+
+def test_ipv4() -> None:
+    with NetNS() as ns:
+        ip('link add dummy type dummy', ns=ns)
+        ip('link set dummy mtu 65556', ns=ns)
+        ip('link set dummy up', ns=ns)
+        ip('addr add 10.0.0.1/24 dev dummy', ns=ns)
+        ip('neigh add 10.0.0.2 lladdr 02:00:00:00:00:02 dev dummy nud permanent', ns=ns)
+
+        with NetNSEnter(ns):
+            with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as fd:
+                fd.setsockopt(socket.IPPROTO_IP, IP_MTU_DISCOVER, IP_PMTUDISC_PROBE)
+                try:
+                    fd.sendto(b' ' * 65528, ('10.0.0.2', 1234))
+                except OSError as e:
+                    # Ignore EMSGSIZE: the check happens after the WARN is printed.
+                    if e.errno != errno.EMSGSIZE:
+                        raise
+
+        ip('link del dummy', ns=ns)
+
+    ksft_true(check_dmesg_clean('udp_send_skb'), 'WARNING detected in dmesg')
+
+
+if __name__ == "__main__":
+    ksft_run([
+        test_ipv6,
+        test_ipv4,
+    ])
+    ksft_exit()
Signature · 1 line
2.55.0
#4 lore raw

PATCH v2 2/2 net: ipv6: Clamp to IP6_MAX_MTU in ip6_dst_mtu_maybe_forward

In reply to Alice Mikityanska

From: Alice Mikityanska <[email protected]>

Commit 427faee167bc ("net: ipv6: introduce ip6_dst_mtu_maybe_forward") dropped the IP6_MAX_MTU clamp that used to be present in ip6_mtu(). A similar IPv4 commit ac6627a28dbf ("net: ipv4: Consolidate ipv4_mtu and ip_dst_mtu_maybe_forward") preserves the IP_MAX_MTU clamp.

Restore the upper bound in the IPv6 flow to avoid potential 16-bit overflows in forwarding paths.

Fixes 427faee167bc ("net: ipv6: introduce ip6_dst_mtu_maybe_forward")
---
 include/net/ip6_route.h | 2 ++
 1 file changed, 2 insertions(+)
include/net/ip6_route.h +2 -0
index 09ffe0f13ce7..fb59a5885faa 100644
@@ -382,6 +382,8 @@ static inline unsigned int ip6_dst_mtu_maybe_forward(const struct dst_entry *dst
 	rcu_read_unlock();
 
 out:
+	mtu = min_t(unsigned int, mtu, IP6_MAX_MTU);
+
 	return mtu - lwtunnel_headroom(dst->lwtstate, mtu);
 }
 
Signature · 1 line
2.55.0
Reviewed-by on v2 2/2
#5 lore raw

Re: [PATCH net v2 2/2] net: ipv6: Clamp to IP6_MAX_MTU in ip6_dst_mtu_maybe_forward

Quoted 7 lines · Alice Mikityanska

From: Alice Mikityanska <[email protected]>

Commit 427faee167bc ("net: ipv6: introduce ip6_dst_mtu_maybe_forward") dropped the IP6_MAX_MTU clamp that used to be present in ip6_mtu(). A similar IPv4 commit ac6627a28dbf ("net: ipv4: Consolidate ipv4_mtu and ip_dst_mtu_maybe_forward") preserves the IP_MAX_MTU clamp.

Quoted 6 lines

Restore the upper bound in the IPv6 flow to avoid potential 16-bit overflows in forwarding paths.

Fixes 427faee167bc ("net: ipv6: introduce ip6_dst_mtu_maybe_forward")
Quoted 9 lines
---
 include/net/ip6_route.h | 2 ++
 1 file changed, 2 insertions(+)
include/net/ip6_route.h +0 -0
index 09ffe0f13ce7..fb59a5885faa 100644

include/net/ip6_route.h static inline unsigned int ip6_dst_mtu_maybe_forward(const struct dst_entry *dst · line 388

Quoted 7 lines
include/net/ip6_route.h +2 -0
@@ -382,6 +382,8 @@ static inline unsigned int ip6_dst_mtu_maybe_forward(const struct dst_entry *dst
 	rcu_read_unlock();
 
 out:
+	mtu = min_t(unsigned int, mtu, IP6_MAX_MTU);
+
 	return mtu - lwtunnel_headroom(dst->lwtstate, mtu);
 }

It appears IPv4 only clamps device MTU, not route MTU:

        mtu = dst_metric_raw(dst, RTAX_MTU);
        if (!mtu)
                mtu = min(READ_ONCE(dst->dev->mtu), IP_MAX_MTU);

I don't think that was necessarily intentional. Perhaps route MTU itself is already bounds checked on configuration. The device MTU min() was added after a syzbot report, in commit c780a049f9b.

Current IPv6 proposal is arguably more robust, covering both. There just remains a difference between IPv4 and IPv6 code paths.

#6 lore raw

Re: [PATCH net v2 2/2] net: ipv6: Clamp to IP6_MAX_MTU in ip6_dst_mtu_maybe_forward

Quoted 36 lines · Willem de Bruijn
Quoted 7 lines · Alice Mikityanska

From: Alice Mikityanska <[email protected]>

Commit 427faee167bc ("net: ipv6: introduce ip6_dst_mtu_maybe_forward") dropped the IP6_MAX_MTU clamp that used to be present in ip6_mtu(). A similar IPv4 commit ac6627a28dbf ("net: ipv4: Consolidate ipv4_mtu and ip_dst_mtu_maybe_forward") preserves the IP_MAX_MTU clamp.

Quoted 6 lines

Restore the upper bound in the IPv6 flow to avoid potential 16-bit overflows in forwarding paths.

Fixes 427faee167bc ("net: ipv6: introduce ip6_dst_mtu_maybe_forward")
Quoted 9 lines
---
 include/net/ip6_route.h | 2 ++
 1 file changed, 2 insertions(+)
include/net/ip6_route.h +0 -0
index 09ffe0f13ce7..fb59a5885faa 100644

include/net/ip6_route.h static inline unsigned int ip6_dst_mtu_maybe_forward(const struct dst_entry *dst · line 388

Quoted 7 lines
include/net/ip6_route.h +2 -0
@@ -382,6 +382,8 @@ static inline unsigned int ip6_dst_mtu_maybe_forward(const struct dst_entry *dst
 	rcu_read_unlock();
 
 out:
+	mtu = min_t(unsigned int, mtu, IP6_MAX_MTU);
+
 	return mtu - lwtunnel_headroom(dst->lwtstate, mtu);
 }

It appears IPv4 only clamps device MTU, not route MTU:

Quoted 3 lines
        mtu = dst_metric_raw(dst, RTAX_MTU);
        if (!mtu)
                mtu = min(READ_ONCE(dst->dev->mtu), IP_MAX_MTU);

This is some old code from v5.14, it changed in commit ac6627a28dbf ("net: ipv4: Consolidate ipv4_mtu and ip_dst_mtu_maybe_forward"), and IPv4 clamps MTU in both cases since then.

Quoted 3 lines

I don't think that was necessarily intentional. Perhaps route MTU itself is already bounds checked on configuration. The device MTU min() was added after a syzbot report, in commit c780a049f9b.

This commit merely adds READ_ONCE to the existing min.

Quoted 2 lines

Current IPv6 proposal is arguably more robust, covering both. There just remains a difference between IPv4 and IPv6 code paths.

So, looking at the fresh checkout, it seems that my patch covers the difference, right?

#7 lore raw

Re: [PATCH net v2 2/2] net: ipv6: Clamp to IP6_MAX_MTU in ip6_dst_mtu_maybe_forward

Quoted 37 lines · Alice Mikityanska
Quoted 36 lines · Willem de Bruijn
Quoted 7 lines · Alice Mikityanska

From: Alice Mikityanska <[email protected]>

Commit 427faee167bc ("net: ipv6: introduce ip6_dst_mtu_maybe_forward") dropped the IP6_MAX_MTU clamp that used to be present in ip6_mtu(). A similar IPv4 commit ac6627a28dbf ("net: ipv4: Consolidate ipv4_mtu and ip_dst_mtu_maybe_forward") preserves the IP_MAX_MTU clamp.

Quoted 6 lines

Restore the upper bound in the IPv6 flow to avoid potential 16-bit overflows in forwarding paths.

Fixes 427faee167bc ("net: ipv6: introduce ip6_dst_mtu_maybe_forward")
Quoted 9 lines
---
 include/net/ip6_route.h | 2 ++
 1 file changed, 2 insertions(+)
include/net/ip6_route.h +0 -0
index 09ffe0f13ce7..fb59a5885faa 100644

include/net/ip6_route.h static inline unsigned int ip6_dst_mtu_maybe_forward(const struct dst_entry *dst · line 388

Quoted 7 lines
include/net/ip6_route.h +2 -0
@@ -382,6 +382,8 @@ static inline unsigned int ip6_dst_mtu_maybe_forward(const struct dst_entry *dst
 	rcu_read_unlock();
 
 out:
+	mtu = min_t(unsigned int, mtu, IP6_MAX_MTU);
+
 	return mtu - lwtunnel_headroom(dst->lwtstate, mtu);
 }

It appears IPv4 only clamps device MTU, not route MTU:

Quoted 7 lines
Quoted 3 lines
        mtu = dst_metric_raw(dst, RTAX_MTU);
        if (!mtu)
                mtu = min(READ_ONCE(dst->dev->mtu), IP_MAX_MTU);

This is some old code from v5.14, it changed in commit ac6627a28dbf ("net: ipv4: Consolidate ipv4_mtu and ip_dst_mtu_maybe_forward"), and IPv4 clamps MTU in both cases since then.

Oh indeed.

Quoted 11 lines
Quoted 3 lines

I don't think that was necessarily intentional. Perhaps route MTU itself is already bounds checked on configuration. The device MTU min() was added after a syzbot report, in commit c780a049f9b.

This commit merely adds READ_ONCE to the existing min.

Quoted 2 lines

Current IPv6 proposal is arguably more robust, covering both. There just remains a difference between IPv4 and IPv6 code paths.

So, looking at the fresh checkout, it seems that my patch covers the difference, right?

Yes, agreed.