aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mips
diff options
context:
space:
mode:
authorPaul Burton <paul.burton@imgtec.com>2014-07-22 09:21:21 -0400
committerRalf Baechle <ralf@linux-mips.org>2014-07-30 13:30:39 -0400
commitb1442d39fac2fcfbe6a4814979020e993ca59c9e (patch)
treef3544d2a3fa463b00a30623dab0bd12c6fd91a8c /arch/mips
parentc3b9b945e02e011c63522761e91133ea43eb6939 (diff)
MIPS: Prevent user from setting FCSR cause bits
If one or more matching FCSR cause & enable bits are set in saved thread context then when that context is restored the kernel will take an FP exception. This is of course undesirable and considered an oops, leading to the kernel writing a backtrace to the console and potentially rebooting depending upon the configuration. Thus the kernel avoids this situation by clearing the cause bits of the FCSR register when handling FP exceptions and after emulating FP instructions. However the kernel does not prevent userland from setting arbitrary FCSR cause & enable bits via ptrace, using either the PTRACE_POKEUSR or PTRACE_SETFPREGS requests. This means userland can trivially cause the kernel to oops on any system with an FPU. Prevent this from happening by clearing the cause bits when writing to the saved FCSR context via ptrace. This problem appears to exist at least back to the beginning of the git era in the PTRACE_POKEUSR case. Signed-off-by: Paul Burton <paul.burton@imgtec.com> Cc: stable@vger.kernel.org Cc: linux-mips@linux-mips.org Cc: Paul Burton <paul.burton@imgtec.com> Cc: stable@vger.kernel.org Patchwork: https://patchwork.linux-mips.org/patch/7438/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch/mips')
-rw-r--r--arch/mips/kernel/ptrace.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
index f639ccd5060c..3a7f7dd610fd 100644
--- a/arch/mips/kernel/ptrace.c
+++ b/arch/mips/kernel/ptrace.c
@@ -151,6 +151,7 @@ int ptrace_setfpregs(struct task_struct *child, __u32 __user *data)
151 } 151 }
152 152
153 __get_user(child->thread.fpu.fcr31, data + 64); 153 __get_user(child->thread.fpu.fcr31, data + 64);
154 child->thread.fpu.fcr31 &= ~FPU_CSR_ALL_X;
154 155
155 /* FIR may not be written. */ 156 /* FIR may not be written. */
156 157
@@ -565,7 +566,7 @@ long arch_ptrace(struct task_struct *child, long request,
565 break; 566 break;
566#endif 567#endif
567 case FPC_CSR: 568 case FPC_CSR:
568 child->thread.fpu.fcr31 = data; 569 child->thread.fpu.fcr31 = data & ~FPU_CSR_ALL_X;
569 break; 570 break;
570 case DSP_BASE ... DSP_BASE + 5: { 571 case DSP_BASE ... DSP_BASE + 5: {
571 dspreg_t *dregs; 572 dspreg_t *dregs;