Skip to contentSkip to conversation

ipv6: fix MSG_SPLICE_PAGES with a dst trailer in __ip6_append_data()

PATCH Applied Kyuwon Cho 4 participants 5 messages Nov 22 – Nov 29

Subsystems (3)
lore
Share & tools
lore

Kyuwon Cho

author
#0 lore raw

cover ipv6: fix MSG_SPLICE_PAGES with a dst trailer in __ip6_append_data()

sendfile() of a UDPv6 datagram that needs fragmentation over an xfrm tunnel hits a WARN_ON_ONCE() in __ip6_append_data() and fails with EIO. The patch removes the MSG_SPLICE_PAGES branch that causes it, as proposed in the report; Ido asked for it to be sent as a patch.

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

The issue was found by an LLM-guided test generator that we are developing as a research prototype; the report has the reproducer. The patch was written with LLM assistance; we reviewed and tested it. With it, the reproducer runs clean and all its sendfile() calls succeed, where they all fail with EIO before.

Kyuwon Cho (1):
ipv6: fix MSG_SPLICE_PAGES with a dst trailer in __ip6_append_data()

 net/ipv6/ip6_output.c | 2 --
 1 file changed, 2 deletions(-)
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH 1/1 ipv6: fix MSG_SPLICE_PAGES with a dst trailer in __ip6_append_data()

When __ip6_append_data() starts a new skb for a fragment that is not the last one, it adds the dst's trailer_len to datalen. On the paged path pagedlen was computed before that, so with an xfrm dst

	copy = datalen - transhdrlen - fraggap - pagedlen;

is trailer_len instead of 0. getfrag() copies those bytes from the message iterator, but the MSG_SPLICE_PAGES branch right after it also runs when getfrag() succeeds and resets copy to 0, so length is not reduced by the bytes just copied. On the next pass the splice branch finds copy larger than what is left in the iterator, warns and returns -EIO, so sendfile() of a UDPv6 datagram that needs fragmentation over an xfrm tunnel fails:

  WARNING: net/ipv6/ip6_output.c:1796 at __ip6_append_data+0x17ed/0x4b70
  RIP: 0010:__ip6_append_data (net/ipv6/ip6_output.c:1796)
  Call Trace:
   <TASK>
   ip6_make_skb (net/ipv6/ip6_output.c:2097)
   udpv6_sendmsg (net/ipv6/udp.c:1717)
   sock_sendmsg (net/socket.c:841)
   splice_to_socket (fs/splice.c:811)
   direct_splice_actor (fs/splice.c:863 fs/splice.c:1114)
   splice_direct_to_actor (fs/splice.c:1023)
   do_splice_direct (fs/splice.c:1157 fs/splice.c:1183)
   do_sendfile (fs/read_write.c:1351)

IPv4 is not affected: __ip_append_data() does not add trailer_len to datalen.

The branch was added by commit ce650a166335 ("udp6: Fix __ip6_append_data()'s handling of MSG_SPLICE_PAGES"), when copy could be negative on this path. Since commit 736b380e28d0 ("ipv6: account for fraggap on the paged allocation path") a negative copy returns -EINVAL before this point, so remove the branch.

Fixes ce650a166335 ("udp6: Fix __ip6_append_data()'s handling of MSG_SPLICE_PAGES")
---
 net/ipv6/ip6_output.c | 2 --
 1 file changed, 2 deletions(-)
net/ipv6/ip6_output.c +0 -2
index cb648c839431..5887e537f662 100644
@@ -1742,8 +1742,6 @@ static int __ip6_append_data(struct sock *sk,
 				err = -EFAULT;
 				kfree_skb(skb);
 				goto error;
-			} else if (flags & MSG_SPLICE_PAGES) {
-				copy = 0;
 			}
 
 			offset += copy;
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#2 lore raw
Quoted 30 lines · Kyuwon Cho

When __ip6_append_data() starts a new skb for a fragment that is not the last one, it adds the dst's trailer_len to datalen. On the paged path pagedlen was computed before that, so with an xfrm dst

	copy = datalen - transhdrlen - fraggap - pagedlen;

is trailer_len instead of 0. getfrag() copies those bytes from the message iterator, but the MSG_SPLICE_PAGES branch right after it also runs when getfrag() succeeds and resets copy to 0, so length is not reduced by the bytes just copied. On the next pass the splice branch finds copy larger than what is left in the iterator, warns and returns -EIO, so sendfile() of a UDPv6 datagram that needs fragmentation over an xfrm tunnel fails:

  WARNING: net/ipv6/ip6_output.c:1796 at __ip6_append_data+0x17ed/0x4b70
  RIP: 0010:__ip6_append_data (net/ipv6/ip6_output.c:1796)
  Call Trace:
   <TASK>
   ip6_make_skb (net/ipv6/ip6_output.c:2097)
   udpv6_sendmsg (net/ipv6/udp.c:1717)
   sock_sendmsg (net/socket.c:841)
   splice_to_socket (fs/splice.c:811)
   direct_splice_actor (fs/splice.c:863 fs/splice.c:1114)
   splice_direct_to_actor (fs/splice.c:1023)
   do_splice_direct (fs/splice.c:1157 fs/splice.c:1183)
   do_sendfile (fs/read_write.c:1351)

IPv4 is not affected: __ip_append_data() does not add trailer_len to datalen.

Quoted 8 lines

