Commit b1442d39 authored by Paul Burton's avatar Paul Burton Committed by Ralf Baechle

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

This problem appears to exist at least back to the beginning of the git
era in the PTRACE_POKEUSR case.
Signed-off-by: default avatarPaul Burton <>
Cc: Paul Burton <>
Patchwork: default avatarRalf Baechle <>
parent c3b9b945
......@@ -151,6 +151,7 @@ int ptrace_setfpregs(struct task_struct *child, __u32 __user *data)
__get_user(child->thread.fpu.fcr31, data + 64);
child->thread.fpu.fcr31 &= ~FPU_CSR_ALL_X;
/* FIR may not be written. */
......@@ -565,7 +566,7 @@ long arch_ptrace(struct task_struct *child, long request,
case FPC_CSR:
child->thread.fpu.fcr31 = data;
child->thread.fpu.fcr31 = data & ~FPU_CSR_ALL_X;
case DSP_BASE ... DSP_BASE + 5: {
dspreg_t *dregs;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment