• D
    x86, mpx: Decode MPX instruction to get bound violation information · fcc7ffd6
    Dave Hansen 提交于
    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: NDave Hansen <dave.hansen@linux.intel.com>
    Based-on-patch-by: NQiaowei 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.comSigned-off-by: NThomas Gleixner <tglx@linutronix.de>
    fcc7ffd6
mpx.h 1.1 KB