]> git.dujemihanovic.xyz Git - linux.git/commitdiff
bpf: Force kprobe multi expected_attach_type for kprobe_multi link
authorJiri Olsa <jolsa@kernel.org>
Sun, 18 Jun 2023 13:14:14 +0000 (15:14 +0200)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 21 Jun 2023 08:40:26 +0000 (10:40 +0200)
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: ca74823c6e16 ("bpf: Add cookie support to programs attached with kprobe multi link")
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20230618131414.75649-1-jolsa@kernel.org
kernel/bpf/syscall.c

index 0c21d0d8efe492d32ea6b87483eccd8fb1e4bcd3..f1c8733f76b83581fdeafc5022020f15efec28a5 100644 (file)
@@ -3440,6 +3440,11 @@ static int bpf_prog_attach_check_attach_type(const struct bpf_prog *prog,
                return prog->enforce_expected_attach_type &&
                        prog->expected_attach_type != attach_type ?
                        -EINVAL : 0;
+       case BPF_PROG_TYPE_KPROBE:
+               if (prog->expected_attach_type == BPF_TRACE_KPROBE_MULTI &&
+                   attach_type != BPF_TRACE_KPROBE_MULTI)
+                       return -EINVAL;
+               return 0;
        default:
                return 0;
        }