linux/arch
Luke Nelson 4178417cc5 arm, bpf: Fix offset overflow for BPF_MEM BPF_DW
This patch fixes an incorrect check in how immediate memory offsets are
computed for BPF_DW on arm.

For BPF_LDX/ST/STX + BPF_DW, the 32-bit arm JIT breaks down an 8-byte
access into two separate 4-byte accesses using off+0 and off+4. If off
fits in imm12, the JIT emits a ldr/str instruction with the immediate
and avoids the use of a temporary register. While the current check off
<= 0xfff ensures that the first immediate off+0 doesn't overflow imm12,
it's not sufficient for the second immediate off+4, which may cause the
second access of BPF_DW to read/write the wrong address.

This patch fixes the problem by changing the check to
off <= 0xfff - 4 for BPF_DW, ensuring off+4 will never overflow.

A side effect of simplifying the check is that it now allows using
negative immediate offsets in ldr/str. This means that small negative
offsets can also avoid the use of a temporary register.

This patch introduces no new failures in test_verifier or test_bpf.c.

Fixes: c5eae69257 ("ARM: net: bpf: improve 64-bit store implementation")
Fixes: ec19e02b34 ("ARM: net: bpf: fix LDX instructions")
Co-developed-by: Xi Wang <xi.wang@gmail.com>
Signed-off-by: Xi Wang <xi.wang@gmail.com>
Signed-off-by: Luke Nelson <luke.r.nels@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20200409221752.28448-1-luke.r.nels@gmail.com
2020-04-14 21:27:54 +02:00
..
alpha asm-generic: fix unistd_32.h generation format 2020-04-07 10:43:42 -07:00
arc ARC updates for 5.7-rc1 2020-04-03 15:28:42 -07:00
arm arm, bpf: Fix offset overflow for BPF_MEM BPF_DW 2020-04-14 21:27:54 +02:00
arm64 1) Improve getrandom and /dev/random's support for those arm64 2020-04-05 10:59:18 -07:00
c6x SCSI misc on 20200402 2020-04-02 17:03:53 -07:00
csky mm/vma: append unlikely() while testing VMA access permissions 2020-04-07 10:43:38 -07:00
h8300 asm-generic: make more kernel-space headers mandatory 2020-04-02 09:35:25 -07:00
hexagon mm: allow VM_FAULT_RETRY for multiple times 2020-04-02 09:35:30 -07:00
ia64 kasan: stackdepot: move filter_irq_stacks() to stackdepot.c 2020-04-07 10:43:43 -07:00
m68k mm/vma: append unlikely() while testing VMA access permissions 2020-04-07 10:43:38 -07:00
microblaze asm-generic: fix unistd_32.h generation format 2020-04-07 10:43:42 -07:00
mips asm-generic: fix unistd_32.h generation format 2020-04-07 10:43:42 -07:00
nds32 kasan: stackdepot: move filter_irq_stacks() to stackdepot.c 2020-04-07 10:43:43 -07:00
nios2 dma-mapping updates for 5.7 2020-04-04 10:12:47 -07:00
openrisc OpenRISC updates for 5.6 2020-04-07 12:33:37 -07:00
parisc Merge branch 'akpm' (patches from Andrew) 2020-04-07 14:11:54 -07:00
powerpc asm-generic: fix unistd_32.h generation format 2020-04-07 10:43:42 -07:00
riscv Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf 2020-04-09 17:39:22 -07:00
s390 s390 updates for the 5.7 merge window 2020-04-04 09:45:50 -07:00
sh asm-generic: fix unistd_32.h generation format 2020-04-07 10:43:42 -07:00
sparc Merge branch 'akpm' (patches from Andrew) 2020-04-07 14:11:54 -07:00
um This pull request contains the following changes for UML: 2020-04-07 12:36:09 -07:00
unicore32 SPDX patches for 5.7-rc1. 2020-04-03 13:12:26 -07:00
x86 Merge branch 'akpm' (patches from Andrew) 2020-04-07 14:11:54 -07:00
xtensa asm-generic: fix unistd_32.h generation format 2020-04-07 10:43:42 -07:00
.gitignore .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
Kconfig dma-mapping updates for 5.7 2020-04-04 10:12:47 -07:00