linux-stable/arch
Piotr Krysiuk 6cce305480 bpf, x86: Validate computation of branch displacements for x86-32
commit 26f55a59dc upstream.

The branch displacement logic in the BPF JIT compilers for x86 assumes
that, for any generated branch instruction, the distance cannot
increase between optimization passes.

But this assumption can be violated due to how the distances are
computed. Specifically, whenever a backward branch is processed in
do_jit(), the distance is computed by subtracting the positions in the
machine code from different optimization passes. This is because part
of addrs[] is already updated for the current optimization pass, before
the branch instruction is visited.

And so the optimizer can expand blocks of machine code in some cases.

This can confuse the optimizer logic, where it assumes that a fixed
point has been reached for all machine code blocks once the total
program size stops changing. And then the JIT compiler can output
abnormal machine code containing incorrect branch displacements.

To mitigate this issue, we assert that a fixed point is reached while
populating the output image. This rejects any problematic programs.
The issue affects both x86-32 and x86-64. We mitigate separately to
ease backporting.

Signed-off-by: Piotr Krysiuk <piotras@gmail.com>
Reviewed-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-04-10 13:34:31 +02:00
..
alpha alpha: fix annotation of io{read,write}{16,32}be() 2020-08-26 10:40:58 +02:00
arc arch/arc: add copy_user_page() to <asm/page.h> to fix build error on ARC 2021-01-19 18:26:15 +01:00
arm ARM: dts: am33xx: add aliases for mmc interfaces 2021-04-10 13:34:30 +02:00
arm64 arm64: kdump: update ppos when reading elfcorehdr 2021-03-30 14:35:27 +02:00
c6x
csky csky: Fixup abiv2 syscall_trace break a4 & a5 2020-06-17 16:40:21 +02:00
h8300 h8300: fix PREEMPTION build, TI_PRE_COUNT undefined 2021-02-17 10:35:18 +01:00
hexagon hexagon: define ioremap_uc 2020-05-10 10:31:31 +02:00
ia64 ia64: fix format strings for err_inject 2021-04-10 13:34:31 +02:00
m68k m68k: q40: Fix info-leak in rtc_ioctl 2020-10-01 13:17:12 +02:00
microblaze
mips MIPS: Drop 32-bit asm string functions 2021-03-07 12:20:43 +01:00
nds32
nios2
openrisc openrisc: Fix issue with get_user for 64-bit values 2020-11-01 12:01:06 +01:00
parisc parisc: Bump 64-bit IRQ stack size to 64 KB 2021-03-07 12:20:47 +01:00
powerpc powerpc: Force inlining of cpu_has_feature() to avoid build failure 2021-04-07 14:47:39 +02:00
riscv riscv: Correct SPARSEMEM configuration 2021-03-24 11:26:39 +01:00
s390 s390/vtime: fix increased steal time accounting 2021-03-24 11:26:35 +01:00
sh sh: dma: fix kconfig dependency for G2_DMA 2021-01-27 11:47:52 +01:00
sparc sparc64: Fix opcode filtering in handling of no fault loads 2021-03-30 14:35:22 +02:00
um um: mm: check more comprehensively for stub changes 2021-03-04 10:26:50 +01:00
unicore32
x86 bpf, x86: Validate computation of branch displacements for x86-32 2021-04-10 13:34:31 +02:00
xtensa xtensa: move coprocessor_flush to the .text section 2021-04-07 14:47:42 +02:00
.gitignore
Kconfig Revert: "ring-buffer: Remove HAVE_64BIT_ALIGNED_ACCESS" 2020-12-30 11:51:47 +01:00