From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.219.70 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795974719; b=ovTAvB7zj418vIfoGHYu4rDk+0m9qg8uMIDGollgykS2bit9j3EFCjVawRpEnW8Y2vR9 JyskHgzXW0ncJh7FCvv/fs4hSu2RJvfXi1N2VGzJyVHjKyZYVh5kuZKk14kSJjUDh7d8z xLN50qn2dVWl7ws7YW4KkH1HjmwXeXw6wW0VhNehsnplFB20PNaVRZVxawSkKhfeW11bM gS6WOxiUH5xD9W9gNlTvsNIdtHR4qlmlhnLE2eCzI/9F/LtUZWM6k4jowHY1uEZoreVXy h1xmmmE2L2bhutys1njYOLbeE1DMiRrZTvurjlbL84kxM76PZqeWmhDQ1BwKcYch4Qg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795974719; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:Message-ID:Subject:From:To:Cc:Content-Type; bh=H6uN1lBfYuvnUlmCFk9eDh0778fX6PdqHQkzuuaP2yk=; b=Ifc/QUt4hq5MxN/X19DgiaLLJf9SSmosv8pj+EIGMpLNwijBcm0KrZ5ldQvJjMFhSEb3 gNMoH7gvKNbYaeke1P5dicbMGef56QXZShlkyViEF4Grm2JjVpiVWmR3CCE6/pVb6rEAp pECsFWy0O4xr8x2nUTk21XB8ro2TRD83VTEbeQBmn8iA4/BHwlYN7xEYsaEBt8uRMcuf+ x1vIdq37730sKKy3E+aio472umzF0PYYSEzYCVNlBxTJInjIGs5vqCUpG9aenRJL0dMaU GN091MQZp7jFWVOeNK7k9vIa0b4cky3oYjEInFWe2Ya0LYyzyZebce43qrp5cbbKpGA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--willemb.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=StQkv48X; arc=none smtp.remote-ip=209.85.219.70 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDEE4606A31C for ; Sun, 29 Nov 2026 17:51:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DDEE4606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--willemb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=StQkv48X Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-9213659143bso118574046d6.0 for ; Sun, 29 Nov 2026 09:51:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1795974718; x=1796579518; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=H6uN1lBfYuvnUlmCFk9eDh0778fX6PdqHQkzuuaP2yk=; b=StQkv48XsygWLjZ2x5T5fs5g1bpbrr6glfgQTg/6IyyuTHfDAH9ph8WPoJoyYPlim+ cYV0R0jTYjLN28TGHYrdAFl1L5Q3kLO17IazdtfgIhuwfPlsT/6RgvFFDZG0iTwbvesj 1I0dCOJNeayg8EVxFGhYc/a0VHYuWYOMsylLI66mXGGvkXl3SEd6h7HrMEuS2f7qpf8w i0Du5nMvR0lIFjxO8XYwiMEpptgDuEAbmNl61AWayQU0wc6/7q2X7PdNnD/0/oywj+So 1tvgT8ORfYstauKXgObgDlad5kenOkyaslG7+F6Is6Lr8pLC4rxZOCTNH2HGpH5LzuHY 2Pzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795974718; x=1796579518; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=H6uN1lBfYuvnUlmCFk9eDh0778fX6PdqHQkzuuaP2yk=; b=K5x9Jlio2iGbFT7HXVZzjgIdQbZDbrvR8lVWMZ78IscKAZBu1rICtTmft9SdINumER sYz6hAce2LgWluuhQqpMzrCraVX/DdDycZxCnue6OU5hT4Pj/X3MqgzRty8pjuGLZRxA KT7OgYfl01hWEP/3faKrxVwFjbXhTwNeKgxxypF+y1pLit8PvNB6bPApIIdRU3dwPH9L lzldoMccutosevxzfZ0jXMALcivncrRrRm9LnKwqiaie7H1kpBXbeujNK4xAT05GoCG2 SB+XOlTNTbu8v8QYup2vQwqBvWjYNc3whwmX4g5rFAKaDytZQAvQ7gLAJ0jEiX7tjbcN ZxoA== X-Forwarded-Encrypted: i=1; AL+hErHNvDIZAXavlLiz0xv2RNGC0uSIzDVDrWzErlzZdoMdWMjZYZ5eiuLqJ5DaFXRZx+7nOS09flg=@vger.kernel.org X-Gm-Message-State: APuU4Z+esJ/rzFMU6uA6q2UVnk3aR2fXrPGZ6b6tR4b26eRCdMNDxd54 kyOKNbYiUXGeQI8ivxfHwG1V4C5AcvsMWp8B54bnPbpIQd1PyKB+Ze0Pcx39WR6LlU/X6Ihcv8V V5s9s9Q8GDQ== X-Received: from qvrp8.prod.google.com ([2002:a0c:fd88:0:b0:921:34f1:e659]) (user=willemb job=prod-delivery.src-stubby-dispatcher) by 2002:ad4:4eaf:0:b0:921:1e23:3e9c with SMTP id 6a1803df08f44-92134a3730emr572119596d6.18.1795974717567; Sun, 29 Nov 2026 09:51:57 -0800 (PST) Date: Sun, 29 Nov 2026 12:51:56 -0500 In-Reply-To: <179534083350.2499182.16621119046570934510@gmail.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <179534083350.2499182.16169984227830330896@gmail.com> <179534083350.2499182.16621119046570934510@gmail.com> Message-ID: Subject: Re: [PATCH net 1/1] ipv6: fix MSG_SPLICE_PAGES with a dst trailer in __ip6_append_data() From: willemb@google.com To: Kyuwon Cho , David Ahern , Ido Schimmel Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman , David Howells , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8"; format=flowed; delsp=yes Kyuwon Cho wrote: > 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: > > 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. 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. > 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") > Signed-off-by: Kyuwon Cho > --- > net/ipv6/ip6_output.c | 2 -- > 1 file changed, 2 deletions(-) > diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c > index cb648c839431..5887e537f662 100644 > --- a/net/ipv6/ip6_output.c > +++ b/net/ipv6/ip6_output.c > @@ -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