• Paul Burton's avatar
    MIPS: Prevent "restoration" of MSA context in non-MSA kernels · 6dc9f27c
    Paul Burton authored
    commit 6533af4d upstream.
    
    If a kernel doesn't support MSA context (ie. CONFIG_CPU_HAS_MSA=n) then
    it will only keep 64 bits per FP register in thread context, and the
    calls to set_fpr64 in restore_msa_extcontext will overrun the end of the
    FP register context into the FCSR & MSACSR values. GCC 6.x has become
    smart enough to detect this & complain like so:
    
        arch/mips/kernel/signal.c: In function 'protected_restore_fp_context':
        ./arch/mips/include/asm/processor.h:114:17: error: array subscript is above array bounds [-Werror=array-bounds]
          fpr->val##width[FPR_IDX(width, idx)] = val;   \
          ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
        ./arch/mips/include/asm/processor.h:118:1: note: in expansion of macro 'BUILD_FPR_ACCESS'
         BUILD_FPR_ACCESS(64)
    
    The only way to trigger this code to run would be for a program to set
    up an artificial extended MSA context structure following a sigframe &
    execute sigreturn. Whilst this doesn't allow a program to write to any
    state that it couldn't already, it makes little sense to allow this
    "restoration" of MSA context in a system that doesn't support MSA.
    
    Fix this by killing a program with SIGSYS if it tries something as crazy
    as "restoring" fake MSA context in this way, also fixing the build error
    & allowing for most of restore_msa_extcontext to be optimised out of
    kernels without support for MSA.
    Signed-off-by: default avatarPaul Burton <paul.burton@imgtec.com>
    Reported-by: default avatarMichal Toman <michal.toman@imgtec.com>
    Fixes: bf82cb30 ("MIPS: Save MSA extended context around signals")
    Tested-by: default avatarAaro Koskinen <aaro.koskinen@iki.fi>
    Cc: James Hogan <james.hogan@imgtec.com>
    Cc: Michal Toman <michal.toman@imgtec.com>
    Cc: linux-mips@linux-mips.org
    Patchwork: https://patchwork.linux-mips.org/patch/13164/Signed-off-by: default avatarRalf Baechle <ralf@linux-mips.org>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    6dc9f27c
signal.c 22 KB