From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796380634; b=mQBK+7pJBLKNhzmXA8x2CSXJH8FFSBb24QpSMaeGeHehVw3alSKZOzqNuiq1X6f5qFuk karDyYIA1skPSXSnjdA/GVWU3ecCMPnKjjbTb6fQzlRKuOwV3fsRwOArC4ysobH9t5byj nzfL5mUIRqWWFv7PqqTOfjS0I5PW4ncVZRhGvugnQOLcN9iSmD2lgKZi3+eaUOfdlBFyZ chYBjKYCtEF1leOp7A5l2Ew3YHGt1ZEJEJ5UYqmusQokiReaS1GzH6d3KaqWtDb/BWOMC cGhQhIwH+16RRLSL9NkvmkFawJJ7nTJuJXAurgiQ97hV5Z1uD8vmLjs8fSaConpCWdQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380634; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=9qiGspO64+3woKBYauU/xpHX0dpmukPLb+jdqVR+7a0=; b=y2bFSTVPRqADGi3rhc9jmoZsjwttOfvhMWIyDoGw+WICGiZVUNeoA36qMfpH7/REubKf ilH4pLsPnbyxG5iKd3ud4wqssu8rvfLFfcLyXkN/D2/HOealvY9Pb2sZZwAaJCdYl1vBu KrDlN6HR30PCXBoU4b0xzWbXZq1xwzdfWys4+7HCt4H+3qZzU1dG7VHR7O7ojDrpNZvdE rJxjShVLnZmLNULB4NDn7vtNiLacoQjNM2+x0HWBSbb+r1Q6ag9eyfsAwgXnJ5eHqLUsL BX6xc79yGhZWppTVqmoMOV4mnQTmi/BAm8VSiwaZ4yPo/YJW9uuKNGgPntpYl4nGeNQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=rjAjxeJS; arc=none smtp.remote-ip=100.103.45.18 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 A50A7606A33B; Fri, 4 Dec 2026 10:37:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=rjAjxeJS Received: by smtp.kernel.org (Postfix) with ESMTPSA id BFFEB1F000C2; Fri, 4 Dec 2026 10:37:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380634; bh=9qiGspO64+3woKBYauU/xpHX0dpmukPLb+jdqVR+7a0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=rjAjxeJS5qU2BEe1I/7HPVdXoRiwlDAlipLtTLMvpieo5qBFtN6WcGI80cGKH12tJ St+zBb8lvReJ600XpfatvU6G0RckhIWSwAm/uJ4OhQoqvPzM1Hwj6O0t6lqmFiNP53 nLd97yk4gDHcwu+RQ/L2NPkBe1AonviOBm6ksRvQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jiayuan Chen , Eric Dumazet , Willem de Bruijn , Sasha Levin Subject: [PATCH 7.3 307/742] tcp: fix negative sk_forward_alloc after MSG_ZEROCOPY append Date: Fri, 4 Dec 2026 19:02:51 +0900 Message-ID: <20261204100643.186686077@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jiayuan Chen [ Upstream commit e50436deae925d1b95b01936e2499428c4782a6a ] 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: 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 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 Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/20261123122432.297135-1-jiayuan.chen@linux.dev Signed-off-by: Willem de Bruijn Signed-off-by: Sasha Levin --- net/ipv4/tcp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 338c30c65dad9..de95bc5e9c9b6 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -1349,6 +1349,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.53.0