From: Alexei Starovoitov Date: Tue, 21 Mar 2023 20:38:52 +0000 (-0700) Subject: bpf: Teach the verifier to recognize rdonly_mem as not null. X-Git-Tag: v6.6.7~2736^2~129^2~68^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1057d299459657b85e593a4b6294a000f920672a;p=platform%2Fkernel%2Flinux-starfive.git bpf: Teach the verifier to recognize rdonly_mem as not null. Teach the verifier to recognize PTR_TO_MEM | MEM_RDONLY as not NULL otherwise if (!bpf_ksym_exists(known_kfunc)) doesn't go through dead code elimination. Signed-off-by: Alexei Starovoitov Signed-off-by: Andrii Nakryiko Acked-by: David Vernet Link: https://lore.kernel.org/bpf/20230321203854.3035-3-alexei.starovoitov@gmail.com --- diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 8bc44f5..5693e4a 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -486,8 +486,17 @@ static bool type_is_sk_pointer(enum bpf_reg_type type) type == PTR_TO_XDP_SOCK; } +static bool type_may_be_null(u32 type) +{ + return type & PTR_MAYBE_NULL; +} + static bool reg_type_not_null(enum bpf_reg_type type) { + if (type_may_be_null(type)) + return false; + + type = base_type(type); return type == PTR_TO_SOCKET || type == PTR_TO_TCP_SOCK || type == PTR_TO_MAP_VALUE || @@ -531,11 +540,6 @@ static bool type_is_rdonly_mem(u32 type) return type & MEM_RDONLY; } -static bool type_may_be_null(u32 type) -{ - return type & PTR_MAYBE_NULL; -} - static bool is_acquire_function(enum bpf_func_id func_id, const struct bpf_map *map) {