[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YZgbS0GUpEzAeGNu@krava>
Date: Fri, 19 Nov 2021 22:46:51 +0100
From: Jiri Olsa <jolsa@...hat.com>
To: Alexei Starovoitov <alexei.starovoitov@...il.com>
Cc: Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>, netdev@...r.kernel.org,
bpf@...r.kernel.org, Martin KaFai Lau <kafai@...com>,
Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
John Fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...omium.org>
Subject: Re: [PATCH bpf-next 07/29] bpf, x64: Allow to use caller address
from stack
On Thu, Nov 18, 2021 at 08:14:09PM -0800, Alexei Starovoitov wrote:
> On Thu, Nov 18, 2021 at 12:24:33PM +0100, Jiri Olsa wrote:
> > 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. In this case 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@...nel.org>
> > ---
> > arch/x86/net/bpf_jit_comp.c | 13 +++++++++----
> > include/linux/bpf.h | 5 +++++
> > 2 files changed, 14 insertions(+), 4 deletions(-)
> >
> > diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
> > index 67e8ac9aaf0d..d87001073033 100644
> > --- a/arch/x86/net/bpf_jit_comp.c
> > +++ b/arch/x86/net/bpf_jit_comp.c
> > @@ -2035,10 +2035,15 @@ int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *image, void *i
> > if (flags & BPF_TRAMP_F_CALL_ORIG) {
> > restore_regs(m, &prog, nr_args, stack_size);
> >
> > - /* call original function */
> > - if (emit_call(&prog, orig_call, prog)) {
> > - ret = -EINVAL;
> > - goto cleanup;
> > + if (flags & BPF_TRAMP_F_ORIG_STACK) {
> > + emit_ldx(&prog, BPF_DW, BPF_REG_0, BPF_REG_FP, 8);
> > + EMIT2(0xff, 0xd0); /* call *rax */
>
> Either return an eror if repoline is on
> or use emit_indirect_jump().
>
ok, will check
thanks,
jirka
Powered by blists - more mailing lists