linux/arch/x86
Alexei Starovoitov 070a08cd74 net: filter: x86: fix JIT address randomization
[ Upstream commit 773cd38f40 ]

bpf_alloc_binary() adds 128 bytes of room to JITed program image
and rounds it up to the nearest page size. If image size is close
to page size (like 4000), it is rounded to two pages:
round_up(4000 + 4 + 128) == 8192
then 'hole' is computed as 8192 - (4000 + 4) = 4188
If prandom_u32() % hole selects a number >= PAGE_SIZE - sizeof(*header)
then kernel will crash during bpf_jit_free():

kernel BUG at arch/x86/mm/pageattr.c:887!
Call Trace:
 [<ffffffff81037285>] change_page_attr_set_clr+0x135/0x460
 [<ffffffff81694cc0>] ? _raw_spin_unlock_irq+0x30/0x50
 [<ffffffff810378ff>] set_memory_rw+0x2f/0x40
 [<ffffffffa01a0d8d>] bpf_jit_free_deferred+0x2d/0x60
 [<ffffffff8106bf98>] process_one_work+0x1d8/0x6a0
 [<ffffffff8106bf38>] ? process_one_work+0x178/0x6a0
 [<ffffffff8106c90c>] worker_thread+0x11c/0x370

since bpf_jit_free() does:
  unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
  struct bpf_binary_header *header = (void *)addr;
to compute start address of 'bpf_binary_header'
and header->pages will pass junk to:
  set_memory_rw(addr, header->pages);

Fix it by making sure that &header->image[prandom_u32() % hole] and &header
are in the same page

Fixes: 314beb9bca ("x86: bpf_jit_comp: secure bpf jit against spraying attacks")
Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
Acked-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-05-31 13:20:38 -07:00
..
boot x86/efi: Correct EFI boot stub use of code32_start 2014-05-06 07:59:29 -07:00
configs
crypto crypto: ghash-clmulni-intel - use C implementation for setkey() 2014-04-14 06:50:05 -07:00
ia32 constify copy_siginfo_to_user{,32}() 2013-11-09 00:16:29 -05:00
include x86,preempt: Fix preemption for i386 2014-05-31 13:20:28 -07:00
kernel x86-64, modify_ldt: Ban 16-bit segments on 64-bit kernels 2014-05-06 07:59:26 -07:00
kvm KVM: x86: remove WARN_ON from get_kernel_ns() 2014-05-31 13:20:27 -07:00
lguest x86, asmlinkage, lguest: Fix C functions used by inline assembler 2014-01-29 22:17:17 -08:00
lib x86, hash: Fix build failure with older binutils 2014-05-06 07:59:26 -07:00
math-emu x86: math-emu: Drop already-disabled print of build date 2014-01-27 23:14:12 +01:00
mm x86, pageattr: Export page unmapping interface 2014-04-14 06:50:02 -07:00
net net: filter: x86: fix JIT address randomization 2014-05-31 13:20:38 -07:00
oprofile perf: Fix arch_perf_out_copy_user default 2013-11-06 12:34:25 +01:00
pci ACPI and power management updates for 3.14-rc1 2014-01-24 15:51:02 -08:00
platform x86/efi: Make efi virtual runtime map passing more robust 2014-04-14 06:50:02 -07:00
power
realmode Merge commit 'f4bcd8ccddb02833340652e9f46f5127828eb79d' into x86/build 2014-01-29 09:07:00 -08:00
syscalls sched: Add new scheduler syscalls to support an extended scheduling parameters ABI 2014-01-13 13:41:04 +01:00
tools Merge commit 'f4bcd8ccddb02833340652e9f46f5127828eb79d' into x86/build 2014-01-29 09:07:00 -08:00
um x86: Remove CONFIG_X86_OOSTORE 2014-03-11 10:16:18 -07:00
vdso Merge branch 'x86-cleanups-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2014-01-20 12:03:57 -08:00
video
xen xen/spinlock: Don't enable them unconditionally. 2014-05-31 13:20:29 -07:00
.gitignore
Kbuild
Kconfig * Avoid WARN_ON() when mapping BGRT on Baytrail (EFI 32-bit). 2014-02-07 11:27:30 -08:00
Kconfig.cpu x86: Remove CONFIG_X86_OOSTORE 2014-03-11 10:16:18 -07:00
Kconfig.debug x86: Disable CONFIG_X86_DECODER_SELFTEST in allmod/allyesconfigs 2014-02-05 14:10:30 -08:00
Makefile x86-64, build: Fix stack protector Makefile breakage with 32-bit userland 2014-05-13 13:32:58 +02:00
Makefile.um
Makefile_32.cpu