Skip to content

Commit 0789e13

Browse files
lmbAlexei Starovoitov
authored andcommitted
bpf: Explicitly size compatible_reg_types
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. Suggested-by: Alexei Starovoitov <[email protected]> Signed-off-by: Lorenz Bauer <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent a8a7179 commit 0789e13

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

kernel/bpf/verifier.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4002,7 +4002,7 @@ static const struct bpf_reg_types const_map_ptr_types = { .types = { CONST_PTR_T
40024002
static const struct bpf_reg_types btf_ptr_types = { .types = { PTR_TO_BTF_ID } };
40034003
static const struct bpf_reg_types spin_lock_types = { .types = { PTR_TO_MAP_VALUE } };
40044004

4005-
static const struct bpf_reg_types *compatible_reg_types[] = {
4005+
static const struct bpf_reg_types *compatible_reg_types[__BPF_ARG_TYPE_MAX] = {
40064006
[ARG_PTR_TO_MAP_KEY] = &map_key_value_types,
40074007
[ARG_PTR_TO_MAP_VALUE] = &map_key_value_types,
40084008
[ARG_PTR_TO_UNINIT_MAP_VALUE] = &map_key_value_types,
@@ -4025,7 +4025,6 @@ static const struct bpf_reg_types *compatible_reg_types[] = {
40254025
[ARG_PTR_TO_ALLOC_MEM_OR_NULL] = &alloc_mem_types,
40264026
[ARG_PTR_TO_INT] = &int_ptr_types,
40274027
[ARG_PTR_TO_LONG] = &int_ptr_types,
4028-
[__BPF_ARG_TYPE_MAX] = NULL,
40294028
};
40304029

40314030
static int check_reg_type(struct bpf_verifier_env *env, u32 regno,

0 commit comments

Comments
 (0)