linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: linux@armlinux.org.uk (Russell King - ARM Linux)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 2/2] arm64: defconfig: enable BPF related configs
Date: Tue, 27 Nov 2018 23:18:39 +0000	[thread overview]
Message-ID: <20181127231839.GF30658@n2100.armlinux.org.uk> (raw)
In-Reply-To: <20181127193118.GG5641@arm.com>

On Tue, Nov 27, 2018 at 07:31:18PM +0000, Will Deacon wrote:
> Hi Russell,
> 
> On Mon, Nov 26, 2018 at 03:52:47PM +0000, Russell King - ARM Linux wrote:
> > On Mon, Nov 26, 2018 at 03:38:20PM +0000, Will Deacon wrote:
> > > On Sat, Nov 17, 2018 at 03:18:04PM -0800, Ard Biesheuvel wrote:
> > > > On Mon, 12 Nov 2018 at 10:36, Will Deacon <will.deacon@arm.com> wrote:
> > > > > On Sun, Nov 11, 2018 at 06:10:48PM +0000, Peter Robinson wrote:
> > > > > > The BPF components are getting more widely used by various components
> > > > > > so we should enable them in the ARMv7 multi config to ensure they
> > > > > > get wider testing and don't regress.
> > > > >
> > > > > Have other architectures already made this leap?
> > > > >
> > > > 
> > > > $ git grep CONFIG_BPF_SYSCALL=y arch/
> > > > arch/arm/configs/aspeed_g4_defconfig:CONFIG_BPF_SYSCALL=y
> > > > arch/arm/configs/aspeed_g5_defconfig:CONFIG_BPF_SYSCALL=y
> > > > arch/mips/configs/generic_defconfig:CONFIG_BPF_SYSCALL=y
> > > > arch/powerpc/configs/44x/fsp2_defconfig:CONFIG_BPF_SYSCALL=y
> > > > arch/powerpc/configs/powernv_defconfig:CONFIG_BPF_SYSCALL=y
> > > > arch/powerpc/configs/ppc64_defconfig:CONFIG_BPF_SYSCALL=y
> > > > arch/powerpc/configs/pseries_defconfig:CONFIG_BPF_SYSCALL=y
> > > > arch/riscv/configs/defconfig:CONFIG_BPF_SYSCALL=y
> > > > arch/s390/configs/debug_defconfig:CONFIG_BPF_SYSCALL=y
> > > > arch/s390/configs/performance_defconfig:CONFIG_BPF_SYSCALL=y
> > > > arch/s390/defconfig:CONFIG_BPF_SYSCALL=y
> > > > 
> > > > but nobody seems to enable CONFIG_BPF_JIT_ALWAYS_ON.
> > > > 
> > > > I sent some patches to move the BPF JIT allocations out of the module
> > > > range. Whether that really improves things in terms of security is not
> > > > obvious to me, but at least we stop wasting module region space (and
> > > > potentially KASAN shadow pages) on BPF programs.
> > > > 
> > > > If this is mainly for coverage, it would indeed be nice if we could at
> > > > least make it root only by default. However, if the distros are
> > > > enabling this in their default configurations, I'd prefer it if we at
> > > > least have a config that will help us spot issues early on.
> > > 
> > > That's a fair point on the distros. Peter, as author of the patch, please
> > > can you take a look at the arm64 kernel configs from some popular
> > > distributions and see which of these options they tend to enable?
> > 
> > Another point to consider is whether the BPF JIT creates code that
> > is safe from Spectre, or whether it opens up more Spectre issues.
> > If it isn't, maybe the better option is to disable kernel-side BPF
> > entirely until it is fixed up.
> > 
> > I've raised that point for 32-bit ARM already, and the 32-bit ARM
> > BPF JIT isn't going to have the Spectre mitigations applied (since
> > no one appears interested whenever I've raised it.)  So, for 32-bit
> > ARM, it's better to have kernel-side BPF entirely disabled if you
> > care about Spectre mitigations.
> 
> I thought that the Spectre mitigations (at least for variant 1) were handled
> by the core BPF JIT, as a result of b2157399cc98 ("bpf: prevent out-of-bounds
> speculation")? I think we rely on randomization to protect against variant 2
> for JITted code.
> 
> Did I miss something here?

It depends - there's at least one case in eBPF that requires the JIT to
be mitigated, and that's the tail-call stuff.  That's prime Spectre
exploitation territory, because the pseudocode for that eBPF instruction
is:

	if (index >= array->map.max_entries)
		goto out;
	if (tail_call_cnt > MAX_TAIL_CALL_CNT)
		goto out;
	tail_call_cnt++;
	prog = array->ptrs[index];
	if (prog == NULL)
		goto out;
	goto *(prog->bpf_func + prologue_size);

If 'index' is larger than map.max_entries, and we speculate past the
goto, then out of bounds cache lines in the array->ptrs[] could be
loaded.

In cBPF, it seems to me that there is enough support to do something
like:

	if (val > max)		// BPF_JMP | BPF_JGT | BPF_K
		jump somewhere;
	addr += val;		// BPF_ALU | BPF_ADD | BPF_W
	val2 = *addr;		// BPF_LDX | BPF_MEM | BPF_W

which looks to me like it can fit the Spectre exploitation pattern,
but is much harder to work around than the eBPF tailcall (we would
need to detect the BPF instruction sequence.)  I haven't validated
that such a sequence is actually possible in cBPF, but as cBPF is
used for packet filtering, and there's a need for it to support
jumping over the headers which can be variable lengths, then I
would not be surprised if such BPF sequences were possible.

-- 
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up

  reply	other threads:[~2018-11-27 23:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-11 18:10 [PATCH 1/2] ARM: multi_v7_defconfig: enable BPF related configs Peter Robinson
2018-11-11 18:10 ` [PATCH 2/2] arm64: defconfig: " Peter Robinson
2018-11-12 18:36   ` Will Deacon
2018-11-17 23:18     ` Ard Biesheuvel
2018-11-26 15:38       ` Will Deacon
2018-11-26 15:52         ` Russell King - ARM Linux
2018-11-27 19:31           ` Will Deacon
2018-11-27 23:18             ` Russell King - ARM Linux [this message]
2018-11-28 20:01               ` Will Deacon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181127231839.GF30658@n2100.armlinux.org.uk \
    --to=linux@armlinux.org.uk \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).