Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

bpf: use type_may_be_null() helper for nullable-param check

Commit 980ca8ceeae6 ("bpf: check bpf_dummy_struct_ops program params for
test runs") does bitwise AND between reg_type and PTR_MAYBE_NULL, which
is correct, but due to type difference the compiler complains:

net/bpf/bpf_dummy_struct_ops.c:118:31: warning: bitwise operation between different enumeration types ('const enum bpf_reg_type' and 'enum bpf_type_flag') [-Wenum-enum-conversion]
118 | if (info && (info->reg_type & PTR_MAYBE_NULL))
| ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~

Workaround the warning by moving the type_may_be_null() helper from
verifier.c into bpf_verifier.h, and reuse it here to check whether param
is nullable.

Fixes: 980ca8ceeae6 ("bpf: check bpf_dummy_struct_ops program params for test runs")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202404241956.HEiRYwWq-lkp@intel.com/
Signed-off-by: Shung-Hsi Yu <shung-hsi.yu@suse.com>
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/r/20240905055233.70203-1-shung-hsi.yu@suse.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Shung-Hsi Yu and committed by
Alexei Starovoitov
1ae497c7 b9d32677

+6 -6
+5
include/linux/bpf_verifier.h
··· 927 927 type == PTR_TO_XDP_SOCK; 928 928 } 929 929 930 + static inline bool type_may_be_null(u32 type) 931 + { 932 + return type & PTR_MAYBE_NULL; 933 + } 934 + 930 935 static inline void mark_reg_scratched(struct bpf_verifier_env *env, u32 regno) 931 936 { 932 937 env->scratched_regs |= 1U << regno;
-5
kernel/bpf/verifier.c
··· 383 383 verbose(env, " should have been in [%d, %d]\n", range.minval, range.maxval); 384 384 } 385 385 386 - static bool type_may_be_null(u32 type) 387 - { 388 - return type & PTR_MAYBE_NULL; 389 - } 390 - 391 386 static bool reg_not_null(const struct bpf_reg_state *reg) 392 387 { 393 388 enum bpf_reg_type type;
+1 -1
net/bpf/bpf_dummy_struct_ops.c
··· 115 115 116 116 offset = btf_ctx_arg_offset(bpf_dummy_ops_btf, func_proto, arg_no); 117 117 info = find_ctx_arg_info(prog->aux, offset); 118 - if (info && (info->reg_type & PTR_MAYBE_NULL)) 118 + if (info && type_may_be_null(info->reg_type)) 119 119 continue; 120 120 121 121 return -EINVAL;