Article View: linux.kernel.netdev
Article #19736Re: [PATCH net] tcp: fix negative sk_forward_alloc after MSG_ZEROCOPY append
From: netdev-bot+sashiko
Date: Fri, 20 Nov 2026 09:57
Date: Fri, 20 Nov 2026 09:57
116 lines
12017 bytes
12017 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] The new sk_forced_mem_schedule(sk, 0) only runs on the success
path of skb_zerocopy_iter_stream().
- [Low] In tcp_sendmsg_locked() (net/ipv4/tcp.c), the MSG_ZEROCOPY branch
only pre-schedules memory when the skb is not pure: `if…
--
tcp: fix negative sk_forward_alloc after MSG_ZEROCOPY append
The MSG_ZEROCOPY path in tcp_sendmsg_locked() can append to a skb that
already holds copied data. In that case only the user length is
scheduled, but the pinned pages are charged by truesize. This commit adds
sk_forced_mem_schedule(sk, 0) after a successful skb_zerocopy_iter_stream()
so that sk_forward_alloc does not go negative.
> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index 832b25ddd3c2e..9f8c0954001bb 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;
> + /* Pages were charged by truesize, not by copy. */
> + sk_forced_mem_schedule(sk, 0);
[Severity: Medium]
Can sk_forward_alloc still go negative on the error path? The new call
only runs when skb_zerocopy_iter_stream() succeeds, because the
"if (err < 0) goto do_error" check comes first.
In skb_zerocopy_iter_stream(), the truesize charge made by
__zerocopy_sg_from_iter() is undone on -EFAULT only if ___pskb_trim()
succeeds:
net/core/skbuff.c:skb_zerocopy_iter_stream() {
...
if (err == -EFAULT || (err == -EMSGSIZE && skb->len == orig_len)) {
...
if (!___pskb_trim(skb, orig_len)) {
skb->truesize -= delta_truesize;
sk_wmem_queued_add(sk, -delta_truesize);
if (!skb_zcopy_pure(skb))
sk_mem_uncharge(sk, delta_truesize);
}
skb->sk = save_sk;
return err;
}
...
}
___pskb_trim() fails when the skb is cloned and
pskb_expand_head(skb, 0, 0, GFP_ATOMIC) fails.
Suppose the write queue tail skb is not pure, so only copy was scheduled,
and it is cloned. If the user iovec faults after some pages are pinned and
the atomic allocation fails, those pages stay charged by truesize. The
caller then jumps to do_error without running the fix-up.
A later non-zerocopy sendmsg() under tcp_mem pressure would then get a
negative copy back from tcp_wmem_schedule(). That is the same case the
commit message describes.
Would it work to call sk_forced_mem_schedule(sk, 0) right after
skb_zerocopy_iter_stream() returns, before the error checks? On the paths
that do undo the charge, the call would do nothing.
[Severity: Low]
This isn't a bug, but does the new comment hold for pure zerocopy skbs?
Earlier in this branch, the pre-schedule is guarded:
if (!skb_zcopy_pure(skb)) {
copy = tcp_wmem_schedule(sk, copy);
if (!copy)
goto wait_for_space;
}
__zerocopy_sg_from_iter() also skips the charge for pure skbs:
net/core/datagram.c:__zerocopy_sg_from_iter() {
...
sk_wmem_queued_add(sk, truesize);
if (!skb_zcopy_pure(skb))
sk_mem_charge(sk, truesize);
...
}
So when SKBFL_PURE_ZEROCOPY is set, no pages were charged to
sk_forward_alloc. sk_forced_mem_schedule(sk, 0) is still called anyway.
In that case it does nothing, unless sk_forward_alloc is already negative
for some unrelated reason. Then it would force-charge without any warning
and hide that imbalance.
Could the call use the same !skb_zcopy_pure(skb) check as the
pre-schedule? Alternatively, the comment could say it covers the non-pure
case.
> } else if (zc == MSG_SPLICE_PAGES) {
> /* Splice in data if we can; copy if we can't. */
> if (tcp_downgrade_zcopy_pure(sk, skb))
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119090828.343748-1-jiayuan.chen%40linux.dev
Technical Details
Message-ID:
<179516866272.3136.232647069823092530@kernel.org>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-367837-linux-kernel-netdev=dewy.ruReferences:
<20261119090828.343748-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-367837-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net] tcp: fix negative sk_forward_alloc after MSG_ZEROCOPY append Date: Fri, 20 Nov 2026 09:57:42 +0000 Organization: Usenet Network Message-ID: <179516866272.3136.232647069823092530@kernel.org> References: <20261119090828.343748-1-jiayuan.chen@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="3125684"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:oS+U0NUnlQchgKbEc2TFZ+QrbXo= sha256:vAizXkjyZJfR3mK2MM1TMtQNOfvvasdsuL2AG8TU+hw= sha1:z4TfHm1gFy8xDkJYhLPvtEuvbUM= sha256:W2aQDZirpDcRgATBhdq3iSIkkHGrlO2Gtfn9KJHjX9o= 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 1CCFC11593D; Fri, 20 Nov 2026 12:58:01 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.501 X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31 tests=[DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org 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 LtO4CyOGFGcY; Fri, 20 Nov 2026 12:57:56 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-367837-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id CC7BA11593B; Fri, 20 Nov 2026 12:57:48 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id 22A72681B59; Fri, 20 Nov 2026 09:57:48 +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=1795168665; b=hjyAm2RtMUmrkqDHkM2E63xN/rqF5//xXAkRJCRse0u+ScnzoPFBJAPVYRo7oW8CHsvj z/yjdbDofCbrqOFK/ZdX2KqPvN3iCcE4l2NgrwJnGYOyYX+fJIvdqFUFwLqhhlWGdQkp8 fHUKdniYvt5WgqVTc7Xr1f8u7puFhVDZZb7ewkAS1JVmzkHdE9j1nKibgC2LT0RymrbRs 97mjmRb1Dqp/b2Me8WkmIVU8ROu5Dxwc1+mXxc07pblCPu8u1Slioz+G42Ag0TqpDggeB zGYMG11CeojcG0fKwkaS9VfU+vDT7mp+xLpAQx7RNO0sHb62WUpNxnYgKfQ4hTtqJbg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795168665; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=US+BwjsBu2YGs4iPWGc7Xdq/wpYAMCQoXR2jUtQoE6E=; b=hHu4v58wmTakMKjdMhqawyRscBTirrFN6vGcUez7K0HjCyHBDIG7fMhwDE7bYLjUj6xS dFqsCzEe5hzxdZOxE7uZ18yTsDMTggJ1IsygQPsOJbDC4FQWSw9FAP0zWOcKeK9xS2yzu yqTtYedIwWf94FF1Hjm8Hm/6qzPmcfluMkvybMFu+8zABROQ6g6jm/MDlgO3QzI2suyEh YvTkHr1J7JqEtLsbOdMgSID61irC6oK/cGKB9ty1fo80Yl6WKhQssDlIy+KGkvEvTRxBg 6kM2QR3WzXq1l9LnTxCA6f4zooI4Ma/PSOh1GfG89VElwLjdkvrTRyGXFBu6YjPdowg== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=clpYv4nf; 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 1776B606A334; Fri, 20 Nov 2026 09:57:45 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=clpYv4nf X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795168664; b=0Vdds9NeMG1gx1/vW1GZaRVBTEeKxC4+0jkhorgKe8Kcddq+nxW89zFXkjmf7yr/xrGr 7Ffxnc/WcZRKvmalplBOMeq+Y1El29gWtw169ZSXnbW7ewVMpwnhILPiOc1CRqKXVsPBl Twk9ODg7nYOCnbj4IQp4fLnHAfdASoZsVIomaBwLRA9baYjatffPsZ+9IZeCc3i87iOcV mLdAcZmalPDuaIZVjd/8zr2hjiiLQ4lVacdJCJUKByxPx271UfcDA/MBtNFHIrA5RiTqA 6g1GMg4HL+Zk3bO5XhQf3A5oraKxFuV6uHuu48jAPdu54x6ttvGFHfinrbfCbcZPcqw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795168664; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=US+BwjsBu2YGs4iPWGc7Xdq/wpYAMCQoXR2jUtQoE6E=; b=syCAF3tW8nzoTMkCX1mEpvxu/mYw2eKVGWK+3uRG0fR6mfOVifxED4RriuzmoAkgNtGn PfHu07i5VDzg6bNM4KQ7hJhBsYwByvispzTkSdcrr7KDPbEkRCInY1NgeV7IlAYgKD1MX dU4+ozpt6tnhVlND8zedHIefUW2q7C9Ago6e8kjCmY9WAqmv1lOLqwsFfW7e7Y2KS3Fe9 wkLwyGvavIWjz9fXOPxR539YM0YVfBSRmYZftwbOwoGuwagWFGj+vOyZdLwo2w0IinMUH SNigyXdls7AqWSl4oWH1qV0FjX+dVxx127BaDPoeIRCq8pdkn0OPlTHEgmHg8Ne6d2w== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=clpYv4nf; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3389E606A320; Fri, 20 Nov 2026 09:57:43 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28B161F000CA; Fri, 20 Nov 2026 09:57:43 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795168663; bh=US+BwjsBu2YGs4iPWGc7Xdq/wpYAMCQoXR2jUtQoE6E=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=clpYv4nf7GoRQgSzznc2rvcK1WJk2g6BZeRgeLlN/EqEoj9aMQbtcGbmNUqwvfUhx LbSiYfDczBc6J7XGGTObjzBJPhpvPyEBAOHv69laqE0zi/4u0JV6nWPkrLvrvd6hHP Y6QpmtSIUtqA1EZqlbzlnbzSqZe2iDSZeVpYLcqMpUmOwaEfGmTcYFbokGkmQWi2Lx z/XGdDS16hb36EF9zk6iyRcO15vU+yfqJ1T9rOi4oIqzWRRDucyWDWwYy/rZMPjRVT PD4bkkJMDbjWQrBQVQX0G2rfXYBh2HBPDrM2Zm0IEdAPlzQ2rDOKA/ybnsSefWLOkt 0fZOFFPowLENg== X-Cc: netdev@vger.kernel.org, edumazet@kernel.org, ncardwell@google.com, kuniyu@google.com, davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, weiwan@google.com, soheil@google.com, shakeel.butt@linux.dev, linux-kernel@vger.kernel.org X-In-Reply-To: <20261119090828.343748-1-jiayuan.chen@linux.dev> X-sashiko-severity: Medium 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