lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <4fc1f65c-d950-42a5-b3d2-8e7adfcb4d45@linux.dev>
Date: Thu, 1 May 2025 11:28:31 -0700
From: Martin KaFai Lau <martin.lau@...ux.dev>
To: Jordan Rife <jordan@...fe.io>
Cc: netdev@...r.kernel.org, bpf@...r.kernel.org,
 Aditi Ghag <aditi.ghag@...valent.com>, Daniel Borkmann
 <daniel@...earbox.net>, Willem de Bruijn <willemdebruijn.kernel@...il.com>,
 Kuniyuki Iwashima <kuniyu@...zon.com>,
 Alexei Starovoitov <alexei.starovoitov@...il.com>
Subject: Re: [PATCH v6 bpf-next 3/7] bpf: udp: Get rid of st_bucket_done

On 4/28/25 11:00 AM, Jordan Rife wrote:
> Get rid of the st_bucket_done field to simplify UDP iterator state and
> logic. Before, st_bucket_done could be false if bpf_iter_udp_batch
> returned a partial batch; however, with the last patch ("bpf: udp: 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 <jordan@...fe.io>
> ---
>   net/ipv4/udp.c | 14 ++++++--------
>   1 file changed, 6 insertions(+), 8 deletions(-)
> 
> diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
> index 5fe22f4f43d7..57ac84a77e3d 100644
> --- a/net/ipv4/udp.c
> +++ b/net/ipv4/udp.c
> @@ -3397,7 +3397,6 @@ struct bpf_udp_iter_state {
>   	unsigned int max_sk;
>   	int offset;
>   	struct sock **batch;
> -	bool st_bucket_done;
>   };
>   
>   static int bpf_iter_udp_realloc_batch(struct bpf_udp_iter_state *iter,
> @@ -3418,7 +3417,7 @@ static struct sock *bpf_iter_udp_batch(struct seq_file *seq)
>   	resume_offset = iter->offset;
>   
>   	/* The current batch is done, so advance the bucket. */
> -	if (iter->st_bucket_done)
> +	if (iter->cur_sk == iter->end_sk)
>   		state->bucket++;

I think the very first bucket will be skipped.

>   
>   	udptable = udp_get_table_seq(seq, net);
> @@ -3433,7 +3432,6 @@ static struct sock *bpf_iter_udp_batch(struct seq_file *seq)
>   	 */
>   	iter->cur_sk = 0;
>   	iter->end_sk = 0;
> -	iter->st_bucket_done = true;
>   	batch_sks = 0;
>   
>   	for (; state->bucket <= udptable->mask; state->bucket++) {
> @@ -3596,8 +3594,10 @@ static int bpf_iter_udp_seq_show(struct seq_file *seq, void *v)
>   
>   static void bpf_iter_udp_put_batch(struct bpf_udp_iter_state *iter)
>   {
> -	while (iter->cur_sk < iter->end_sk)
> -		sock_put(iter->batch[iter->cur_sk++]);
> +	unsigned int cur_sk = iter->cur_sk;
> +
> +	while (cur_sk < iter->end_sk)
> +		sock_put(iter->batch[cur_sk++]);
>   }
>   
>   static void bpf_iter_udp_seq_stop(struct seq_file *seq, void *v)
> @@ -3613,10 +3613,8 @@ static void bpf_iter_udp_seq_stop(struct seq_file *seq, void *v)
>   			(void)udp_prog_seq_show(prog, &meta, v, 0, 0);
>   	}
>   
> -	if (iter->cur_sk < iter->end_sk) {
> +	if (iter->cur_sk < iter->end_sk)
>   		bpf_iter_udp_put_batch(iter);
> -		iter->st_bucket_done = false;
> -	}
>   }
>   
>   static const struct seq_operations bpf_iter_udp_seq_ops = {


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