Article View: linux.kernel.netdev
Article #3896Re: [PATCH net 1/2] tcp: clamp return value of tcp_wmem_schedule() to non-negative
From: Eric Dumazet
Date: Fri, 16 Oct 2026 08:19
Date: Fri, 16 Oct 2026 08:19
44 lines
8497 bytes
8497 bytes
Le ven. 16 oct. 2026 à 09:42, Kuniyuki Iwashima <kuniyu@google.com> a écrit :
>
> On Thu, Oct 15, 2026 at 12:37 AM Octavian Purdila <tavip@google.com> wrote:
> >
> > When sk_wmem_schedule(sk, copy) fails under TCP memory pressure and
> > sk->sk_wmem_queued already reaches or exceeds sysctl_tcp_wmem[0],
> > tcp_wmem_schedule() returns min(copy, sk->sk_forward_alloc).
> >
> > However, sk->sk_forward_alloc is a signed int that can transiently
> > become negative when tcp_collapse() re-packs partially read or high
> > payload-to-truesize SKBs in the receive queue and charges newly
> > allocated SKBs via sk_mem_charge() before freeing the original SKB.
> >
> > If tcp_wmem_schedule() returns a negative value, tcp_sendmsg_locked()
> > passes that negative copy length to skb_copy_to_page_nocache() ->
> > copy_from_iter_full() -> check_copy_size(), where it is converted to an
> > unsigned size_t > INT_MAX, triggering a WARN_ON_ONCE(bytes > INT_MAX)
> > and returning -EFAULT instead of waiting for memory or returning
> > -EAGAIN.
> >
> > Clamp the return value of tcp_wmem_schedule() to [0, copy] so callers
> > treat negative sk_forward_alloc as 0 available bytes.
> >
> > Fixes: 849b425cd091 ("tcp: fix possible freeze in tx path under memory pressure")
> > Assisted-by: LLM
> > Signed-off-by: Octavian Purdila <tavip@google.com>
>
> Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
>
Reviewed-by: Eric Dumazet <edumazet@kernel.org>
> Basically sk->sk_forward_alloc should not be negative, and
> I was able to avoid that by refactoring tcp_collapse(), but it was
> a bit invasive for stable and late in rc8, so I'll post it in the next cycle.
>
> $ git diff --stat HEAD~4
> net/ipv4/tcp_input.c | 158 ...
> 1 file changed, 109 insertions(+), 49 deletions(-)
Technical Details
Message-ID:
<CAL4Wiipff3Aai0f=iwXmvc1MKessWzO2fojVu67BQ6e-pGPk3A@mail.gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-347170-linux-kernel-netdev=dewy.ruReferences:
<20261015073736.2944215-1-tavip@google.com> <20261015073736.2944215-2-tavip@google.com> <CAAVpQUAnURtwVgKmRYXTZBjEyb58mxXkeJoMkh7Mc6+ESb1Sfg@mail.gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-347170-linux-kernel-netdev=dewy.ru
From: edumazet@kernel.org (Eric Dumazet)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net 1/2] tcp: clamp return value of tcp_wmem_schedule() to non-negative
Date: Fri, 16 Oct 2026 10:19:46 +0200
Organization: Usenet Network
Message-ID: <CAL4Wiipff3Aai0f=iwXmvc1MKessWzO2fojVu67BQ6e-pGPk3A@mail.gmail.com>
References: <20261015073736.2944215-1-tavip@google.com> <20261015073736.2944215-2-tavip@google.com>
<CAAVpQUAnURtwVgKmRYXTZBjEyb58mxXkeJoMkh7Mc6+ESb1Sfg@mail.gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
logging-data="2716264"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:a7F/WuxNve1T+lmH7w4w3AL4Gis= sha256:2E/JldOF3qOjYa0GCVJ5/kQ+Fi17RXkoIieM65dfMXY=
sha1:2dXenYpieD0O5LH0zAeyvk8UuHM= sha256:e+jSSsNA2cceZ8cHfjZaO4xM6UKol9zgjwdAct2FcuU=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 48B02110495; Fri, 16 Oct 2026 11:21:35 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -1.44
X-Spam-Status: No, score=-1.44 tagged_above=-9999 required=6.31
tests=[DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1,
SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id yFuXsWko-yNp;
Fri, 16 Oct 2026 11:21:28 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-347170-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
by mail.dewy.ru (Postfix) with ESMTPS id ED50B110493; Fri, 16 Oct 2026 11:21:17 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
by sto.lore.kernel.org (Postfix) with ESMTP id 3E071609D4A; Fri, 16 Oct 2026 08:20:03 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 0742C3B8948;
Fri, 16 Oct 2026 08:20:02 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iKxlHMUo"
X-Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B6E93BFACE
for <netdev@vger.kernel.org>; Fri, 16 Oct 2026 08:20:00 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1792138801; cv=none; b=NjCyJ+SSPME7uzlIxdpfFAAIjEuPBKKNknhrHpFGtKL0Y9LyTNPujH/15dnXuLc5ExzlEdvvubXsZ2Cp7a7L+UGkRmmeW5xPievx8aauO5h/luxU71dre9uCc+Hgu9Oe/1tXGKHuSciex/HMPl7kqpv25vc4DkLqqml+vCWovf0=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1792138801; c=relaxed/simple;
bh=Q/VFJDeaY/23ZJwVigeNwes0ycOyUM1dhiVYAZgu9lE=;
h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject:
To:Cc:Content-Type; b=jLSWm24RP0p0wQBarWL7w/E7yAcBFjNILBD0OFlJTwKejWNN+kMhd0Ae1agwuI68zfXRB80oAXiOJVGkzCLzm870REDtt0SlzFzzUWnoGdutOi40d83YRDFwHiu5oHDp07L0M+CZUPrh2ZpIB9gdGELRuZVGez7fO6gqUCWXLz0=
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iKxlHMUo; arc=none smtp.client-ip=100.103.45.18
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55BF51F000D2
for <netdev@vger.kernel.org>; Fri, 16 Oct 2026 08:20:00 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
s=k20260515; t=1792138800;
bh=NQNdQ79CqehE3MN8JBQ8cGNawuMei/JypxZtTt4YpYc=;
h=References:In-Reply-To:From:Date:Subject:To:Cc;
b=iKxlHMUo+/1GZcAn9zFCZJrdBiM4xpOj7aQo/0biOZE99rPXdb9j84gzoYcPY3MQL
n/vzJrQYSYACTqxmx/rxDWNdYugxZfkWiXvYgc6XW4MINFf4Br37NBRmQI7V9nw5vk
e7lZJa8fl3D5k0KHMwV/Rg/qYUt3z1f6h3o8jAyRfc6NdkoGyOPLHQFX07bVm6B7G8
snxa5s3JukuEMx+ugj0XqfA4DSQs3jawv/jwA3SsRPIGxcoYO/Df966VlkutDzq23b
HeiTGXGGke2+QgOmf3/uXIOp5HxVSGPK9gm4OAlGKi1XAciFRVX16J5QOnnkYL9gjd
c5dB4fQdnxYgg==
X-Received: by mail-oo1-f47.google.com with SMTP id 006d021491bc7-6df0b02fe91so620864eaf.0
for <netdev@vger.kernel.org>; Fri, 16 Oct 2026 01:20:00 -0700 (PDT)
X-Forwarded-Encrypted: i=1; AKwUvBw85lrsmrbE+9hDNtxwqrKYLEiXHSzsEemXWOzROvRINY05ku0VQidMOqIUUC6ses+aCNvmkXs=@vger.kernel.org
X-Gm-Message-State: AFq9FYI/XrDDf73dCoGFCfHcCJFgkInJQp6hEgxIJCWhshXQ22B+/z9m
cprUWlPC+uLi4FUDUOho+uvdhTGu1a/9KF2N/IS77s/nj6XIT/+sb9JJXmPvGvkUlq85yQWJvwF
85vzKqx59HnZVMC9YgKa3QvFwqO8iRjo=
X-Received: by 2002:a05:6820:f02a:b0:6d8:462d:2755 with SMTP id
006d021491bc7-70114debb9bmr1594715eaf.37.1792138799204; Fri, 16 Oct 2026
01:19:59 -0700 (PDT)
X-Precedence: bulk
X-Mailing-List: netdev@vger.kernel.org
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-In-Reply-To: <CAAVpQUAnURtwVgKmRYXTZBjEyb58mxXkeJoMkh7Mc6+ESb1Sfg@mail.gmail.com>
X-Gmail-Original-Message-ID: <CAL4Wiipff3Aai0f=iwXmvc1MKessWzO2fojVu67BQ6e-pGPk3A@mail.gmail.com>
X-Gm-Features: AclHuK_ghVWdNzfqvDun0kKrC7LGzJBYtDJxzI9zBA3uy3mDqEmjWu5L0M5ujAU
X-Cc: Octavian Purdila <tavip@google.com>, Neal Cardwell <ncardwell@google.com>,
"David S . Miller" <davem@davemloft.net>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>, Shuah Khan <shuah@kernel.org>,
Willem de Bruijn <willemb@google.com>, Soheil Hassas Yeganeh <soheil@google.com>, Wei Wang <weiwan@google.com>,
Shakeel Butt <shakeel.butt@linux.dev>, netdev@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org