From mboxrd@z Thu Jan 1 00:00:00 1970 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 8B79D3C061F for ; Fri, 16 Oct 2026 08:20:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792138802; cv=none; b=c9NcTJPfzFCQEpmzhGR48ItwDSDlxxj9VPeuGK62qrel+EIjSmTu4df2BUsBhHzddi8jvMoQWhg9E4+kd06HCD+iRR7UZghvjoLhC9cm2w+/ngJUYT+uapBdRPELWfYF/tu0m6xZ8zO9AH0elQGhuijzKEea+D8VJFa+PUV/tZw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792138802; c=relaxed/simple; bh=Q/VFJDeaY/23ZJwVigeNwes0ycOyUM1dhiVYAZgu9lE=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Tm/Bp7FyLHlpvP7P7LfrGJ/1vGujPcSPgFnEzL1TeuImUXncuPvnWHZuQZ9fDCSoaLFhQpdcAk4ywelS21fIUeTPz2oTzUVIvpefgOzai8aasjbYvVLMRL3DSgZUwX3VLCLZYYREMSiJkreaGA77nSv2BBj0PxD3bdjbzG9frQk= 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iKxlHMUo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 34D4E1F000CC for ; Fri, 16 Oct 2026 08:20:00 +0000 (UTC) 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== Received: by mail-oo1-f51.google.com with SMTP id 006d021491bc7-70094949641so842320eaf.0 for ; Fri, 16 Oct 2026 01:20:00 -0700 (PDT) X-Forwarded-Encrypted: i=1; AKwUvBzqv/wp3h/JRHBQkdcPL9GnZebAaervhXLYXpHhggL3lt9bOkTrygtieMPo6fKY5sDf4S60vlBKuW374q4=@vger.kernel.org X-Gm-Message-State: AFq9FYL+NrTDqCpkUMvr+x2WEWiynMDEXcNoKz8hiNWBUSyoBAV004gD 8ybO+RGGbw2gGPFPWHfV5Th+LKM716qjvHlEsdFqVwfoDRIW/EfGfyGabMx9qMuQhydTZNFocDY sHrOEUV9g3Tjj4/IuV18a9XJuLGWPpA0= 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) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20261015073736.2944215-1-tavip@google.com> <20261015073736.2944215-2-tavip@google.com> In-Reply-To: From: Eric Dumazet Date: Fri, 16 Oct 2026 10:19:46 +0200 X-Gmail-Original-Message-ID: X-Gm-Features: AclHuK_ghVWdNzfqvDun0kKrC7LGzJBYtDJxzI9zBA3uy3mDqEmjWu5L0M5ujAU Message-ID: Subject: Re: [PATCH net 1/2] tcp: clamp return value of tcp_wmem_schedule() to non-negative To: Kuniyuki Iwashima Cc: Octavian Purdila , Neal Cardwell , "David S . Miller" , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan , Willem de Bruijn , Soheil Hassas Yeganeh , Wei Wang , Shakeel Butt , netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Le ven. 16 oct. 2026 =C3=A0 09:42, Kuniyuki Iwashima a = =C3=A9crit : > > On Thu, Oct 15, 2026 at 12:37=E2=80=AFAM Octavian Purdila 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 > > Reviewed-by: Kuniyuki Iwashima > Reviewed-by: Eric Dumazet > 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 cy= cle. > > $ git diff --stat HEAD~4 > net/ipv4/tcp_input.c | 158 ... > 1 file changed, 109 insertions(+), 49 deletions(-)