Skip to content

Commit db8eae6

Browse files
olsajiriborkmann
authored andcommitted
bpf: Force kprobe multi expected_attach_type for kprobe_multi link
We currently allow to create perf link for program with expected_attach_type == BPF_TRACE_KPROBE_MULTI. This will cause crash when we call helpers like get_attach_cookie or get_func_ip in such program, because it will call the kprobe_multi's version (current->bpf_ctx context setup) of those helpers while it expects perf_link's current->bpf_ctx context setup. Making sure that we use BPF_TRACE_KPROBE_MULTI expected_attach_type only for programs attaching through kprobe_multi link. Fixes: ca74823 ("bpf: Add cookie support to programs attached with kprobe multi link") Signed-off-by: Jiri Olsa <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 9724160 commit db8eae6

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

kernel/bpf/syscall.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3440,6 +3440,11 @@ static int bpf_prog_attach_check_attach_type(const struct bpf_prog *prog,
34403440
return prog->enforce_expected_attach_type &&
34413441
prog->expected_attach_type != attach_type ?
34423442
-EINVAL : 0;
3443+
case BPF_PROG_TYPE_KPROBE:
3444+
if (prog->expected_attach_type == BPF_TRACE_KPROBE_MULTI &&
3445+
attach_type != BPF_TRACE_KPROBE_MULTI)
3446+
return -EINVAL;
3447+
return 0;
34433448
default:
34443449
return 0;
34453450
}

0 commit comments

Comments
 (0)