Thread (9 messages) 9 messages, 5 authors, 1d ago

Re: [PATCH bpf] bpf: tcp: Fix use-after-free in bpf_iter_tcp_established_batch()

From: Jose Fernandez (Anthropic) <hidden>
Date: 2026-07-11 15:00:36
Also in: bpf, lkml

Hi Kuniyuki,

Thanks for the review!

On Sat, Jul 11, 2026 at 05:36:05AM -0700, Kuniyuki Iwashima wrote:
quoted
+               } 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.
quoted
@@ -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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help