Skip to content

Commit

Permalink
bpf: mark PTR_TO_MEM as non-null register type
Browse files Browse the repository at this point in the history
PTR_TO_MEM register without PTR_MAYBE_NULL is indeed non-null. This is
important for BPF verifier to be able to prune guaranteed not to be
taken branches. This is always the case with open-coded iterators.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20230302235015.2044271-11-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
  • Loading branch information
Andrii Nakryiko authored and Alexei Starovoitov committed Mar 4, 2023
1 parent d0e1ac2 commit d5271c5
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion kernel/bpf/verifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,8 @@ static bool reg_type_not_null(enum bpf_reg_type type)
type == PTR_TO_TCP_SOCK ||
type == PTR_TO_MAP_VALUE ||
type == PTR_TO_MAP_KEY ||
type == PTR_TO_SOCK_COMMON;
type == PTR_TO_SOCK_COMMON ||
type == PTR_TO_MEM;
}

static bool type_is_ptr_alloc_obj(u32 type)
Expand Down

0 comments on commit d5271c5

Please sign in to comment.