From: "Jose Fernandez (Anthropic)" <jose.fernandez@linux.dev>
To: Kuniyuki Iwashima <kuniyu@google.com>
Cc: Eric Dumazet <edumazet@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>,
Andrii Nakryiko <andrii@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Martin KaFai Lau <martin.lau@linux.dev>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
bpf@vger.kernel.org, Ben Cressey <ben@cressey.dev>,
Daniel Borkmann <daniel@iogearbox.net>
Subject: Re: [PATCH bpf] bpf: tcp: Fix use-after-free in bpf_iter_tcp_established_batch()
Date: Sat, 11 Jul 2026 15:00:13 +0000 [thread overview]
Message-ID: <alJXbCGnSXck4B7e@linux.dev> (raw)
In-Reply-To: <CAAVpQUDiLwSYwFStRGpMQkGbm3j8_KJm9LVj0ykV7V3nYQ4YTg@mail.gmail.com>
Hi Kuniyuki,
Thanks for the review!
On Sat, Jul 11, 2026 at 05:36:05AM -0700, Kuniyuki Iwashima wrote:
> > + } else if (!*start_sk) {
> > + /* Remember where we left off. */
> > + *start_sk = sk;
> > }
> > + expected++;
>
> This should be incremented just after seq_sk_match()
> (see below)
Will do.
> > @@ -3167,6 +3168,10 @@ static struct sock *bpf_iter_tcp_batch(struct seq_file *seq)
> > WARN_ON_ONCE(iter->end_sk != expected);
>
> Let's say the batch array was smaller than the hash chain length
> and we reallocate the array based on "expected" w/ the bucket lock.
>
> What happens if refcount_set(..., 3) is called during reallocation ?
> bpf_iter_fill_batch() will see the larger "expected", and WARN_ON_ONCE()
> will be triggered.
Right. Moving expected++ up fixes the sizing. Since end_sk == expected
then no longer holds when a socket is skipped, I'll make the
batch-complete check and the WARN look for a leftover socket instead.
I'll send a v2 early next week.
Thanks,
Jose
prev parent reply other threads:[~2026-07-11 15:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-20 0:32 [PATCH bpf] bpf: tcp: Fix use-after-free in bpf_iter_tcp_established_batch() Jose Fernandez (Anthropic)
2026-06-20 14:06 ` Jiayuan Chen
2026-06-29 7:37 ` Emil Tsalapatis
2026-07-10 13:44 ` Jose Fernandez (Anthropic)
2026-07-10 14:32 ` Daniel Borkmann
2026-07-10 16:17 ` Kuniyuki Iwashima
2026-07-10 22:24 ` Jose Fernandez (Anthropic)
2026-07-11 12:36 ` Kuniyuki Iwashima
2026-07-11 15:00 ` Jose Fernandez (Anthropic) [this message]
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=alJXbCGnSXck4B7e@linux.dev \
--to=jose.fernandez@linux.dev \
--cc=andrii@kernel.org \
--cc=ben@cressey.dev \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=yonghong.song@linux.dev \
/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