Skip to content

Commit 1271a40

Browse files
mannkafaianakryiko
authored andcommitted
bpf: Allow access to const void pointer arguments in tracing programs
Adding support to access arguments with const void pointer arguments in tracing programs. Currently we allow tracing programs to access void pointers. If we try to access argument which is pointer to const void like 2nd argument in kfree, verifier will fail to load the program with; 0: R1=ctx() R10=fp0 ; asm volatile ("r2 = *(u64 *)(r1 + 8); "); 0: (79) r2 = *(u64 *)(r1 +8) func 'kfree' arg1 type UNKNOWN is not a struct Changing the is_int_ptr to void and generic integer check and renaming it to is_void_or_int_ptr. Signed-off-by: KaFai Wan <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Acked-by: Jiri Olsa <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 6aca583 commit 1271a40

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

kernel/bpf/btf.c

+7-11
Original file line numberDiff line numberDiff line change
@@ -6383,12 +6383,11 @@ struct btf *bpf_prog_get_target_btf(const struct bpf_prog *prog)
63836383
return prog->aux->attach_btf;
63846384
}
63856385

6386-
static bool is_int_ptr(struct btf *btf, const struct btf_type *t)
6386+
static bool is_void_or_int_ptr(struct btf *btf, const struct btf_type *t)
63876387
{
63886388
/* skip modifiers */
63896389
t = btf_type_skip_modifiers(btf, t->type, NULL);
6390-
6391-
return btf_type_is_int(t);
6390+
return btf_type_is_void(t) || btf_type_is_int(t);
63926391
}
63936392

63946393
static u32 get_ctx_arg_idx(struct btf *btf, const struct btf_type *func_proto,
@@ -6776,14 +6775,11 @@ bool btf_ctx_access(int off, int size, enum bpf_access_type type,
67766775
}
67776776
}
67786777

6779-
if (t->type == 0)
6780-
/* This is a pointer to void.
6781-
* It is the same as scalar from the verifier safety pov.
6782-
* No further pointer walking is allowed.
6783-
*/
6784-
return true;
6785-
6786-
if (is_int_ptr(btf, t))
6778+
/*
6779+
* If it's a pointer to void, it's the same as scalar from the verifier
6780+
* safety POV. Either way, no futher pointer walking is allowed.
6781+
*/
6782+
if (is_void_or_int_ptr(btf, t))
67876783
return true;
67886784

67896785
/* this is a pointer to another type */

0 commit comments

Comments
 (0)