mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
selftests/bpf: Cover trusted BTF ID argument provenance
Extend verifier_global_ptr_args.c with calls that pass bare and RCU-protected task pointers to a global __arg_trusted parameter. Both calls must be rejected because neither pointer is referenced or trusted. Add paired test-module kfuncs that return and accept a nullable trusted task pointer. Passing the return value directly must succeed, covering PTR_TRUSTED | PTR_MAYBE_NULL handling in the common argument checker. Signed-off-by: Yiyang Chen <chenyy23@mails.tsinghua.edu.cn> Reviewed-by: Amery Hung <ameryhung@gmail.com> Link: https://lore.kernel.org/bpf/20261007-a3-arg-trusted-v4-v4-2-253ef3a1a69a@mails.tsinghua.edu.cn Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
This commit is contained in:
parent
c3a0bfddae
commit
71b6a960c7
|
|
@ -46,6 +46,17 @@ int iter_next_trusted_or_null(const void *ctx)
|
|||
return 0;
|
||||
}
|
||||
|
||||
SEC("syscall")
|
||||
__success
|
||||
int trusted_nullable_kfunc(const void *ctx)
|
||||
{
|
||||
struct task_struct *task;
|
||||
|
||||
task = bpf_kfunc_trusted_null_test();
|
||||
bpf_kfunc_trusted_nullable_test(task);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEC("raw_tp/sys_enter")
|
||||
__success
|
||||
int iter_next_rcu(const void *ctx)
|
||||
|
|
|
|||
|
|
@ -289,6 +289,41 @@ __weak int subprog_void_untrusted(void *p __arg_untrusted)
|
|||
return *(int *)p;
|
||||
}
|
||||
|
||||
__weak int subprog_trusted_bare(struct task_struct *task __arg_trusted)
|
||||
{
|
||||
return task->pid;
|
||||
}
|
||||
|
||||
SEC("tp_btf/task_newtask")
|
||||
__failure
|
||||
__msg("R1 must be referenced or trusted")
|
||||
__msg("Caller passes invalid args into func#{{.*}} ('subprog_trusted_bare')")
|
||||
int bare_to_trusted(void *ctx)
|
||||
{
|
||||
struct task_struct *cur = bpf_get_current_task_btf();
|
||||
struct task_struct *wakee;
|
||||
|
||||
if (!cur)
|
||||
return 0;
|
||||
wakee = cur->last_wakee;
|
||||
if (!wakee)
|
||||
return 0;
|
||||
return subprog_trusted_bare(wakee);
|
||||
}
|
||||
|
||||
SEC("tp_btf/task_newtask")
|
||||
__failure
|
||||
__msg("R1 must be referenced or trusted")
|
||||
__msg("Caller passes invalid args into func#{{.*}}")
|
||||
int memrcu_to_trusted(void *ctx)
|
||||
{
|
||||
struct task_struct *cur = bpf_get_current_task_btf();
|
||||
|
||||
if (!cur)
|
||||
return 0;
|
||||
return subprog_trusted_task_nullable(cur->real_parent);
|
||||
}
|
||||
|
||||
__weak int subprog_char_untrusted(char *p __arg_untrusted)
|
||||
{
|
||||
return *(int *)p;
|
||||
|
|
|
|||
|
|
@ -350,6 +350,15 @@ __bpf_kfunc void bpf_kfunc_trusted_task_test(struct task_struct *ptr)
|
|||
{
|
||||
}
|
||||
|
||||
__bpf_kfunc struct task_struct *bpf_kfunc_trusted_null_test(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
__bpf_kfunc void bpf_kfunc_trusted_nullable_test(struct task_struct *ptr__nullable)
|
||||
{
|
||||
}
|
||||
|
||||
__bpf_kfunc void bpf_kfunc_trusted_num_test(int *ptr)
|
||||
{
|
||||
}
|
||||
|
|
@ -957,6 +966,8 @@ BTF_ID_FLAGS(func, bpf_kfunc_nested_acquire_zero_offset_test, KF_ACQUIRE)
|
|||
BTF_ID_FLAGS(func, bpf_kfunc_nested_release_test, KF_RELEASE)
|
||||
BTF_ID_FLAGS(func, bpf_kfunc_trusted_vma_test)
|
||||
BTF_ID_FLAGS(func, bpf_kfunc_trusted_task_test)
|
||||
BTF_ID_FLAGS(func, bpf_kfunc_trusted_null_test, KF_RET_NULL)
|
||||
BTF_ID_FLAGS(func, bpf_kfunc_trusted_nullable_test)
|
||||
BTF_ID_FLAGS(func, bpf_kfunc_trusted_num_test)
|
||||
BTF_ID_FLAGS(func, bpf_kfunc_rcu_task_test, KF_RCU)
|
||||
BTF_ID_FLAGS(func, bpf_kfunc_ret_rcu_test, KF_RET_NULL | KF_RCU_PROTECTED)
|
||||
|
|
|
|||
|
|
@ -353,6 +353,8 @@ int bpf_kfunc_st_ops_inc10(struct st_ops_args *args) __ksym;
|
|||
|
||||
void bpf_kfunc_trusted_vma_test(struct vm_area_struct *ptr) __ksym;
|
||||
void bpf_kfunc_trusted_task_test(struct task_struct *ptr) __ksym;
|
||||
struct task_struct *bpf_kfunc_trusted_null_test(void) __ksym;
|
||||
void bpf_kfunc_trusted_nullable_test(struct task_struct *ptr__nullable) __ksym;
|
||||
void bpf_kfunc_trusted_num_test(int *ptr) __ksym;
|
||||
void bpf_kfunc_rcu_task_test(struct task_struct *ptr) __ksym;
|
||||
struct task_struct *bpf_kfunc_ret_rcu_test(void) __ksym;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user