* [PATCH net v3] tcp: fix negative sk_forward_alloc after MSG_ZEROCOPY append
@ 2026-11-23 12:24 Jiayuan Chen
2026-11-23 18:04 ` Eric Dumazet
2026-11-26 2:20 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Jiayuan Chen @ 2026-11-23 12:24 UTC (permalink / raw)
To: netdev
Cc: Jiayuan Chen, Eric Dumazet, Neal Cardwell, Kuniyuki Iwashima,
David S. Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
Wei Wang, Shakeel Butt, Soheil Hassas Yeganeh, linux-kernel
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net v3] tcp: fix negative sk_forward_alloc after MSG_ZEROCOPY append
2026-11-23 12:24 [PATCH net v3] tcp: fix negative sk_forward_alloc after MSG_ZEROCOPY append Jiayuan Chen
@ 2026-11-23 18:04 ` Eric Dumazet
2026-11-26 2:20 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Eric Dumazet @ 2026-11-23 18:04 UTC (permalink / raw)
To: Jiayuan Chen
Cc: netdev, Neal Cardwell, Kuniyuki Iwashima, David S. Miller,
Jakub Kicinski, Paolo Abeni, Simon Horman, Wei Wang,
Shakeel Butt, Soheil Hassas Yeganeh, linux-kernel
Le lun. 23 nov. 2026 à 13:24, Jiayuan Chen <jiayuan.chen@linux.dev> a écrit :
>
> Our local syzbot reported the following warning:
>
>
>
> 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>
Reviewed-by: Eric Dumazet <edumazet@kernel.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net v3] tcp: fix negative sk_forward_alloc after MSG_ZEROCOPY append
2026-11-23 12:24 [PATCH net v3] tcp: fix negative sk_forward_alloc after MSG_ZEROCOPY append Jiayuan Chen
2026-11-23 18:04 ` Eric Dumazet
@ 2026-11-26 2:20 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-11-26 2:20 UTC (permalink / raw)
To: Jiayuan Chen
Cc: netdev, edumazet, ncardwell, kuniyu, davem, kuba, pabeni, horms,
weiwan, shakeel.butt, soheil, linux-kernel
Hello:
This patch was applied to netdev/net.git (main)
by Willem de Bruijn <willemb@google.com>:
On Mon, 23 Nov 2026 20:24:31 +0800 you 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>
>
> [...]
Here is the summary with links:
- [net,v3] tcp: fix negative sk_forward_alloc after MSG_ZEROCOPY append
https://git.kernel.org/netdev/net/c/e50436deae92
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-26 2:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-23 12:24 [PATCH net v3] tcp: fix negative sk_forward_alloc after MSG_ZEROCOPY append Jiayuan Chen
2026-11-23 18:04 ` Eric Dumazet
2026-11-26 2:20 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®