[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <285e32b1-daa5-1be4-5939-c86249680311@iogearbox.net>
Date: Tue, 30 Jun 2020 16:52:47 +0200
From: Daniel Borkmann <daniel@...earbox.net>
To: Andrii Nakryiko <andriin@...com>, bpf@...r.kernel.org,
netdev@...r.kernel.org, ast@...com
Cc: andrii.nakryiko@...il.com, kernel-team@...com
Subject: Re: [PATCH v2 bpf] bpf: enforce BPF ringbuf size to be the power of 2
On 6/30/20 8:15 AM, Andrii Nakryiko 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>
Lgtm, applied, thanks!
[...]
> @@ -166,9 +157,16 @@ 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))
Technically !IS_ALIGNED(attr->max_entries, PAGE_SIZE) might have been a bit cleaner
since PAGE_ALIGNED() is only intended for pointers, though, not wrong here given
max_entries is u32.
Thanks,
Daniel
Powered by blists - more mailing lists