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 DA79E43B6E7; Mon, 17 Aug 2026 14:53:21 +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=1786978403; cv=none; b=hYNXsHK6cZIxxE/YL88i2io2ZVI+lWeHWs8R835HWrTOdcIQew/LlUe0ZT/j5ZhY4c1wYUaTvGC4bj1qN8AnkqPFT2/m391Qw1MH2EQiYoIGYRqv3a465aQLgI9Zcn/4foha5+30vyUe1rrH7sWUa5sMcH0w7kxjHqMg2tGtLaI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786978403; c=relaxed/simple; bh=JznSkf8AtTGaZ/STUBEzdBrtzdYYBonEJCqWF2nN90A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GGk9Ou5lBvm3WGfnkDBajZWqk33fNRi+TiHdUymziMlrl35nEDqQdoFjlWHzdO70svmc1I2QAsTN6/khLg4MW6F/3Lb5zE7AIL81ITbwmzRTPACklC97NJ12Y+y2zHEzrT+1JSzebvRpjGzSZ+WKdN2TY4QRP7L4xU1befsG10Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=WDSNjupY; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="WDSNjupY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3CB791F000E9; Mon, 17 Aug 2026 14:53:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1786978401; bh=NAod2zYBbnGBvtQVBUaRSeRi2KV81bqxMu2fP7QKAIA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=WDSNjupYcwn4UJBVFwoJ3kjgIOykCUSMnL8hrRfLopV/EbQ/XzGdzG/nyknw8NDTX 265zfwZG1lOjViIU00bD3XE3xw/y5j/7uRfvJ8BatXwQDn/bYFJJjdLv0K0AuhVTln nzx8WsrDFqxa3d2Ad52ywuXJlle1kPxkqcNxM2ek= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jordan Rife , Martin KaFai Lau , Kuniyuki Iwashima , Stanislav Fomichev , Sasha Levin Subject: [PATCH 6.6 024/156] bpf: tcp: Get rid of st_bucket_done Date: Mon, 17 Aug 2026 15:32:38 +0200 Message-ID: <20260817132535.577460213@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260817132534.666299318@linuxfoundation.org> References: <20260817132534.666299318@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jordan Rife [ Upstream commit e25ab9b874a4bd8c6e3e5ce66cbe8a1dd4096e2e ] Get rid of the st_bucket_done field to simplify TCP iterator state and logic. Before, st_bucket_done could be false if bpf_iter_tcp_batch returned a partial batch; however, with the last patch ("bpf: tcp: Make sure iter->batch always contains a full bucket snapshot"), st_bucket_done == true is equivalent to iter->cur_sk == iter->end_sk. Signed-off-by: Jordan Rife Signed-off-by: Martin KaFai Lau Reviewed-by: Kuniyuki Iwashima Acked-by: Stanislav Fomichev Stable-dep-of: e5fd3f514e27 ("bpf: tcp: Fix use-after-free in bpf_iter_tcp_established_batch()") Signed-off-by: Sasha Levin --- net/ipv4/tcp_ipv4.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index d584ce27b2ddd..c32902c07bd0c 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -2782,7 +2782,6 @@ struct bpf_tcp_iter_state { unsigned int end_sk; unsigned int max_sk; struct sock **batch; - bool st_bucket_done; }; struct bpf_iter__tcp { @@ -2805,8 +2804,10 @@ static int tcp_prog_seq_show(struct bpf_prog *prog, struct bpf_iter_meta *meta, static void bpf_iter_tcp_put_batch(struct bpf_tcp_iter_state *iter) { - while (iter->cur_sk < iter->end_sk) - sock_gen_put(iter->batch[iter->cur_sk++]); + unsigned int cur_sk = iter->cur_sk; + + while (cur_sk < iter->end_sk) + sock_gen_put(iter->batch[cur_sk++]); } static int bpf_iter_tcp_realloc_batch(struct bpf_tcp_iter_state *iter, @@ -2923,7 +2924,7 @@ static struct sock *bpf_iter_tcp_batch(struct seq_file *seq) * one by one in the current bucket and eventually find out * it has to advance to the next bucket. */ - if (iter->st_bucket_done) { + if (iter->end_sk && iter->cur_sk == iter->end_sk) { st->offset = 0; st->bucket++; if (st->state == TCP_SEQ_STATE_LISTENING && @@ -2935,7 +2936,6 @@ static struct sock *bpf_iter_tcp_batch(struct seq_file *seq) iter->cur_sk = 0; iter->end_sk = 0; - iter->st_bucket_done = true; sk = tcp_seek_last_pos(seq); if (!sk) @@ -3083,10 +3083,8 @@ static void bpf_iter_tcp_seq_stop(struct seq_file *seq, void *v) (void)tcp_prog_seq_show(prog, &meta, v, 0); } - if (iter->cur_sk < iter->end_sk) { + if (iter->cur_sk < iter->end_sk) bpf_iter_tcp_put_batch(iter); - iter->st_bucket_done = false; - } } static const struct seq_operations bpf_iter_tcp_seq_ops = { -- 2.53.0