Article View: linux.kernel.netdev
Article #20007Re: [PATCH bpf v2] net: skmsg: fix copy cursor when coalescing clones
From: Jiayuan Chen
Date: Fri, 20 Nov 2026 22:50
Date: Fri, 20 Nov 2026 22:50
77 lines
11015 bytes
11015 bytes
On 11/21/26 5:45 AM, Kyle Zeng wrote:
> A splice or zero-copy append can leave the destination copy cursor at
> sg.end. If sk_msg_clone() subsequently coalesces with the last entry,
> sg.end does not advance and the cursor still points at an unused slot.
> sk_msg_memcopy_from_iter() can then walk around the ring and write into
> older entries, including file pages spliced from a read-only descriptor.
>
> Software TLS can reach this with an ordinary MSG_MORE send after a file
> splice and a splice from another TCP socket. Both TCP and the TLS
> encrypted-message allocation can use the sending task's page fragment,
> so the TCP-sourced plaintext can be contiguous with the next cloned
> encrypted-message range.
>
> When coalescing with an exhausted destination, move the copy cursor to
> the tail and set copybreak to its old length before extending it. Find
> the actual tail on each iteration using the ring iterator, including
> when end wraps to zero. Leave an existing copy cursor unchanged and
> preserve the normal coalescing, reference counting, and memory charging.
>
> The issue was found by an LLM.
>
> Fixes: fda497e5f5b8 ("Optimize sk_msg_clone() by data merge to end dst sg entry")
> Cc: stable@vger.kernel.org
> Signed-off-by: Kyle Zeng <kylebot@openai.com>
Hi Kyle, I also received same issue from somewhere, but I think we should fix the root cause(TLS).
I have a fix patch and will send it shortly.
> ---
> v2:
> - Rebase onto the BPF fixes tree; no code changes.
>
> v1: https://lore.kernel.org/bpf/20261030042138.73739-1-kylebot@openai.com/
>
> I have a reproducer for this issue and can share via DM
>
> net/core/skmsg.c | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/net/core/skmsg.c b/net/core/skmsg.c
> index 8a3b8536c0c2..f47c59ba1ec6 100644
> --- a/net/core/skmsg.c
> +++ b/net/core/skmsg.c
> @@ -103,16 +103,26 @@ int sk_msg_clone(struct sock *sk, struct sk_msg *dst, struct sk_msg *src,
> }
>
> while (len) {
> + int last = dst->sg.end;
> +
> sge_len = sge->length - off;
> if (sge_len > len)
> sge_len = len;
>
> - if (dst->sg.end)
> - sgd = sk_msg_elem(dst, dst->sg.end - 1);
> + sgd = NULL;
> + if (dst->sg.size) {
> + sk_msg_iter_var_prev(last);
> + sgd = sk_msg_elem(dst, last);
> + }
>
> if (sgd &&
> (sg_page(sge) == sg_page(sgd)) &&
> (sg_virt(sge) + off == sg_virt(sgd) + sgd->length)) {
> + /* Start copying at the newly cloned suffix. */
> + if (dst->sg.curr == dst->sg.end) {
> + dst->sg.curr = last;
> + dst->sg.copybreak = sgd->length;
> + }
> sgd->length += sge_len;
> dst->sg.size += sge_len;
> } else if (!sk_msg_full(dst)) {
>
> base-commit: d5ba86298b45e1a81c578c499e9a222a3b734d5d
Technical Details
Message-ID:
<bd1ed1fa-2ff2-435c-8e0c-372802eb7187@linux.dev>Path:
mbox-mo1.pugleaf.net!news-sfo.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368196-linux-kernel-netdev=dewy.ruReferences:
<20261120214511.25934-1-kylebot@openai.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-sfo.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368196-linux-kernel-netdev=dewy.ru From: jiayuan.chen@linux.dev (Jiayuan Chen) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH bpf v2] net: skmsg: fix copy cursor when coalescing clones Date: Sat, 21 Nov 2026 06:50:15 +0800 Organization: Usenet Network Message-ID: <bd1ed1fa-2ff2-435c-8e0c-372802eb7187@linux.dev> References: <20261120214511.25934-1-kylebot@openai.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="3284842"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:80TOJMXIpuhHk2fqS7BsJMltIc8= sha256:jnTnZgKiL70knUj0/VCCXh/iw69o/fPcM2deG5SphDo= sha1:Acrpu2/1GMrXTKng3SsCPNpZHnc= sha256:dLXpuC/txUV5NIS7hWkSbZYUCNs+LzvQsD6L7b4DCfc= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id E99D4115ABA; Sat, 21 Nov 2026 01:50:54 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -2.05 X-Spam-Status: No, score=-2.05 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, HK_RANDOM_FROM=1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key) header.d=linux.dev X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Fer1UTWGkW8T; Sat, 21 Nov 2026 01:50:51 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-368196-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id A8C54115AB8; Sat, 21 Nov 2026 01:50:40 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 52B1E2790B; Fri, 20 Nov 2026 22:50:38 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795215036; b=d+h5bTXHbbUthUctm0dp94wTCLP1Yyj44MtuBMyvMGbblBpsZ2LBgtKWGtLwbVm7wbPz h4ffmdoGkbc8s1EM5t/iZU/hXrRHU2zXIHwDgHe35ZEpLKrjXz6SKKV9qzByGICOz+54I ARw7hMmir9IFKLntSWnewTNT4YE3m5DtDcpzX5y0tVw2SBfgOlf8RhfIfM7kOI1PeeJMt Z6oKqfHFFpDfsFy6e5aDV6CiUzBEd+TUC5Uaf8CdIAh27DjrTxd3ZPZ0t8WXN4YDt6Tg3 AIM5cf2vl/xM9iPTKEc31+Vf07NboKqAzE+jRRuj8mj6r601DErkyIJS+EjgmcM+HUg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795215036; h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature: X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date: X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version:User-Agent: Subject:To:Cc:References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=teexMSd8PHdfaM03rUjjEKQ2tL2BcpPqCRX495L4lZM=; b=T6BcxbCNFgb4wklj06umOATXYzvnqnxOyIGP2zhk6EDoOE5Z+7uUMGU2+Cv9L2qo83Ce AOln9S8+5UxSkxltHq18rVXCS4dbgqp01bQJoL7subinPdM77V1AkuynR8oybGcaeumIe QWIzcyZ9j/2Cc5Fc096uqEa1dQqOEVcQ3+Wqqr15CTn16I114y812sllI4UrfS1qnWuJ7 BmruHfsX81mMan4W9uQHcJRxcCv32uoZzkAS07EpE5lHuSjA41yVQ3AZLuMbGRAwzKXni Pablfl3KmwVPg3+LwNDkXSwMoVyJBX4lAOLdXHo5GOsgyd6aHxfv+8ZTzclihjJxZNA== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=EKrcD2EY; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2BF8A606A6B1; Fri, 20 Nov 2026 22:50:36 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=EKrcD2EY X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.102 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795215035; b=AvL//t/4MBFocO05Uxesepv7Ow5Ahcz5WmEy2wsMmLjcH5h2YOHhsUkf2r9n9a8OyUIp Q/d0TAXczOrZjXbBzbtP4nKftDfKVzahhTRCdRACQuHoVJr7ozEPaxD78uYspTAt7WpxF QQfcIhMShEEnbi99M8CUiA/V6/XrgFvBSrSX0QPJixzOt8zIyhzpYfoyJxt+H4PU/DtVW JtpFCdOWsRuWl1EMDc7IpGAbatF9rZI3YKY+PFVnDllcDqkj8X9Q9+SJo/L6vSZu+yFDx YZ7pAm36pPQMZXu5RVBrpdr3N5e9skEuUWAlrMIRNCAiQOgKegNAvDo8l3SU+5g+uww== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795215035; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=teexMSd8PHdfaM03rUjjEKQ2tL2BcpPqCRX495L4lZM=; b=rf+FYlPB6nIi0k9ZB8UufCGcgJ2rhE3JLwAy9w31f5bPnD9zGNg9UZZOoihWoM8utMRV vQ6/AoUGGjG+LA2YEaLfoFPf59TcNsTK3ATNQwMUct5takb7sVsFaoXjOSdYnwQoe2pDV jzTnnT7fB85iM+PmQ9oe3ygakgrAlwvR/DPoeVug8/PjF3TRtkNTUNkDK2L/s/+ifXed1 ED7RtZ0z7w1h5AMm6zmNM5ee8ZXLV84pdrHKO+fudvxcUl1jod9Q8vNayOY29HbZ5i5IQ Ngj9gFrU277ZLUlFbD2p4ZZ8tqpjfMv40NOKCGggpldGg7tuHqVH8eJSoPN9C0cIlSw== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=EKrcD2EY; arc=none smtp.remote-ip=91.218.175.102 X-Received: from mta0.migadu.com (out-102.mta0.migadu.com [91.218.175.102]) (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 2988F606A689 for <netdev@vger.kernel.org>; Fri, 20 Nov 2026 22:50:21 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2988F606A689 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Envelope-To: netdev@vger.kernel.org X-DKIM-Signature: a=rsa-sha256; bh=rYwH//s3ZpyAARSSd1MnfBFwVXfqUmxKvytgZIbg1u8=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1795215020; v=1; x=1795819820; b=EKrcD2EYwrim8wKNjZask/JMVfOilOIWboPZPxjVypk3fDw9G7bE5j12jZooP21W0W+zGV8/ THKr/md0GWRkwVS65SatZiGhtA7PiJKtjvbZmdcbKw6i+jQD4501gVGDv5827tvtdddyHUYeI5+ UQBlL6Hi/9QaN+uA7Hxst2MA= X-Envelope-To: netdev@vger.kernel.org X-Received: by smtp.migadu.com with ESMTPS id 15c7c981e0c8d853; Fri, 20 Nov 2026 22:50:19 +0000 X-Mizu-Trace-ID: 15c7c981e0c8d853 X-Migadu-Flow: FLOW_OUT X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-User-Agent: Mozilla Thunderbird X-Cc: john.fastabend@gmail.com, jakub@cloudflare.com, netdev@vger.kernel.org, alexei.starovoitov@gmail.com, stable@vger.kernel.org X-In-Reply-To: <20261120214511.25934-1-kylebot@openai.com>