bpf: Adjust kprobe_multi entry_ip for CONFIG_X86_KERNEL_IBT
authorJiri Olsa <jolsa@kernel.org>
Mon, 26 Sep 2022 15:33:38 +0000 (17:33 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 27 Sep 2022 03:30:39 +0000 (20:30 -0700)
commitc09eb2e578eb1668bbc84dc07e8d8bd6f04b9a02
tree9973e5887e6c902a44b5bf096a775a8ffd372ab2
parent4d854f4f31ec4b317dfe316111ddac0fab81f735
bpf: Adjust kprobe_multi entry_ip for CONFIG_X86_KERNEL_IBT

Martynas reported bpf_get_func_ip returning +4 address when
CONFIG_X86_KERNEL_IBT option is enabled.

When CONFIG_X86_KERNEL_IBT is enabled we'll have endbr instruction
at the function entry, which screws return value of bpf_get_func_ip()
helper that should return the function address.

There's short term workaround for kprobe_multi bpf program made by
Alexei [1], but we need this fixup also for bpf_get_attach_cookie,
that returns cookie based on the entry_ip value.

Moving the fixup in the fprobe handler, so both bpf_get_func_ip
and bpf_get_attach_cookie get expected function address when
CONFIG_X86_KERNEL_IBT option is enabled.

Also renaming kprobe_multi_link_handler entry_ip argument to fentry_ip
so it's clearer this is an ftrace __fentry__ ip.

[1] commit 7f0059b58f02 ("selftests/bpf: Fix kprobe_multi test.")

Cc: Peter Zijlstra <peterz@infradead.org>
Reported-by: Martynas Pumputis <m@lambda.lt>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/r/20220926153340.1621984-5-jolsa@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/trace/bpf_trace.c
tools/testing/selftests/bpf/progs/kprobe_multi.c