Skip to content

Commit 1ae497c

Browse files
shunghsiyuAlexei Starovoitov
authored andcommitted
bpf: use type_may_be_null() helper for nullable-param check
Commit 980ca8c ("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: 980ca8c ("bpf: check bpf_dummy_struct_ops program params for test runs") Reported-by: kernel test robot <[email protected]> Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/ Signed-off-by: Shung-Hsi Yu <[email protected]> Acked-by: Eduard Zingerman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent b9d3267 commit 1ae497c

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

include/linux/bpf_verifier.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,11 @@ static inline bool type_is_sk_pointer(enum bpf_reg_type type)
927927
type == PTR_TO_XDP_SOCK;
928928
}
929929

930+
static inline bool type_may_be_null(u32 type)
931+
{
932+
return type & PTR_MAYBE_NULL;
933+
}
934+
930935
static inline void mark_reg_scratched(struct bpf_verifier_env *env, u32 regno)
931936
{
932937
env->scratched_regs |= 1U << regno;

kernel/bpf/verifier.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -383,11 +383,6 @@ static void verbose_invalid_scalar(struct bpf_verifier_env *env,
383383
verbose(env, " should have been in [%d, %d]\n", range.minval, range.maxval);
384384
}
385385

386-
static bool type_may_be_null(u32 type)
387-
{
388-
return type & PTR_MAYBE_NULL;
389-
}
390-
391386
static bool reg_not_null(const struct bpf_reg_state *reg)
392387
{
393388
enum bpf_reg_type type;

net/bpf/bpf_dummy_struct_ops.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ static int check_test_run_args(struct bpf_prog *prog, struct bpf_dummy_ops_test_
115115

116116
offset = btf_ctx_arg_offset(bpf_dummy_ops_btf, func_proto, arg_no);
117117
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))
119119
continue;
120120

121121
return -EINVAL;

0 commit comments

Comments
 (0)