The branch was added by commit ce650a166335 ("udp6: Fix __ip6_append_data()'s handling of MSG_SPLICE_PAGES"), when copy could be negative on this path. Since commit 736b380e28d0 ("ipv6: account for fraggap on the paged allocation path") a negative copy returns -EINVAL before this point, so remove the branch.

Fixes ce650a166335 ("udp6: Fix __ip6_append_data()'s handling of MSG_SPLICE_PAGES")
#3 lore raw
In reply to Kyuwon Cho
Quoted 27 lines · Kyuwon Cho

When __ip6_append_data() starts a new skb for a fragment that is not the last one, it adds the dst's trailer_len to datalen. On the paged path pagedlen was computed before that, so with an xfrm dst

	copy = datalen - transhdrlen - fraggap - pagedlen;

is trailer_len instead of 0. getfrag() copies those bytes from the message iterator, but the MSG_SPLICE_PAGES branch right after it also runs when getfrag() succeeds and resets copy to 0, so length is not reduced by the bytes just copied. On the next pass the splice branch finds copy larger than what is left in the iterator, warns and returns -EIO, so sendfile() of a UDPv6 datagram that needs fragmentation over an xfrm tunnel fails:

   WARNING: net/ipv6/ip6_output.c:1796 at __ip6_append_data+0x17ed/0x4b70
   RIP: 0010:__ip6_append_data (net/ipv6/ip6_output.c:1796)
   Call Trace:
    <TASK>
    ip6_make_skb (net/ipv6/ip6_output.c:2097)
    udpv6_sendmsg (net/ipv6/udp.c:1717)
    sock_sendmsg (net/socket.c:841)
    splice_to_socket (fs/splice.c:811)
    direct_splice_actor (fs/splice.c:863 fs/splice.c:1114)
    splice_direct_to_actor (fs/splice.c:1023)
    do_splice_direct (fs/splice.c:1157 fs/splice.c:1183)
    do_sendfile (fs/read_write.c:1351)
Quoted 2 lines

IPv4 is not affected: __ip_append_data() does not add trailer_len to datalen.

Dropping this broken else-if is definitely right, will apply.

But it leaves behind why copy is rt->dst.trailer_len on the paged path in the first place.

Matching IPv4's __ip_append_data() (keep datalen = maxfraglen - fragheaderlen, add rt->dst.trailer_len to alloc_extra only when datalen == length + fraggap, and drop the later datalen += rt->dst.trailer_len) keeps non-paged allocations the same while making copy == 0 on the paged path. Could make a useful net-next follow-up.

For non-last fragments, __ip6_append_data() subtracts rt->dst.trailer_len from datalen, computes pagedlen from that smaller value, adds rt->dst.trailer_len to alloc_extra, and then adds rt->dst.trailer_len back to datalen. Because pagedlen is computed in the middle of that subtract-and-add, copy ends up as rt->dst.trailer_len instead of 0. That leaves two issues on the paged path:

1. Every non-last XFRM fragment under MSG_SPLICE_PAGES (and transport-mode MSG_ZEROCOPY) still copies trailer_len bytes into the linear skb head instead of splicing them, and shifts the spliced pages to an odd offset (ESP6 trailer_len is always odd).

2. If large non-fragmentable IPv6 extension headers leave less than transhdrlen + fraggap + trailer_len bytes of payload room per fragment (e.g. MTU 1280 with 1208 bytes of extension headers and 33-byte ESP trailer_len), pagedlen underflows (unsigned int) while copy wraps back to +trailer_len. skb_put() then exceeds maxfraglen, and sendfile() fails
with
-EFAULT when fewer than trailer_len bytes remain in the iterator, even though a normal send() of the same datagram succeeds.

Quoted 27 lines

The branch was added by commit ce650a166335 ("udp6: Fix __ip6_append_data()'s handling of MSG_SPLICE_PAGES"), when copy could be negative on this path. Since commit 736b380e28d0 ("ipv6: account for fraggap on the paged allocation path") a negative copy returns -EINVAL before this point, so remove the branch.

Fixes ce650a166335 ("udp6: Fix __ip6_append_data()'s handling of MSG_SPLICE_PAGES")
---
  net/ipv6/ip6_output.c | 2 --
  1 file changed, 2 deletions(-)
net/ipv6/ip6_output.c +0 -3
index cb648c839431..5887e537f662 100644
@@ -1742,8 +1742,6 @@ static int __ip6_append_data(struct sock *sk,
  				err = -EFAULT;
  				kfree_skb(skb);
  				goto error;
-			} else if (flags & MSG_SPLICE_PAGES) {
-				copy = 0;
  			}
 
  			offset += copy;
--

2.43.0

#4 lore raw
In reply to Kyuwon Cho
This patch was applied to netdev/net.git (main) by Willem de Bruijn <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Willem de Bruijn <[email protected]>:

Quoted 8 lines · On Sun, 22 Nov 2026 19:24:06 +0900 you wrote:

sendfile() of a UDPv6 datagram that needs fragmentation over an xfrm tunnel hits a WARN_ON_ONCE() in __ip6_append_data() and fails with EIO. The patch removes the MSG_SPLICE_PAGES branch that causes it, as proposed in the report; Ido asked for it to be sent as a patch.

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

[...]

Here is the summary with links:
- [net,1/1] ipv6: fix MSG_SPLICE_PAGES with a dst trailer in __ip6_append_data()

    https://git.kernel.org/netdev/net/c/fad0d57b12f6

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html