[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <642514fd-70d3-384a-5b48-323068174997@iogearbox.net>
Date: Tue, 22 Nov 2022 23:16:38 +0100
From: Daniel Borkmann <daniel@...earbox.net>
To: xiangxia.m.yue@...il.com
Cc: netdev@...r.kernel.org, Alexei Starovoitov <ast@...nel.org>,
Andrii Nakryiko <andrii@...nel.org>,
Martin KaFai Lau <martin.lau@...ux.dev>,
Song Liu <song@...nel.org>, Yonghong Song <yhs@...com>,
John Fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...nel.org>,
Stanislav Fomichev <sdf@...gle.com>,
Hao Luo <haoluo@...gle.com>, Jiri Olsa <jolsa@...nel.org>
Subject: Re: [net-next] bpf: avoid the multi checking
On 11/21/22 11:05 AM, xiangxia.m.yue@...il.com wrote:
> From: Tonghao Zhang <xiangxia.m.yue@...il.com>
>
> .map_alloc_check checked bpf_attr::max_entries, and if bpf_attr::max_entries
> == 0, return -EINVAL. bpf_htab::n_buckets will not be 0, while -E2BIG is not
> appropriate.
>
> Cc: Alexei Starovoitov <ast@...nel.org>
> Cc: Daniel Borkmann <daniel@...earbox.net>
> Cc: Andrii Nakryiko <andrii@...nel.org>
> Cc: Martin KaFai Lau <martin.lau@...ux.dev>
> Cc: Song Liu <song@...nel.org>
> Cc: Yonghong Song <yhs@...com>
> Cc: John Fastabend <john.fastabend@...il.com>
> Cc: KP Singh <kpsingh@...nel.org>
> Cc: Stanislav Fomichev <sdf@...gle.com>
> Cc: Hao Luo <haoluo@...gle.com>
> Cc: Jiri Olsa <jolsa@...nel.org>
> Signed-off-by: Tonghao Zhang <xiangxia.m.yue@...il.com>
Pls Cc bpf@...r.kernel.org list and $subj line should target bpf-next.
> ---
> kernel/bpf/hashtab.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c
> index 50d254cd0709..22855d6ff6d3 100644
> --- a/kernel/bpf/hashtab.c
> +++ b/kernel/bpf/hashtab.c
> @@ -500,9 +500,10 @@ static struct bpf_map *htab_map_alloc(union bpf_attr *attr)
> htab->elem_size += round_up(htab->map.value_size, 8);
>
> err = -E2BIG;
> - /* prevent zero size kmalloc and check for u32 overflow */
> - if (htab->n_buckets == 0 ||
> - htab->n_buckets > U32_MAX / sizeof(struct bucket))
> + /* avoid zero size and u32 overflow kmalloc.
> + * bpf_attr::max_entries checked in .map_alloc_check().
> + */
> + if (htab->n_buckets > U32_MAX / sizeof(struct bucket))
This looks buggy to remove it, this is to guard against the previous
roundup_pow_of_two() on htab->n_buckets.
> goto free_htab;
>
> err = -ENOMEM;
>
Powered by blists - more mailing lists