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 BE20726461F; Mon, 17 Aug 2026 15:24:02 +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=1786980243; cv=none; b=cMypuXPFELCIjy2F/opxeomg8oNQPi+pqfedgRSXwR9clnHLzyoXOpSLbGccF6hrT+3eh9Ln8poNKD3aI3uxL6C7WjGGUUhCWP+ruWM8VP6Y8k1s2R96EqaSalYxmNZIx+CBzuaPa1S20HjoaEJuitA5ke2Yen0rwYSKujNdEgY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786980243; c=relaxed/simple; bh=aIQEVMBHGPhLIibVkaW1YvFwNqX++HUQJbNTWKQe0NI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rug8AJerGRkA0LkwCWCilOEyURmI70M8VGAqOQgCYSnEZ+yQdSL8fmf1Cfi+IaF185uNPL6Sp8AnpR45Zehz8jlmUplc9CrGLcxUlbh/4/OSEH/B4eNTAXZMMyDHb83VPP1drmUp+Sk4fzVBw206JQT0Ws20ojH2ASnJNrRfrP0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=exrHdoJC; 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="exrHdoJC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 280661F000E9; Mon, 17 Aug 2026 15:24:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1786980242; bh=DzXbEqME3Mgh1fpsTiVWGZKYynMLS6c40k4zuAXR3X8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=exrHdoJCu1mRPNytQtJRvxRtcrf8gKAi+XolKOPF/y4bYzOFMamHfWqbJQLn81OIy wgb/1y2b/MuWkEkg5KgKlojNq+aCB5l7krlsardd6oaX1urMGylgJI1lFtzlH6gy2F dIn6fy5Md2RvIxnuzBw6lEnPngoQtlXFX2XoJw1E= 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.1 505/609] bpf: tcp: Get rid of st_bucket_done Date: Mon, 17 Aug 2026 15:33:21 +0200 Message-ID: <20260817132600.766243854@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260817132543.039278408@linuxfoundation.org> References: <20260817132543.039278408@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.1-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 70c15160d2491..fb975e8f55ae5 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -2731,7 +2731,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 { @@ -2754,8 +2753,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, @@ -2872,7 +2873,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 && @@ -2884,7 +2885,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) @@ -3032,10 +3032,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