Article View: linux.kernel.netdev
Article #20942[PATCH net v3] tcp: fix negative sk_forward_alloc after MSG_ZEROCOPY append
From: Jiayuan Chen
Date: Mon, 23 Nov 2026 12:24
Date: Mon, 23 Nov 2026 12:24
85 lines
11222 bytes
11222 bytes
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>
---
v2: https://lore.kernel.org/netdev/20261120094605.46063-1-jiayuan.chen@linux.dev/
v1: https://lore.kernel.org/netdev/20261119090828.343748-1-jiayuan.chen@linux.dev/
Changes in v3:
- Call sk_forced_mem_schedule() before the error checks
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..79b85035bf45 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -1352,6 +1352,8 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
err = skb_zerocopy_iter_stream(sk, skb, msg, copy, uarg,
binding);
+ if (!skb_zcopy_pure(skb))
+ sk_forced_mem_schedule(sk, 0);
if (err == -EMSGSIZE || err == -EEXIST) {
tcp_mark_push(tp, skb);
goto new_segment;
--
2.43.0
Technical Details
Message-ID:
<20261123122432.297135-1-jiayuan.chen@linux.dev>Path:
mbox-mo1.pugleaf.net!srv.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-369315-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.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-369315-linux-kernel-netdev=dewy.ru From: jiayuan.chen@linux.dev (Jiayuan Chen) Newsgroups: linux.kernel.netdev Subject: [PATCH net v3] tcp: fix negative sk_forward_alloc after MSG_ZEROCOPY append Date: Mon, 23 Nov 2026 20:24:31 +0800 Organization: Usenet Network Message-ID: <20261123122432.297135-1-jiayuan.chen@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="3872445"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:Y72oAQcOZYnSTMlp/TZWWx2sNaA= sha256:WE7WtEgjJVqdwOv9vXdEsyuYCfoorqnSpNuyNlK18zQ= sha1:bsJXeD/RzQ+eFT+x7G/J1Cw8u4Y= sha256:ufzvAmCev2A7Is2UxFQNTgie/XalCVd4g7PtrssPdMI= 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 ED6A8125DA6; Mon, 23 Nov 2026 15:25:09 +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 ESyhedIy7Q1k; Mon, 23 Nov 2026 15:25:01 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-369315-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 E3AEA125DA8; Mon, 23 Nov 2026 15:24:50 +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 5D54B25076; Mon, 23 Nov 2026 12:24:46 +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=1795436685; b=Of+b3iw6jRDPz29pPrJY1Rr+3lblTaE9LRoCghxlNMc7tE7Vr4Gp6JgfyQr3oCodzTg8 SxUkQGH/gU/Ke042F2ijWiTmGsbr4ts93SN95U/8/4MEjZ5j78A2Z+5O5ubhhs7mBjrM4 g2RqgCe3yBBmc3mulf49KsF8Gw0tsxtc0oYD8HZVT3K5Gt8SQt2P3RpU4M/O8LU+7+xnC l70ub/6K7vD+as0OQywdh0gS3LQqi9peR42slvlI/Cq6qmTzjSdnvwTdQQmqN/cWnM231 trXVX+jOcKnsC8MW5Gp1KFjLSl7thP20vpQxoJaENJgoj2XFVUtylzxannoYis9y+aQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795436685; h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature: X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc: Subject:Date:Message-ID:X-Mailer:X-Mailing-List:List-Id:List-Post: List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence: MIME-Version:Content-Transfer-Encoding; bh=z2ZqcAzvn8rftSdz5CTFszuPMfE/mGAN+/UBYcUwPrE=; b=T7EtonsLMe3lpw8ifm5uNDwc5P2t8k73Jk7/ooajgD9OCLTHmmGUkqdylobCALRJMLKJ rAQfPVi0Y3gnYMA14F5RKpAewxOLMKhwA4jlOjN0jHO8AIgKHFk5TUk4RkKgXo5PYOX/W S0kF09ePnNBQ7m1qFsQOaeLkkCptsvlp34QZ5msihqv0M7d5IUySmpoD2WN7cw8MXJgn9 uizvzWH9u5NDNxcaj282q2Nz30Q/1QUzEFcGA5m7rebKgDqgLv7qPYhkFM+IOnZi1MIH+ aU/RoRHJhRzpcUMrsXlhyeYHroCVFKOYaiiOSybhuXX+SDbVuEfdBYki9cKJ//s7+lw== 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=wu3K2n5x; 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 C6982606A331; Mon, 23 Nov 2026 12:24:45 +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=wu3K2n5x X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.103 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795436685; b=xs6sR7jlKJXNyzSlXcdI85dI0SYYiR/DogM67y3GRa2v+tfhNK3u1bP6pWnl/WLth/AV fplxoCFdEqSX+hcyd7iE4lb4DKdVBnmoCfB6ht2ugKJy6DQ4K4cGPipLLWeD/BwgYixdV 3FFfji5XuC1jvx2lbTHAoHdZWIt9bhoUrUwT3zNh9dJF0vzI5hzb/Cm+TJyyEAGaKTXdI Luwh1tVzGLMyku3XyH3oWlmEG0jKj1xF6bSPhENILbf95qTcIbGYiHbck/e1lfGso9ZgE 5FBbXmhSxUCcqk5yv5nWMqq9LabZM9fkHpblxQIwCX5ChepmSbfEcxSSM2VC34+XNjQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795436685; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=z2ZqcAzvn8rftSdz5CTFszuPMfE/mGAN+/UBYcUwPrE=; b=2T5qzinkpn+OQv2wWA7LkeoqcFKZIEo8Ud3RBhKVvjj/oBDM4xHzbBycTaubwM1V7vuR XFOhv7suANuLbQB1VaBGhbTDqJBFfy+UUrx2ZWwTsyQClDuSVERDzY9EjV8P0XPUuSTbn 7Avu3otTQmR29dww+hdTazOfkGvQ6i7FqNGW5Icr1rF+edtwWtfCwFoPMxm3Mf5kTRb0h ncVVCM8Onh5Xo0k0MD1mAZ62X2CbkBr7LxTFEQTWComHBin3bAf98YZ5zEGS2F2Kt5ppF lVca8WA22C7uhP7nDZxPwxTAfNeFNFvnAcXdoE04/iEe04q5ZCZzKzcXdtrv1dVWuKg== 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=wu3K2n5x; arc=none smtp.remote-ip=95.215.58.103 X-Received: from mta1.migadu.com (out-103.mta1.migadu.com [95.215.58.103]) (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 502DB606A31A for <netdev@vger.kernel.org>; Mon, 23 Nov 2026 12:24:43 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 502DB606A31A 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=8Q1SjcwepZqcgCq92WDlIH0YSR9zqzm2uSjkwhu8qA8=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1795436682; v=1; x=1796041482; b=wu3K2n5x1EoCo7UGeAlIBRwvkmXp/8LZtB5hdm44gtIKdPhbEw2TqYQ2RjRfETkRBZ4B7knZ xOcQ6RCrcqvW8GvMsQm5jzVtEeqmyHdULLGc7gZUrYewav6jKGNj9WjpnvkttBshNMaNpsT0NDJ iEj0ySByYwUVCAU+Ag1kx6gg= X-Envelope-To: netdev@vger.kernel.org X-Received: by smtp.migadu.com with ESMTPS id c2fabbd8dfc1efd4; Mon, 23 Nov 2026 12:24:42 +0000 X-Mizu-Trace-ID: c2fabbd8dfc1efd4 X-Migadu-Flow: FLOW_OUT X-Cc: Jiayuan Chen <jiayuan.chen@linux.dev>, 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>, Wei Wang <weiwan@google.com>, Shakeel Butt <shakeel.butt@linux.dev>, Soheil Hassas Yeganeh <soheil@google.com>, linux-kernel@vger.kernel.org X-Mailer: git-send-email 2.43.0 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