linux/arch/arm64
Daniel Borkmann 21e3113298 bpf, arm64: fix faulty emission of map access in tail calls
[ Upstream commit d8b54110ee ]

Shubham was recently asking on netdev why in arm64 JIT we don't multiply
the index for accessing the tail call map by 8. That led me into testing
out arm64 JIT wrt tail calls and it turned out I got a NULL pointer
dereference on the tail call.

The buggy access is at:

  prog = array->ptrs[index];
  if (prog == NULL)
      goto out;

  [...]
  00000060:  d2800e0a  mov x10, #0x70 // #112
  00000064:  f86a682a  ldr x10, [x1,x10]
  00000068:  f862694b  ldr x11, [x10,x2]
  0000006c:  b40000ab  cbz x11, 0x00000080
  [...]

The code triggering the crash is f862694b. x1 at the time contains the
address of the bpf array, x10 offsetof(struct bpf_array, ptrs). Meaning,
above we load the pointer to the program at map slot 0 into x10. x10
can then be NULL if the slot is not occupied, which we later on try to
access with a user given offset in x2 that is the map index.

Fix this by emitting the following instead:

  [...]
  00000060:  d2800e0a  mov x10, #0x70 // #112
  00000064:  8b0a002a  add x10, x1, x10
  00000068:  d37df04b  lsl x11, x2, #3
  0000006c:  f86b694b  ldr x11, [x10,x11]
  00000070:  b40000ab  cbz x11, 0x00000084
  [...]

This basically adds the offset to ptrs to the base address of the bpf
array we got and we later on access the map with an index * 8 offset
relative to that. The tail call map itself is basically one large area
with meta data at the head followed by the array of prog pointers.
This makes tail calls working again, tested on Cavium ThunderX ARMv8.

Fixes: ddb55992b0 ("arm64: bpf: implement bpf_tail_call() helper")
Reported-by: Shubham Bansal <illusionist.neo@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2017-06-07 12:07:43 +02:00
..
boot arm64: dts: hi6220: Reset the mmc hosts 2017-05-25 15:44:44 +02:00
configs ZTE arm64 defconfig updates for 4.9: 2016-09-19 22:35:21 +02:00
crypto crypto: arm64/aes-blk - honour iv_out requirement in CBC and CTR modes 2017-02-09 08:08:26 +01:00
include arm64: uaccess: ensure extension of access_ok() addr 2017-05-25 15:44:45 +02:00
kernel arm64: armv8_deprecated: ensure extension of addr 2017-05-25 15:44:45 +02:00
kvm arm64: KVM: Do not use stack-protector to compile EL2 code 2017-05-25 15:44:43 +02:00
lib Merge branch 'work.uaccess' into for-linus 2016-10-14 20:42:44 -04:00
mm arm64: mm: unaligned access by user-land should be received as SIGBUS 2017-04-12 12:41:11 +02:00
net bpf, arm64: fix faulty emission of map access in tail calls 2017-06-07 12:07:43 +02:00
xen arm/xen: add support for vm_assist hypercall 2016-07-06 10:42:14 +01:00
Kconfig irqchip/gicv3-its: Add workaround for QDF2400 ITS erratum 0065 2017-03-22 12:43:39 +01:00
Kconfig.debug arm64: always enable DEBUG_RODATA and remove the Kconfig option 2016-08-26 10:13:41 +01:00
Kconfig.platforms arm64: uniphier: select ARCH_HAS_RESET_CONTROLLER 2016-10-22 18:25:52 +09:00
Makefile arm64: kernel: force ET_DYN ELF type for CONFIG_RELOCATABLE=y 2016-10-20 11:37:25 +01:00