linux/arch
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
..
alpha alpha: fix broken network checksum 2014-01-31 09:21:55 -08:00
arc ARC: !PREEMPT: Ensure Return to kernel mode is IRQ safe 2014-05-13 13:32:50 +02:00
arm arm: KVM: fix possible misalignment of PGDs and bounce page 2014-05-13 13:32:47 +02:00
arm64 arm64: __NR_compat_syscalls fix 2014-05-06 07:59:29 -07:00
avr32 avr32: add generic vga.h to Kbuild 2014-02-17 11:24:48 +01:00
blackfin Merge branch 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media 2014-01-31 09:31:14 -08:00
c6x Build fix for c6x 2014-03-07 09:52:46 -08:00
cris cris: convert ffs from an object-like macro to a function-like macro 2014-03-10 17:26:21 -07:00
frv Merge branch 'kbuild' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild 2014-01-30 16:58:05 -08:00
hexagon Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2014-01-25 11:17:34 -08:00
ia64 mm: fix GFP_THISNODE callers and clarify 2014-03-10 17:26:19 -07:00
m32r Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2014-01-25 11:17:34 -08:00
m68k m68k: Skip futex_atomic_cmpxchg_inatomic() test 2014-04-14 06:50:05 -07:00
metag Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2014-01-25 11:17:34 -08:00
microblaze microblaze: Fix a typo when disabling stack protection 2014-02-10 07:44:11 +01:00
mips MIPS: Hibernate: Flush TLB entries in swsusp_arch_resume() 2014-05-13 13:32:48 +02:00
mn10300 Merge branch 'kbuild' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild 2014-01-30 16:58:05 -08:00
openrisc OpenRISC updates for 3.14 2014-01-30 17:08:41 -08:00
parisc parisc: remove _STK_LIM_MAX override 2014-05-31 13:20:29 -07:00
powerpc powerpc: Fix Oops in rtas_stop_self() 2014-05-13 13:32:49 +02:00
s390 net: filter: s390: fix JIT address randomization 2014-05-31 13:20:38 -07:00
score Merge branch 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media 2014-01-31 09:31:14 -08:00
sh sh: fix format string bug in stack tracer 2014-05-06 07:59:34 -07:00
sparc sparc64: Make sure %pil interrupts are enabled during hypervisor yield. 2014-03-24 14:45:12 -04:00
tile tile: remove compat_sys_lookup_dcookie declaration to fix compile error 2014-02-01 10:55:15 -08:00
um Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rw/uml 2014-01-26 11:06:16 -08:00
unicore32 arch/unicore32/kernel/early_printk.c:setup_early_printk: missing initialization 2014-01-27 21:02:39 -08:00
x86 net: filter: x86: fix JIT address randomization 2014-05-31 13:20:38 -07:00
xtensa Xtensa fixes for 3.14: 2014-02-24 00:34:36 -08:00
.gitignore
Kconfig stackprotector: Introduce CONFIG_CC_STACKPROTECTOR_STRONG 2013-12-20 09:38:40 +01:00