mirror of
https://github.com/torvalds/linux.git
synced 2026-09-14 16:10:02 +02:00
selftests/bpf: Check faultable stack helper contexts
Add verifier coverage for the sleepable bpf_get_stack() and bpf_get_task_stack() implementations. Call each helper while preemption is disabled and require the verifier to reject it as sleepable. Both programs load when the prototypes lack might_sleep, so the expected-failure tests fail. Keep success controls outside the non-preemptible region to ensure ordinary calls from sleepable uprobes remain valid. Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> Link: https://lore.kernel.org/r/20260903214758.2727663-7-memxor@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
9d02927fdf
commit
1ba0d0d8b6
|
|
@ -115,6 +115,58 @@ int preempt_sleepable_helper(void *ctx)
|
|||
return 0;
|
||||
}
|
||||
|
||||
SEC("?uprobe.s")
|
||||
__failure __msg("sleepable helper bpf_get_stack#")
|
||||
int preempt_sleepable_get_stack(struct pt_regs *ctx)
|
||||
{
|
||||
struct bpf_stack_build_id stack;
|
||||
|
||||
bpf_preempt_disable();
|
||||
bpf_get_stack(ctx, &stack, sizeof(stack),
|
||||
BPF_F_USER_STACK | BPF_F_USER_BUILD_ID);
|
||||
bpf_preempt_enable();
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEC("?uprobe.s")
|
||||
__failure __msg("sleepable helper bpf_get_task_stack#")
|
||||
int preempt_sleepable_get_task_stack(void *ctx)
|
||||
{
|
||||
struct bpf_stack_build_id stack;
|
||||
struct task_struct *task;
|
||||
|
||||
task = bpf_get_current_task_btf();
|
||||
bpf_preempt_disable();
|
||||
bpf_get_task_stack(task, &stack, sizeof(stack),
|
||||
BPF_F_USER_STACK | BPF_F_USER_BUILD_ID);
|
||||
bpf_preempt_enable();
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEC("?uprobe.s")
|
||||
__success
|
||||
int sleepable_get_stack(struct pt_regs *ctx)
|
||||
{
|
||||
struct bpf_stack_build_id stack;
|
||||
|
||||
bpf_get_stack(ctx, &stack, sizeof(stack),
|
||||
BPF_F_USER_STACK | BPF_F_USER_BUILD_ID);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEC("?uprobe.s")
|
||||
__success
|
||||
int sleepable_get_task_stack(void *ctx)
|
||||
{
|
||||
struct bpf_stack_build_id stack;
|
||||
struct task_struct *task;
|
||||
|
||||
task = bpf_get_current_task_btf();
|
||||
bpf_get_task_stack(task, &stack, sizeof(stack),
|
||||
BPF_F_USER_STACK | BPF_F_USER_BUILD_ID);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEC("?fentry.s/" SYS_PREFIX "sys_getpgid")
|
||||
__failure __msg("kernel func bpf_copy_from_user_str is sleepable within non-preemptible region")
|
||||
int preempt_sleepable_kfunc(void *ctx)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user