Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1264959

Re: [PATCH] arm64: bpf: fix JIT stack setup

From Alexei Starovoitov <alexei.starovoitov@gmail.com>
Newsgroups linux.kernel
Subject Re: [PATCH] arm64: bpf: fix JIT stack setup
Date 2015-11-08 03:30 +0100
Message-ID <qsnTY-2aP-3@gated-at.bofh.it> (permalink)
References <qs4HF-6ER-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Fri, Nov 06, 2015 at 09:36:17PM -0800, Yang Shi wrote:
> ARM64 JIT used FP (x29) as eBPF fp register, but FP is subjected to
> change during function call so it may cause the BPF prog stack base address
> change too. Whenever, it pointed to the bottom of BPF prog stack instead of
> the top.
> 
> So, when copying data via bpf_probe_read, it will be copied to (SP - offset),
> then it may overwrite the saved FP/LR.
> 
> Use x25 to replace FP as BPF stack base register (fp). Since x25 is callee
> saved register, so it will keep intact during function call.
> It is initialized in BPF prog prologue when BPF prog is started to run
> everytime. When BPF prog exits, it could be just tossed.
> 
> Other than this the BPf prog stack base need to be setup before function
> call stack.
> 
> So, the BPF stack layout looks like:
> 
>                                  high
>          original A64_SP =>   0:+-----+ BPF prologue
>                                 |     | FP/LR and callee saved registers
>          BPF fp register => +64:+-----+
>                                 |     |
>                                 | ... | BPF prog stack
>                                 |     |
>                                 |     |
>          current A64_SP =>      +-----+
>                                 |     |
>                                 | ... | Function call stack
>                                 |     |
>                                 +-----+
>                                   low
> 
> Signed-off-by: Yang Shi <yang.shi@linaro.org>
> CC: Zi Shen Lim <zlim.lnx@gmail.com>
> CC: Xi Wang <xi.wang@gmail.com>

Thanks for tracking it down.
That looks like fundamental bug in arm64 jit. I'm surprised function calls worked at all.
Zi please review.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] arm64: bpf: fix JIT stack setup Yang Shi <yang.shi@linaro.org> - 2015-11-07 07:00 +0100
  Re: [PATCH] arm64: bpf: fix JIT stack setup Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2015-11-08 03:30 +0100
    Re: [PATCH] arm64: bpf: fix JIT stack setup Z Lim <zlim.lnx@gmail.com> - 2015-11-08 23:40 +0100
      Re: [PATCH] arm64: bpf: fix JIT stack setup "Shi, Yang" <yang.shi@linaro.org> - 2015-11-09 19:10 +0100
        Re: [PATCH] arm64: bpf: fix JIT stack setup Z Lim <zlim.lnx@gmail.com> - 2015-11-09 21:10 +0100
          Re: [PATCH] arm64: bpf: fix JIT stack setup "Shi, Yang" <yang.shi@linaro.org> - 2015-11-10 20:50 +0100
            Re: [PATCH] arm64: bpf: fix JIT stack setup Z Lim <zlim.lnx@gmail.com> - 2015-11-11 04:20 +0100

csiph-web