🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #19741

Re: [PATCH net v2] tcp: fix negative sk_forward_alloc after MSG_ZEROCOPY append

#19741
From: Jiayuan Chen
Date: Fri, 20 Nov 2026 10:09
88 lines
11694 bytes

On 11/20/26 5:46 PM, Jiayuan Chen wrote:
> Our local syzbot reported the following warning:
> 
>   WARNING: ./include/linux/ucopysize.h:57 at tcp_sendmsg_locked+0x1e13/0x1f20
>   Modules linked in:
>   CPU: 3 UID: 0 PID: 377 Comm: syz.2.2248 Not tainted 7.4.0-rc2+ #398 PREEMPT
>   RIP: 0010:tcp_sendmsg_locked+0x1e13/0x1f20
>   Call Trace:
>    <TASK>
>    tcp_sendmsg+0x2c/0x50
>    inet_sendmsg+0x62/0xb0
>    __sys_sendto+0x2fe/0x350
>    __x64_sys_sendto+0x7f/0xb0
>    x64_sys_call+0x1375/0x27e0
>    do_syscall_64+0xe4/0x470
>    entry_SYSCALL_64_after_hwframe+0x76/0x7e
>    </TASK>
> 
> The problem is here:
> 
>   if (!skb_zcopy_pure(skb)) {
>           copy = tcp_wmem_schedule(sk, copy);
>           if (!copy)
>                   goto wait_for_space;
>   }
> 
> When MSG_ZEROCOPY data is appended to a skb that already holds copied
> data, only the user length is scheduled, but the pinned pages are then
> charged by their truesize:
> 
>  skb_zerocopy_iter_stream
>    __zerocopy_sg_from_iter
>     zerocopy_fill_skb_from_iter  //truesize += PAGE_ALIGN(copied + start)
>     sk_mem_charge(sk, truesize)  //sk_forward_alloc goes negative
> 
> For example, sending 8 iovecs of 1 byte each schedules 8 bytes and
> charges 32768 with 4K pages.
> 
> On a later sendmsg() without MSG_ZEROCOPY, if sk_wmem_schedule() fails
> (e.g. tcp_mem hard limit is reached), tcp_wmem_schedule() returns
> min(copy, sk->sk_forward_alloc), which is negative. The negative copy
> is passed to skb_copy_to_page_nocache() and triggers the warning, and
> sendmsg() fails with -EFAULT.
> 
> A few options were considered:
> 
> 1) Schedule the truesize up front. It is not known before the pages
>    are pinned, it depends on the iovec layout.
> 2) Do not append zerocopy data to a non pure skb. This splits a small
>    header and its zerocopy payload into two skbs.
> 3) Schedule the missing part right after the pages are charged. They
>    are already in the skb at this point, so this can not fail.
> 
> Go with 3).
> 
> Fixes: 849b425cd091 ("tcp: fix possible freeze in tx path under memory pressure")
> Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
> ---
> v1: https://lore.kernel.org/netdev/20261119090828.343748-1-jiayuan.chen@linux.dev/
> 
> Changes in v2:
> - Only call sk_forced_mem_schedule() for non pure zerocopy skbs (Eric)
> ---
>  net/ipv4/tcp.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index d510e982dcea..343f6d61b408 100644
> --- a/net/ipv4/tcp.c
> +++ b/net/ipv4/tcp.c
> @@ -1359,6 +1359,8 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
>  			if (err < 0)
>  				goto do_error;
>  			copy = err;
> +			if (!skb_zcopy_pure(skb))
> +				sk_forced_mem_schedule(sk, 0);


I think I should move such code before the 'if (err < 0)', like the sashiko said:

https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119090828.343748-1-jiayuan.chen%40linux.dev

>  		} else if (zc == MSG_SPLICE_PAGES) {
>  			/* Splice in data if we can; copy if we can't. */
>  			if (tcp_downgrade_zcopy_pure(sk, skb))
Technical Details
Message-ID: <4198a993-1c7c-4ca5-8d31-8f8e36778702@linux.dev>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367844-linux-kernel-netdev=dewy.ru
References: <20261120094605.46063-1-jiayuan.chen@linux.dev>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367844-linux-kernel-netdev=dewy.ru
From: jiayuan.chen@linux.dev (Jiayuan Chen)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v2] tcp: fix negative sk_forward_alloc after
 MSG_ZEROCOPY append
