linux/arch/s390
Heiko Carstens 4d3b152a2e net: filter: s390: fix JIT address randomization
[ Upstream commit e84d2f8d2a ]

This is the s390 variant of Alexei's JIT bug fix.
(patch description below stolen from Alexei's patch)

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: aa2d2c73c2 ("s390/bpf,jit: address randomize and write protect jit code")

Reported-by: Alexei Starovoitov <ast@plumgrid.com>
Cc: <stable@vger.kernel.org> # v3.11+
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.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
..
appldata s390/appldata: restore missing init_virt_timer() 2014-01-29 09:07:51 +01:00
boot s390/boot: Install bzImage as default kernel image 2013-11-15 14:08:36 +01:00
configs s390: add a couple of useful defconfigs 2013-10-24 17:17:14 +02:00
crypto crypto: s390 - fix des and des3_ede ctr concurrency issue 2014-01-30 21:45:14 +08:00
hypfs s390/hypfs: add interface for diagnose 0x304 2014-01-24 09:40:59 +01:00
include s390/bitops,atomic: add missing memory barriers 2014-05-06 07:59:24 -07:00
kernel s390: fix control register update 2014-05-06 07:59:24 -07:00
kvm KVM: s390: Optimize ucontrol path 2014-05-06 07:59:24 -07:00
lib s390/uaccess: remove dead extern declarations, make functions static 2014-01-22 14:02:17 +01:00
math-emu s390: fix save and restore of the floating-point-control register 2013-10-24 17:17:11 +02:00
mm s390/dump: Fix dump memory detection 2014-02-04 15:39:51 +01:00
net net: filter: s390: fix JIT address randomization 2014-05-31 13:20:38 -07:00
oprofile s390/cpum_sf: Add raw data sampling to support the diagnostic-sampling function 2013-12-16 14:38:00 +01:00
pci s390/pci/dma: use correct segment boundary size 2014-02-21 08:48:27 +01:00
Kbuild
Kconfig futex: Allow architectures to skip futex_atomic_cmpxchg_inatomic() test 2014-04-14 06:50:05 -07:00
Kconfig.debug
Makefile s390: allow to set gcc -mtune flag 2013-10-31 09:54:01 +01:00
defconfig Update default configuration 2013-10-24 17:17:15 +02:00