[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAADnVQLkPPxvFV4ZftGeTNWfhtVnGR+Y8NAYZUmuyOcU_M_Y8g@mail.gmail.com>
Date: Mon, 29 Jun 2020 21:47:10 -0700
From: Alexei Starovoitov <alexei.starovoitov@...il.com>
To: Andrii Nakryiko <andriin@...com>
Cc: bpf <bpf@...r.kernel.org>,
Network Development <netdev@...r.kernel.org>,
Alexei Starovoitov <ast@...com>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii.nakryiko@...il.com>,
Kernel Team <kernel-team@...com>
Subject: Re: [PATCH bpf] bpf: enforce BPF ringbuf size to be the power of 2
On Mon, Jun 29, 2020 at 3:19 PM Andrii Nakryiko <andriin@...com> wrote:
>
> BPF ringbuf assumes the size to be a multiple of page size and the power of
> 2 value. The latter is important to avoid division while calculating position
> inside the ring buffer and using (N-1) mask instead. This patch fixes omission
> to enforce power-of-2 size rule.
>
> Fixes: 457f44363a88 ("bpf: Implement BPF ring buffer and verifier support for it")
> Signed-off-by: Andrii Nakryiko <andriin@...com>
> ---
> kernel/bpf/ringbuf.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/bpf/ringbuf.c b/kernel/bpf/ringbuf.c
> index 180414bb0d3e..dcc8e8b9df10 100644
> --- a/kernel/bpf/ringbuf.c
> +++ b/kernel/bpf/ringbuf.c
> @@ -132,7 +132,7 @@ static struct bpf_ringbuf *bpf_ringbuf_alloc(size_t data_sz, int numa_node)
> {
> struct bpf_ringbuf *rb;
>
> - if (!data_sz || !PAGE_ALIGNED(data_sz))
> + if (!is_power_of_2(data_sz) || !PAGE_ALIGNED(data_sz))
> return ERR_PTR(-EINVAL);
What's the point checking the same value in two different places?
The check below did that already.
> #ifdef CONFIG_64BIT
> @@ -166,7 +166,8 @@ static struct bpf_map *ringbuf_map_alloc(union bpf_attr *attr)
> return ERR_PTR(-EINVAL);
>
> if (attr->key_size || attr->value_size ||
> - attr->max_entries == 0 || !PAGE_ALIGNED(attr->max_entries))
> + !is_power_of_2(attr->max_entries) ||
> + !PAGE_ALIGNED(attr->max_entries))
> return ERR_PTR(-EINVAL);
>
> rb_map = kzalloc(sizeof(*rb_map), GFP_USER);
> --
> 2.24.1
>
Powered by blists - more mailing lists