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=1796382227; b=l3xXpQ+6YFcBnoR5B5LG+VWpecVtw5GqBew3XA/XIRM+cb7q2SHUXWUkF9K9hNIEMFsl 87k8/3tt0py9VKaxu2JBYCDOlKXHAZKRQhXO1hHQKaI0u/htjg7SweU7DOOdxwtF2pcAh ov0GRs15YlhynemfKao6HFgDtvu0A0gLew21B/Ud6LHQyw+L38y2wY4kmBloiYItiZMWM YEGCAY1n7dz+IaPpVXXcN77do6udrZwYS8i2mV1qLYor3Ur16RjWVhxwmh4qgjK1xcLeg JCBDc1aZ8N1skzrKqCfjHkd+PAKK8wHKYDf6M/D3GypuI7m5G+UKK+JtdTBvzYdV6wA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382227; 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=wapy4zEq1TCQVJMlSwG3zipGxHdP+6hdC8A53aOrVW0=; b=CVUXbv7BCe8c4WkrP4lWnX2qNsKjhklsZDC2El9sVaP+QxN38GjIi6d+7/ERcKClxiYp 93uyZZD65MGau6X8dQzwS/BzeIoLqwcXpL+5g+7O88SGNJGeazmJk82/AB97xeghZPVXi eWbws1keu1ZDAXu+eeCgSDdHKAsyeNw8zPn5mS2r1e0uAfw1AfTdOAsLs6W6/t2OlbMdQ vu0cAFuBFIecvp/SJMUmZWRtD3UNq20Q8snvTdxhAKBgCQLMjtnhY5nFcokamEoKM4RxY Qe/uGty/SQQ2xJwApZ0uCG5W1KgSoV0qtWtJtQW/W3fvXOjbCzhp513FFGpFrIYCn9A== 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=c8FobJAM; 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 D989F606A322; Fri, 4 Dec 2026 11:03:47 +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=c8FobJAM Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F4E21F000CE; Fri, 4 Dec 2026 11:03:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382227; bh=wapy4zEq1TCQVJMlSwG3zipGxHdP+6hdC8A53aOrVW0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=c8FobJAMHe8R04BirGaTvPKpMz3RI3A18LmrfKWSaQ0v5E4YpJelq+L2YKTta5yQQ 9sVeB3ClUoKY/F1FL2E/fZGKOIgum8hG3tb8PDn3Oeb/SCPdyypA78BGvcZ6Urie/D HcPFbrF2bYj22ifv+8Qk68tKqKv5qtNLdM3cGoOI= 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 6.18 322/703] tcp: fix negative sk_forward_alloc after MSG_ZEROCOPY append Date: Fri, 4 Dec 2026 19:03:41 +0900 Message-ID: <20261204100636.343373845@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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 6.18-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 4d41f16bd6103..0c5f5bd2621d7 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -1309,6 +1309,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