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=1796384276; b=pcTEsjK98kG+LyLqjI4A53NcD337a1wlfshxoffrgGbML2QXCmajFfIuPf0P9u8s93CU IaNaJueLYXTDt48L7Kl3+d5c5IbTuqwy/+1K1PnqSrjjcBJmIocnd7zbVILHBPNcY/j5B I9XJFM/QW5/27rbsIRQaioRoUMEXN9jCdeC7HHZc3683jVQui/qE/8Z1E7X5bzxP+jFr8 prTnYtzlwlmsB7gVPuRg2x5qzB30KnjCYuuNoFzV1Znu9qlaycZUuvnjGv2Lvk0+TCxS9 x5EnUzAIoDs4tGCnVubfLc8+Afr8I2m4i6SiPwUGs0c755mk3ZUEnv2/MYQJet4nMZw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384276; 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=ohakEvw6LM+B4sMjut/mOuQtpWxzT36bJnWhKIpISyM=; b=EsRxYBS4bEBqzsIjawLHDIQe+f1+E1HBE7YveemRfFFVKgqHi4mpLOlyDaS2A2KhZy+5 AS3eWtkGW5y1yhyh6ENyADweevluYLtm7RoyUVXxDQGCSF37aSIMISWdPhnNH/XmP2Xnz X2sNlqOVwQae0psO05h/wBKSNnWDp/1aWOH8hJTYIIv/HhWVj4Ot430JwhYGr7K/m/yc8 jEtM6DZS7LOUUDBlhwoO7Y6TRwfe6v37aGsuCsYYKklp3bWBprBSxKorWqUW51CMCqu2o xyEbYtxFVCCyzsPwZTm4embW4tp+wopaYL6sghgj7MTB7clkkEfO/BUcQXoLBOCXQQQ== 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=C76Oj08J; 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 B2B1C606A32C; Fri, 4 Dec 2026 11:37:56 +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=C76Oj08J Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30AE61F000C2; Fri, 4 Dec 2026 11:37:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384276; bh=ohakEvw6LM+B4sMjut/mOuQtpWxzT36bJnWhKIpISyM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=C76Oj08JwplXuQ0LIyvz1nzYN1Wvn6HAUNEUAZRAo9d26obi6F6S02WFrUKbH2N7v Oi2SXK4GXK5hMcSdlJKjfGIZ9805H5DZai6Yj8paALv63odd/FMBQoNnFsg3djfFBI 2uH+Zp+IGa45mwyJ7RXMccro8kIAQm0xh9Sm6LW0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Eric Dumazet , Kuniyuki Iwashima , Octavian Purdila , Dave Miller , Sasha Levin Subject: [PATCH 6.6 0083/1167] tcp: do not let tcp_collapse() drive sk_forward_alloc negative Date: Fri, 4 Dec 2026 18:51:50 +0900 Message-ID: <20261204100704.249624413@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Dumazet [ Upstream commit 031c403d13e5046750e2abebd4e770631e7c4627 ] tcp_collapse() charges each newly allocated skb with skb_set_owner_r() before the skbs it replaces are freed, without scheduling memory first. Since sk_mem_uncharge() reclaims eagerly, sk->sk_forward_alloc has no cushion and can become negative. This can be durable when the collapsed skbs had a high payload/truesize ratio or were partially read, because the new skbs can have a bigger total truesize than the old ones. A negative sk_forward_alloc then confuses tcp_wmem_schedule(), which can return a negative length to tcp_sendmsg_locked(), triggering a WARN_ON_ONCE(bytes > INT_MAX) in check_copy_size(). Call sk_forced_mem_schedule() before charging nskb. Fixes: 4890b686f408 ("net: keep sk->sk_forward_alloc as small as possible") Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima Signed-off-by: Octavian Purdila Signed-off-by: Dave Miller Signed-off-by: Sasha Levin --- net/ipv4/tcp_input.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index e911ad30d9a75..87a721a5b70d4 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -5422,6 +5422,10 @@ tcp_collapse(struct sock *sk, struct sk_buff_head *list, struct rb_root *root, __skb_queue_before(list, skb, nskb); else __skb_queue_tail(&tmp, nskb); /* defer rbtree insertion */ + /* nskb is charged before the skbs it replaces are freed. + * Make sure sk->sk_forward_alloc can not become negative. + */ + sk_forced_mem_schedule(sk, nskb->truesize); skb_set_owner_r(nskb, sk); mptcp_skb_ext_move(nskb, skb); -- 2.53.0