linux-stable/arch/x86
Dave Hansen fcc7ffd679 x86, mpx: Decode MPX instruction to get bound violation information
This patch sets bound violation fields of siginfo struct in #BR
exception handler by decoding the user instruction and constructing
the faulting pointer.

We have to be very careful when decoding these instructions.  They
are completely controlled by userspace and may be changed at any
time up to and including the point where we try to copy them in to
the kernel.  They may or may not be MPX instructions and could be
completely invalid for all we know.

Note: This code is based on Qiaowei Ren's specialized MPX
decoder, but uses the generic decoder whenever possible.  It was
tested for robustness by generating a completely random data
stream and trying to decode that stream.  I also unmapped random
pages inside the stream to test the "partial instruction" short
read code.

We kzalloc() the siginfo instead of stack allocating it because
we need to memset() it anyway, and doing this makes it much more
clear when it got initialized by the MPX instruction decoder.

Changes from the old decoder:
 * Use the generic decoder instead of custom functions.  Saved
   ~70 lines of code overall.
 * Remove insn->addr_bytes code (never used??)
 * Make sure never to possibly overflow the regoff[] array, plus
   check the register range correctly in 32 and 64-bit modes.
 * Allow get_reg() to return an error and have mpx_get_addr_ref()
   handle when it sees errors.
 * Only call insn_get_*() near where we actually use the values
   instead if trying to call them all at once.
 * Handle short reads from copy_from_user() and check the actual
   number of read bytes against what we expect from
   insn_get_length().  If a read stops in the middle of an
   instruction, we error out.
 * Actually check the opcodes intead of ignoring them.
 * Dynamically kzalloc() siginfo_t so we don't leak any stack
   data.
 * Detect and handle decoder failures instead of ignoring them.

Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Based-on-patch-by: Qiaowei Ren <qiaowei.ren@intel.com>
Cc: linux-mm@kvack.org
Cc: linux-mips@linux-mips.org
Cc: Dave Hansen <dave@sr71.net>
Link: http://lkml.kernel.org/r/20141114151828.5BDD0915@viggo.jf.intel.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
2014-11-18 00:58:53 +01:00
..
boot Merge branch 'x86-efi-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2014-10-23 14:45:09 -07:00
configs
crypto Revert "crypto: aesni - disable "by8" AVX CTR optimization" 2014-10-02 14:40:28 +08:00
ia32 x86_64, entry: Fix out of bounds read on sysenter 2014-10-31 18:47:09 -07:00
include x86, mpx: Decode MPX instruction to get bound violation information 2014-11-18 00:58:53 +01:00
kernel x86: Remove arbitrary instruction size limit in instruction decoder 2014-11-18 00:58:52 +01:00
kvm KVM: vmx: defer load of APIC access page address during reset 2014-11-02 08:37:18 +01:00
lguest
lib x86: Remove arbitrary instruction size limit in instruction decoder 2014-11-18 00:58:52 +01:00
math-emu
mm x86, mpx: Decode MPX instruction to get bound violation information 2014-11-18 00:58:53 +01:00
net x86: bpf_jit: fix two bugs in eBPF JIT compiler 2014-10-14 13:13:14 -04:00
oprofile
pci xen: features and fixes for 3.18-rc0 2014-10-11 20:29:01 -04:00
platform Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2014-10-31 14:30:16 -07:00
power nosave: consolidate __nosave_{begin,end} in <asm/sections.h> 2014-10-09 22:26:04 -04:00
purgatory arch/x86/purgatory/Makefile: try to use automatic variable in kexec purgatory makefile 2014-10-14 02:18:21 +02:00
realmode
syscalls bpf: enable bpf syscall on x64 and i386 2014-09-26 15:05:14 -04:00
tools x86: Remove arbitrary instruction size limit in instruction decoder 2014-11-18 00:58:52 +01:00
um Merge git://git.infradead.org/users/eparis/audit 2014-10-19 16:25:56 -07:00
vdso x86/vdso: Fix vdso2c's special_pages[] error checking 2014-09-24 09:55:38 +02:00
video
xen x86/xen: panic on bad Xen-provided memory map 2014-10-23 16:24:02 +01:00
.gitignore x86/build: Add arch/x86/purgatory/ make generated files to gitignore 2014-10-09 09:29:46 +02:00
Kbuild
Kconfig x86, mpx: Add MPX-specific mmap interface 2014-11-18 00:58:53 +01:00
Kconfig.cpu
Kconfig.debug
Makefile Merge branch 'x86-build-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2014-10-13 18:17:33 +02:00
Makefile.um
Makefile_32.cpu