mirror of
https://github.com/torvalds/linux.git
synced 2026-06-04 12:35:52 +02:00
Merge branch 'bpf-allow-access-to-const-void-pointer-arguments-in-tracing-programs'
KaFai Wan says: ==================== bpf: Allow access to const void pointer arguments in tracing programs If we try to access argument which is pointer to const void, it's an UNKNOWN type, verifier will fail to load. Use is_void_or_int_ptr to check if type is void or int pointer. Add a selftest to check it. --- ==================== Link: https://patch.msgid.link/20250423121329.3163461-1-mannkafai@gmail.com Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
This commit is contained in:
commit
b9c09fb206
|
|
@ -6383,12 +6383,11 @@ struct btf *bpf_prog_get_target_btf(const struct bpf_prog *prog)
|
|||
return prog->aux->attach_btf;
|
||||
}
|
||||
|
||||
static bool is_int_ptr(struct btf *btf, const struct btf_type *t)
|
||||
static bool is_void_or_int_ptr(struct btf *btf, const struct btf_type *t)
|
||||
{
|
||||
/* skip modifiers */
|
||||
t = btf_type_skip_modifiers(btf, t->type, NULL);
|
||||
|
||||
return btf_type_is_int(t);
|
||||
return btf_type_is_void(t) || btf_type_is_int(t);
|
||||
}
|
||||
|
||||
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,
|
|||
}
|
||||
}
|
||||
|
||||
if (t->type == 0)
|
||||
/* This is a pointer to void.
|
||||
* It is the same as scalar from the verifier safety pov.
|
||||
* No further pointer walking is allowed.
|
||||
*/
|
||||
return true;
|
||||
|
||||
if (is_int_ptr(btf, t))
|
||||
/*
|
||||
* If it's a pointer to void, it's the same as scalar from the verifier
|
||||
* safety POV. Either way, no futher pointer walking is allowed.
|
||||
*/
|
||||
if (is_void_or_int_ptr(btf, t))
|
||||
return true;
|
||||
|
||||
/* this is a pointer to another type */
|
||||
|
|
|
|||
|
|
@ -569,6 +569,11 @@ __bpf_kfunc u32 bpf_fentry_test9(u32 *a)
|
|||
return *a;
|
||||
}
|
||||
|
||||
int noinline bpf_fentry_test10(const void *a)
|
||||
{
|
||||
return (long)a;
|
||||
}
|
||||
|
||||
void noinline bpf_fentry_test_sinfo(struct skb_shared_info *sinfo)
|
||||
{
|
||||
}
|
||||
|
|
@ -699,7 +704,8 @@ int bpf_prog_test_run_tracing(struct bpf_prog *prog,
|
|||
bpf_fentry_test6(16, (void *)17, 18, 19, (void *)20, 21) != 111 ||
|
||||
bpf_fentry_test7((struct bpf_fentry_test_t *)0) != 0 ||
|
||||
bpf_fentry_test8(&arg) != 0 ||
|
||||
bpf_fentry_test9(&retval) != 0)
|
||||
bpf_fentry_test9(&retval) != 0 ||
|
||||
bpf_fentry_test10((void *)0) != 0)
|
||||
goto out;
|
||||
break;
|
||||
case BPF_MODIFY_RETURN:
|
||||
|
|
|
|||
|
|
@ -65,4 +65,16 @@ __naked void ctx_access_u32_pointer_reject_8(void)
|
|||
" ::: __clobber_all);
|
||||
}
|
||||
|
||||
SEC("fentry/bpf_fentry_test10")
|
||||
__description("btf_ctx_access const void pointer accept")
|
||||
__success __retval(0)
|
||||
__naked void ctx_access_const_void_pointer_accept(void)
|
||||
{
|
||||
asm volatile (" \
|
||||
r2 = *(u64 *)(r1 + 0); /* load 1st argument value (const void pointer) */\
|
||||
r0 = 0; \
|
||||
exit; \
|
||||
" ::: __clobber_all);
|
||||
}
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user