linux/arch
Piotr Krysiuk 26f55a59dc bpf, x86: Validate computation of branch displacements for x86-32
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>
2021-04-08 16:24:53 +02:00
..
alpha
arc
arm A set of irqchip updates: 2021-03-14 13:33:33 -07:00
arm64 arm64 fixes for -rc5 2021-03-25 11:07:40 -07:00
csky ftrace: Fix spelling mistake "disabed" -> "disabled" 2021-03-16 21:19:40 -07:00
h8300
hexagon
ia64 ia64: fix format strings for err_inject 2021-03-25 09:22:55 -07:00
m68k
microblaze
mips MIPS: vmlinux.lds.S: Fix appended dtb not properly aligned 2021-03-16 22:53:08 +01:00
nds32
nios2
openrisc
parisc
powerpc powerpc: Force inlining of cpu_has_feature() to avoid build failure 2021-03-14 20:32:24 +11:00
riscv riscv: Correct SPARSEMEM configuration 2021-03-16 22:15:21 -07:00
s390 s390/pci: fix leak of PCI device structure 2021-03-15 19:10:56 +01:00
sh
sparc
um
x86 bpf, x86: Validate computation of branch displacements for x86-32 2021-04-08 16:24:53 +02:00
xtensa
.gitignore
Kconfig