]> git.baikalelectronics.ru Git - kernel.git/commit
bpf, x64: Allow to use caller address from stack
authorJiri Olsa <jolsa@kernel.org>
Wed, 20 Jul 2022 00:21:25 +0000 (17:21 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 22 Jul 2022 20:04:37 +0000 (22:04 +0200)
commitb9657996eb92c72e4c8dfc568c6807f3bed2333d
tree5af366a623b898d85c7f7c56eb46be386a740e52
parent3a9492350b2419bae98a698866577e271dd62507
bpf, x64: Allow to use caller address from stack

Currently we call the original function by using the absolute address
given at the JIT generation. That's not usable when having trampoline
attached to multiple functions, or the target address changes dynamically
(in case of live patch). In such cases we need to take the return address
from the stack.

Adding support to retrieve the original function address from the stack
by adding new BPF_TRAMP_F_ORIG_STACK flag for arch_prepare_bpf_trampoline
function.

Basically we take the return address of the 'fentry' call:

   function + 0: call fentry    # stores 'function + 5' address on stack
   function + 5: ...

The 'function + 5' address will be used as the address for the
original function to call.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Song Liu <song@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20220720002126.803253-4-song@kernel.org
arch/x86/net/bpf_jit_comp.c
include/linux/bpf.h