Skip to content

Commit 9095202

Browse files
committed
bpf: allow pointers for ARG_ANYTHING parameters of global functions
The goal of the commit is to simplify writing global functions that convert their operands to read-only probed memory using bpf_rdonly_cast(). Depending on the context such parameters might be either pointers or scalars. E.g. here is how scalar parameters might occur: ... // `task` is `PTR_TO_BTF_ID` task = bpf_get_current_task_btf(); // .name is defined as `char *` name = task->mm->exe_file->f_path.dentry->d_name.name; global_fn(name); Verifier considers `name` to be a scalar because of how `btf_struct_access` and `btf_struct_walk` process paths that end up with pointers to non-struct types: such pointers are considered to be scalar values. This commit allows declaring global_fn as `global_fn(u64)` and pass both pointers and scalars as in the example above as parameters of the `global_fn`. Suggested-by: Andrii Nakryiko <[email protected]> Signed-off-by: Eduard Zingerman <[email protected]>
1 parent 0256bad commit 9095202

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

kernel/bpf/verifier.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10401,7 +10401,10 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env, int subprog,
1040110401
struct bpf_subprog_arg_info *arg = &sub->args[i];
1040210402

1040310403
if (arg->arg_type == ARG_ANYTHING) {
10404-
if (reg->type != SCALAR_VALUE) {
10404+
if (reg->type == NOT_INIT) {
10405+
bpf_log(log, "parameter R%d is not initialized\n", regno);
10406+
return -EINVAL;
10407+
} else if (!env->allow_ptr_leaks && reg->type != SCALAR_VALUE) {
1040510408
bpf_log(log, "R%d is not a scalar\n", regno);
1040610409
return -EINVAL;
1040710410
}

0 commit comments

Comments
 (0)