Date: Fri, 20 Nov 2026 18:09:09 +0800
Organization: Usenet Network
Message-ID: <4198a993-1c7c-4ca5-8d31-8f8e36778702@linux.dev>
References: <20261120094605.46063-1-jiayuan.chen@linux.dev>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="3129676"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:t9/7dbV0kdlD+FpQp9jaoMlJdrY= sha256:hNzTK2NGn9GN5peGV2f+gkTyM+9uiQAUzWN0ZbTTgJA=
	sha1:/yZyG0qph6j/UnD5mZG4HjYWdKE= sha256:nIyt4aH2qMml2cQ0MYVjuRij/M4KiWFsfDCyeBRshho=
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 F26C8115944; Fri, 20 Nov 2026 13:10:06 +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 lR1wB7SNi3FT;
	Fri, 20 Nov 2026 13:10:02 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-367844-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 sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id 7C1AA11593A; Fri, 20 Nov 2026 13:09:53 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id A6F582F9E1; Fri, 20 Nov 2026 10:09:34 +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=1795169362;
	b=OJLRL4tNlbf2RirAUOIKw82udTPPmkqjezi0iMUc+LLE+q5t+CmFIIzRLvikcMETeVXD
	 bvJBtmYo/TNbJxFoS1HiAIxbvMW9Ln1dURzbhmU/88k8r9IU9mlL9wtkP8NSBkmS/hzjp
	 L1+b2Y0vWqDM/GLnfxvVVyYWYRzyJ4zkPk9quHsYu7JtPro5gMJ4y6K35bfq0YcmCiPhs
	 5oRIYpYao4O2j+pTbVnREBBBIkiezJ2ucUo4BZBGDFK0U+qjduymev3zdIUnDoPz/T9IA
	 SQ4v/egfuaAWxDrKeO509Zgywr5EmzN5L9d7L3+zKFiSAsf4twc2NVa5viq6ycyAnJA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795169362;
	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=8l1rxUVHALrLazVSWALlznjCgIYdHTWqcToTvFjFBKg=;
	b=4NLE332ucITb33/9PS5x2aUMvu+DulrHm8yVUJ3PXPQxAeHzlFPnccLNdASUmykabiMF
	 dr0Qy4D7Iod1upm4MDWkqFhWOaLwielWNxHpzirEL5AisaFv/YDasdSu2AS6EojXon9ey
	 e0E0QR9vH+Wjj67hvqYk9Co0euOUxKVw+Mr2Uvgx252tuxFMvwck3o9Fd0VnWqnWPvA7O
	 xz9KtrDPT60PhAtmUZmFZlIM7soORs8PrOrlgDfBG4QJk2p3MFFD6hkuiGVr6K/WsR5IC
	 0zznAhKjjPoNsLDHFdVbz3b64Qv4m+PUk1fw0vHnJNwe5CCI6NZFPqMVkK0AVl5l8ZQ==
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="KK4/wbl6";
	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 9CEA260A261C;
	Fri, 20 Nov 2026 10:09:22 +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=KK4/wbl6
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.145
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795169361;
	b=zGiqGGY46OtgV5k6PhVuWNi/HJIZURm+F8cAlK8nzrjvDXOqF/0S6CkrUm4UUYgHui3i
	 Th5PbfWNMi6ylm5TZ4XofpRLo0gXoZNVlETAofORKl5WQig7t/BiDEULDqbMKzF0zTRxe
	 MGVvL88h6J+n6pF8gOyrxLPvfqZBf6vU6XFjYD/FIk2+By38aCZDh0qQIfbHbcb/d/31N
	 Va3mv9UrdpFlDjmea5DgVYeoFAVcojA41XQW/m1yJGVqJHDQEeLZEnFgf94pwbf86c5i1
	 52ateI7N0EvnSN6YOwUYLJ0Ui1tngOb4I7gEk9HDSiCnEWgEF5ObujjD3y9wPOXlcog==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795169361;
	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=8l1rxUVHALrLazVSWALlznjCgIYdHTWqcToTvFjFBKg=;
	b=yGPIW1wP0O0mVWq3la99oFmNugVFUVeFAmeLIDelBRd53eyjhPeyU/Xp0RDY4jvYsM/K
	 StMMgXIZiQK6mAUpTsh9/Lbw+tXlJpRUUBAEyIiejeD2dGI/fKn5htBJ8bCl6rejEb0LK
	 Cm4tbri/2GDI3HPqWzTF6afTkffygU7tx/Kr6nkXfkr/sqculjZviNhUusaryFJd41pvN
	 4E+PML6NqWd521g+U1xlaAgvN5T0hu8sXPnIA8bJFxd9DyUm/pn5brZaU5SItmoe72atu
	 lhTYG1Jw4zUyHYduybnUmKL4Y1R/y6tSBLodOtwOAfLCOFV03a+LGRrDVV3UFG+JYIQ==
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="KK4/wbl6";
	arc=none smtp.remote-ip=91.218.175.145
X-Received: from mta0.migadu.com (out-145.mta0.migadu.com [91.218.175.145])
	(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 2E1DF606A334
	for <netdev@vger.kernel.org>; Fri, 20 Nov 2026 10:09:20 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2E1DF606A334
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=lmupTUCv65fg5pP75anIseOQtkdlOKkZnDml59Hx+vg=;
 c=simple/simple; d=linux.dev;
 h=from:to:subject:date:message-id:mime-version:content-type; s=key1;
 t=1795169359; v=1; x=1795774159;
 b=KK4/wbl619CRE9joqmaw8LIvKdOKg2jk4pyiVIF4hVznoWuyV3N6otfaoXWUnWgbBhC6H2rj
 QAV0ijBAhkGuwRWbSwbaVe4Et5hMFScAWdZATXbMESpD6ibOrOzRRufWfOb8Gbmq+aOep6XNsbd
 QDMcI1kaejZZPt53EQ3B6JTM=
X-Envelope-To: netdev@vger.kernel.org
X-Received: by smtp.migadu.com with ESMTPS id 3039bbd6bb4976e6;
	Fri, 20 Nov 2026 10:09:19 +0000
X-Mizu-Trace-ID: 3039bbd6bb4976e6
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: Eric Dumazet <edumazet@kernel.org>, Neal Cardwell <ncardwell@google.com>,
 Kuniyuki Iwashima <kuniyu@google.com>, "David S. Miller"
 <davem@davemloft.net>, Jakub Kicinski <kuba@kernel.org>,
 Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
 Soheil Hassas Yeganeh <soheil@google.com>,
 Shakeel Butt <shakeel.butt@linux.dev>, Wei Wang <weiwan@google.com>,
 linux-kernel@vger.kernel.org
X-In-Reply-To: <20261120094605.46063-1-jiayuan.chen@linux.dev>