Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754008AbbKHC1e (ORCPT ); Sat, 7 Nov 2015 21:27:34 -0500 Received: from mail-pa0-f54.google.com ([209.85.220.54]:34708 "EHLO mail-pa0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751802AbbKHC1b (ORCPT ); Sat, 7 Nov 2015 21:27:31 -0500 Date: Sat, 7 Nov 2015 18:27:27 -0800 From: Alexei Starovoitov To: Yang Shi Cc: ast@kernel.org, daniel@iogearbox.net, catalin.marinas@arm.com, will.deacon@arm.com, zlim.lnx@gmail.com, xi.wang@gmail.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linaro-kernel@lists.linaro.org Subject: Re: [PATCH] arm64: bpf: fix JIT stack setup Message-ID: <20151108022726.GB39441@ast-mbp.thefacebook.com> References: <1446874577-14539-1-git-send-email-yang.shi@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1446874577-14539-1-git-send-email-yang.shi@linaro.org> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2004 Lines: 47 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 > CC: Zi Shen Lim > CC: Xi Wang 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/