From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CED29C4332F for ; Tue, 22 Nov 2022 22:16:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235078AbiKVWQp (ORCPT ); Tue, 22 Nov 2022 17:16:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233239AbiKVWQo (ORCPT ); Tue, 22 Nov 2022 17:16:44 -0500 Received: from www62.your-server.de (www62.your-server.de [213.133.104.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DB5540471 for ; Tue, 22 Nov 2022 14:16:43 -0800 (PST) Received: from sslproxy06.your-server.de ([78.46.172.3]) by www62.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1oxbZI-000MUg-0A; Tue, 22 Nov 2022 23:16:40 +0100 Received: from [85.1.206.226] (helo=linux.home) by sslproxy06.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oxbZH-000Brd-HP; Tue, 22 Nov 2022 23:16:39 +0100 Subject: Re: [net-next] bpf: avoid the multi checking To: xiangxia.m.yue@gmail.com Cc: netdev@vger.kernel.org, Alexei Starovoitov , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa References: <20221121100521.56601-1-xiangxia.m.yue@gmail.com> From: Daniel Borkmann Message-ID: <642514fd-70d3-384a-5b48-323068174997@iogearbox.net> Date: Tue, 22 Nov 2022 23:16:38 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <20221121100521.56601-1-xiangxia.m.yue@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.103.7/26728/Tue Nov 22 09:14:37 2022) Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On 11/21/22 11:05 AM, xiangxia.m.yue@gmail.com wrote: > From: Tonghao Zhang > > .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 > Cc: Daniel Borkmann > Cc: Andrii Nakryiko > Cc: Martin KaFai Lau > Cc: Song Liu > Cc: Yonghong Song > Cc: John Fastabend > Cc: KP Singh > Cc: Stanislav Fomichev > Cc: Hao Luo > Cc: Jiri Olsa > Signed-off-by: Tonghao Zhang Pls Cc bpf@vger.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; >