mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Eric Dumazet <edumazet@kernel.org>
To: Kuniyuki Iwashima <kuniyu@google.com>
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
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	[thread overview]
Message-ID: <CAL4Wiipff3Aai0f=iwXmvc1MKessWzO2fojVu67BQ6e-pGPk3A@mail.gmail.com> (raw)
In-Reply-To: <CAAVpQUAnURtwVgKmRYXTZBjEyb58mxXkeJoMkh7Mc6+ESb1Sfg@mail.gmail.com>

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(-)

  reply	other threads:[~2026-10-16  8:20 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15  7:37 [PATCH net 0/2] " Octavian Purdila
2026-10-15  7:37 ` [PATCH net 1/2] " Octavian Purdila
2026-10-16  7:42   ` Kuniyuki Iwashima
2026-10-16  8:19     ` Eric Dumazet [this message]
2026-10-15  7:37 ` [PATCH net 2/2] selftests: net: packetdrill: add test for negative sk_forward_alloc in tcp_wmem_schedule() Octavian Purdila
2026-10-16  7:54   ` Kuniyuki Iwashima
2026-10-16  8:22     ` Eric Dumazet
2026-10-16  8:23       ` Eric Dumazet
2026-10-16  8:59         ` Octavian Purdila
2026-10-15  7:43 ` [PATCH net 0/2] tcp: clamp return value of tcp_wmem_schedule() to non-negative netdev-bot+sinfo
2026-10-15  7:56   ` Octavian Purdila

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAL4Wiipff3Aai0f=iwXmvc1MKessWzO2fojVu67BQ6e-pGPk3A@mail.gmail.com' \
    --to=edumazet@kernel.org \
    --cc=davem@davemloft.net \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shakeel.butt@linux.dev \
    --cc=shuah@kernel.org \
    --cc=soheil@google.com \
    --cc=tavip@google.com \
    --cc=weiwan@google.com \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®