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 C1B6142376B; Mon, 17 Aug 2026 14:45: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=1786977904; cv=none; b=peTrOqLYWC1KOrueOdIDwvae7Rb8EVi2UXyAYCTbGtgkbcO9GKXO3mrURcW3q3Na9VRk/XJguKwxnQp1q8KXrt+MS64TbUKZyH+dsUZ+FUK8BCLvxrqPPmbQk5IC4LA60Yw1bIOenyYQKDQTGxIOK7zXfmRcqAY5AvhqYUBgvW8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786977904; c=relaxed/simple; bh=823cTOuVmWRPyr3iaXaqQZ97pyzoH/10508VdBlceS4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XUZvg/gv+jtsHfib8mi2LQyr9okP4bEpIIaNmtO53GLi+3XTV/KtgMO2YZ3J8YVL3P2BuqmquLZ2WJxBM8VrWEfU+WP65lN8WG+uYR0AQLDd4bnxif8J9FCjjQDCPJCBy7P9tGbieRkLKFI4VayWms3Yvo4nbi9SO04w1J5b5wA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=GIldsxjn; 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="GIldsxjn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D8EEB1F000E9; Mon, 17 Aug 2026 14:45:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1786977902; bh=3Mpm87ayRjhroeOTFwPi6ahSgG7OHItbd21vT9n+vAw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=GIldsxjn8iO5lA7dAss0rFYa9k7mM2jZkr2SuAEjeiXkqio3aaiRS+JzWNWkOdJSf 3Ig8KmhLsLQ39dUTyfQJ+O6RpQSDYkf6HnFez3NPYjp0kgWdEIp2cUkjUuVqRKL8Fr TWOf644cjHtVPRvlyI1w9ITkANEBmIv4LuAacJHA= 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.12 032/181] bpf: tcp: Get rid of st_bucket_done Date: Mon, 17 Aug 2026 15:32:06 +0200 Message-ID: <20260817132536.637910810@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260817132535.394764707@linuxfoundation.org> References: <20260817132535.394764707@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.12-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 2bcc037521930..c18eee7ed5378 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -3004,7 +3004,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 { @@ -3027,8 +3026,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, @@ -3145,7 +3146,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 && @@ -3157,7 +3158,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) @@ -3305,10 +3305,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