Re: [PATCH net v3] tcp: fix negative sk_forward_alloc after MSG_ZEROCOPY append
From: Eric Dumazet
Date: Mon Nov 23 2026 - 13:04:38 EST
Le lun. 23 nov. 2026 à 13:24, Jiayuan Chen <jiayuan.chen@xxxxxxxxx> 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@xxxxxxxxx>
Reviewed-by: Eric Dumazet <edumazet@xxxxxxxxxx>