linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] bpf: explicitly size compatible_reg_types
@ 2020-09-23 16:01 Lorenz Bauer
  2020-09-23 16:05 ` Andrii Nakryiko
  0 siblings, 1 reply; 3+ messages in thread
From: Lorenz Bauer @ 2020-09-23 16:01 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann
  Cc: kernel-team, Lorenz Bauer, netdev, bpf, linux-kernel

Arrays with designated initializers have an implicit length of the highest
initialized value plus one. I used this to ensure that newly added entries
in enum bpf_reg_type get a NULL entry in compatible_reg_types.

This is difficult to understand since it requires knowledge of the
peculiarities of designated initializers. Use __BPF_ARG_TYPE_MAX to size
the array instead.

Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
Suggested-by: Alexei Starovoitov <ast@kernel.org>
---
 kernel/bpf/verifier.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 15ab889b0a3f..d7c993ded26a 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -4002,7 +4002,7 @@ static const struct bpf_reg_types const_map_ptr_types = { .types = { CONST_PTR_T
 static const struct bpf_reg_types btf_ptr_types = { .types = { PTR_TO_BTF_ID } };
 static const struct bpf_reg_types spin_lock_types = { .types = { PTR_TO_MAP_VALUE } };
 
-static const struct bpf_reg_types *compatible_reg_types[] = {
+static const struct bpf_reg_types *compatible_reg_types[__BPF_ARG_TYPE_MAX] = {
 	[ARG_PTR_TO_MAP_KEY]		= &map_key_value_types,
 	[ARG_PTR_TO_MAP_VALUE]		= &map_key_value_types,
 	[ARG_PTR_TO_UNINIT_MAP_VALUE]	= &map_key_value_types,
@@ -4025,7 +4025,6 @@ static const struct bpf_reg_types *compatible_reg_types[] = {
 	[ARG_PTR_TO_ALLOC_MEM_OR_NULL]	= &alloc_mem_types,
 	[ARG_PTR_TO_INT]		= &int_ptr_types,
 	[ARG_PTR_TO_LONG]		= &int_ptr_types,
-	[__BPF_ARG_TYPE_MAX]		= NULL,
 };
 
 static int check_reg_type(struct bpf_verifier_env *env, u32 regno,
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next] bpf: explicitly size compatible_reg_types
  2020-09-23 16:01 [PATCH bpf-next] bpf: explicitly size compatible_reg_types Lorenz Bauer
@ 2020-09-23 16:05 ` Andrii Nakryiko
  2020-09-23 18:49   ` Alexei Starovoitov
  0 siblings, 1 reply; 3+ messages in thread
From: Andrii Nakryiko @ 2020-09-23 16:05 UTC (permalink / raw)
  To: Lorenz Bauer
  Cc: Alexei Starovoitov, Daniel Borkmann, kernel-team, Networking,
	bpf, open list

On Wed, Sep 23, 2020 at 9:03 AM Lorenz Bauer <lmb@cloudflare.com> wrote:
>
> Arrays with designated initializers have an implicit length of the highest
> initialized value plus one. I used this to ensure that newly added entries
> in enum bpf_reg_type get a NULL entry in compatible_reg_types.
>
> This is difficult to understand since it requires knowledge of the
> peculiarities of designated initializers. Use __BPF_ARG_TYPE_MAX to size
> the array instead.
>
> Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
> Suggested-by: Alexei Starovoitov <ast@kernel.org>
> ---

I like this more as well.

Acked-by: Andrii Nakryiko <andriin@fb.com>

>  kernel/bpf/verifier.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 15ab889b0a3f..d7c993ded26a 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -4002,7 +4002,7 @@ static const struct bpf_reg_types const_map_ptr_types = { .types = { CONST_PTR_T
>  static const struct bpf_reg_types btf_ptr_types = { .types = { PTR_TO_BTF_ID } };
>  static const struct bpf_reg_types spin_lock_types = { .types = { PTR_TO_MAP_VALUE } };
>
> -static const struct bpf_reg_types *compatible_reg_types[] = {
> +static const struct bpf_reg_types *compatible_reg_types[__BPF_ARG_TYPE_MAX] = {
>         [ARG_PTR_TO_MAP_KEY]            = &map_key_value_types,
>         [ARG_PTR_TO_MAP_VALUE]          = &map_key_value_types,
>         [ARG_PTR_TO_UNINIT_MAP_VALUE]   = &map_key_value_types,
> @@ -4025,7 +4025,6 @@ static const struct bpf_reg_types *compatible_reg_types[] = {
>         [ARG_PTR_TO_ALLOC_MEM_OR_NULL]  = &alloc_mem_types,
>         [ARG_PTR_TO_INT]                = &int_ptr_types,
>         [ARG_PTR_TO_LONG]               = &int_ptr_types,
> -       [__BPF_ARG_TYPE_MAX]            = NULL,
>  };
>
>  static int check_reg_type(struct bpf_verifier_env *env, u32 regno,
> --
> 2.25.1
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next] bpf: explicitly size compatible_reg_types
  2020-09-23 16:05 ` Andrii Nakryiko
@ 2020-09-23 18:49   ` Alexei Starovoitov
  0 siblings, 0 replies; 3+ messages in thread
From: Alexei Starovoitov @ 2020-09-23 18:49 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: Lorenz Bauer, Alexei Starovoitov, Daniel Borkmann, kernel-team,
	Networking, bpf, open list

On Wed, Sep 23, 2020 at 9:05 AM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Wed, Sep 23, 2020 at 9:03 AM Lorenz Bauer <lmb@cloudflare.com> wrote:
> >
> > Arrays with designated initializers have an implicit length of the highest
> > initialized value plus one. I used this to ensure that newly added entries
> > in enum bpf_reg_type get a NULL entry in compatible_reg_types.
> >
> > This is difficult to understand since it requires knowledge of the
> > peculiarities of designated initializers. Use __BPF_ARG_TYPE_MAX to size
> > the array instead.
> >
> > Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
> > Suggested-by: Alexei Starovoitov <ast@kernel.org>
> > ---
>
> I like this more as well.
>
> Acked-by: Andrii Nakryiko <andriin@fb.com>

Applied. Thanks

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-09-23 18:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-23 16:01 [PATCH bpf-next] bpf: explicitly size compatible_reg_types Lorenz Bauer
2020-09-23 16:05 ` Andrii Nakryiko
2020-09-23 18:49   ` Alexei Starovoitov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).