mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-15 00:04:15 +08:00
bpf: use type_may_be_null() helper for nullable-param check
Commit980ca8ceea
("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:980ca8ceea
("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>
This commit is contained in:
parent
b9d32677ff
commit
1ae497c78f
@ -927,6 +927,11 @@ static inline bool type_is_sk_pointer(enum bpf_reg_type type)
|
|||||||
type == PTR_TO_XDP_SOCK;
|
type == PTR_TO_XDP_SOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool type_may_be_null(u32 type)
|
||||||
|
{
|
||||||
|
return type & PTR_MAYBE_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static inline void mark_reg_scratched(struct bpf_verifier_env *env, u32 regno)
|
static inline void mark_reg_scratched(struct bpf_verifier_env *env, u32 regno)
|
||||||
{
|
{
|
||||||
env->scratched_regs |= 1U << regno;
|
env->scratched_regs |= 1U << regno;
|
||||||
|
@ -383,11 +383,6 @@ static void verbose_invalid_scalar(struct bpf_verifier_env *env,
|
|||||||
verbose(env, " should have been in [%d, %d]\n", range.minval, range.maxval);
|
verbose(env, " should have been in [%d, %d]\n", range.minval, range.maxval);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool type_may_be_null(u32 type)
|
|
||||||
{
|
|
||||||
return type & PTR_MAYBE_NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool reg_not_null(const struct bpf_reg_state *reg)
|
static bool reg_not_null(const struct bpf_reg_state *reg)
|
||||||
{
|
{
|
||||||
enum bpf_reg_type type;
|
enum bpf_reg_type type;
|
||||||
|
@ -115,7 +115,7 @@ static int check_test_run_args(struct bpf_prog *prog, struct bpf_dummy_ops_test_
|
|||||||
|
|
||||||
offset = btf_ctx_arg_offset(bpf_dummy_ops_btf, func_proto, arg_no);
|
offset = btf_ctx_arg_offset(bpf_dummy_ops_btf, func_proto, arg_no);
|
||||||
info = find_ctx_arg_info(prog->aux, offset);
|
info = find_ctx_arg_info(prog->aux, offset);
|
||||||
if (info && (info->reg_type & PTR_MAYBE_NULL))
|
if (info && type_may_be_null(info->reg_type))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
Loading…
Reference in New Issue
Block a user