* [PATCH] MIPS: prevent user from setting FCSR cause bits
@ 2014-07-22 13:21 ` Paul Burton
0 siblings, 0 replies; 7+ messages in thread
From: Paul Burton @ 2014-07-22 13:21 UTC (permalink / raw)
To: linux-mips; +Cc: Paul Burton, stable
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
---
arch/mips/kernel/ptrace.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
index f639ccd..3a7f7dd 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)
}
__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,
break;
#endif
case FPC_CSR:
- child->thread.fpu.fcr31 = data;
+ child->thread.fpu.fcr31 = data & ~FPU_CSR_ALL_X;
break;
case DSP_BASE ... DSP_BASE + 5: {
dspreg_t *dregs;
--
2.0.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH] MIPS: prevent user from setting FCSR cause bits
@ 2014-07-22 13:21 ` Paul Burton
0 siblings, 0 replies; 7+ messages in thread
From: Paul Burton @ 2014-07-22 13:21 UTC (permalink / raw)
To: linux-mips; +Cc: Paul Burton, stable
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
---
arch/mips/kernel/ptrace.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
index f639ccd..3a7f7dd 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)
}
__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,
break;
#endif
case FPC_CSR:
- child->thread.fpu.fcr31 = data;
+ child->thread.fpu.fcr31 = data & ~FPU_CSR_ALL_X;
break;
case DSP_BASE ... DSP_BASE + 5: {
dspreg_t *dregs;
--
2.0.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] MIPS: prevent user from setting FCSR cause bits
2014-07-22 13:21 ` Paul Burton
(?)
@ 2014-07-30 17:34 ` Ralf Baechle
2014-07-30 17:39 ` Paul Burton
2014-07-30 17:53 ` Maciej W. Rozycki
-1 siblings, 2 replies; 7+ messages in thread
From: Ralf Baechle @ 2014-07-30 17:34 UTC (permalink / raw)
To: Paul Burton; +Cc: linux-mips, stable
On Tue, Jul 22, 2014 at 02:21:21PM +0100, Paul Burton wrote:
> 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.
Good catch - but I think something like UML on a more proper fix. How
until then I'm going to apply this.
Ralf
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] MIPS: prevent user from setting FCSR cause bits
@ 2014-07-30 17:39 ` Paul Burton
0 siblings, 0 replies; 7+ messages in thread
From: Paul Burton @ 2014-07-30 17:39 UTC (permalink / raw)
To: Ralf Baechle; +Cc: linux-mips, stable
On Wed, Jul 30, 2014 at 07:34:47PM +0200, Ralf Baechle wrote:
> On Tue, Jul 22, 2014 at 02:21:21PM +0100, Paul Burton wrote:
>
> > 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.
>
> Good catch - but I think something like UML on a more proper fix. How
> until then I'm going to apply this.
>
> Ralf
Any chance you could expand that acronym for me? Maybe I'm being slow
since neither of the expansions that spring to mind make much sense.
Thanks,
Paul
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] MIPS: prevent user from setting FCSR cause bits
@ 2014-07-30 17:39 ` Paul Burton
0 siblings, 0 replies; 7+ messages in thread
From: Paul Burton @ 2014-07-30 17:39 UTC (permalink / raw)
To: Ralf Baechle; +Cc: linux-mips, stable
On Wed, Jul 30, 2014 at 07:34:47PM +0200, Ralf Baechle wrote:
> On Tue, Jul 22, 2014 at 02:21:21PM +0100, Paul Burton wrote:
>
> > 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.
>
> Good catch - but I think something like UML on a more proper fix. How
> until then I'm going to apply this.
>
> Ralf
Any chance you could expand that acronym for me? Maybe I'm being slow
since neither of the expansions that spring to mind make much sense.
Thanks,
Paul
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] MIPS: prevent user from setting FCSR cause bits
2014-07-30 17:34 ` Ralf Baechle
2014-07-30 17:39 ` Paul Burton
@ 2014-07-30 17:53 ` Maciej W. Rozycki
1 sibling, 0 replies; 7+ messages in thread
From: Maciej W. Rozycki @ 2014-07-30 17:53 UTC (permalink / raw)
To: Ralf Baechle; +Cc: Paul Burton, linux-mips, stable
On Wed, 30 Jul 2014, Ralf Baechle wrote:
> > 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.
>
> Good catch - but I think something like UML on a more proper fix. How
> until then I'm going to apply this.
I'm not sure what you mean by UML, but this is definitely a valid action,
you need to be able to do anything from GDB that a program can do itself,
and a program can raise FP exceptions to itself by fiddling with CP1.FCSR;
this is even required by the ISO C language standard (see the pieces in
<fenv.h>). So I think the kernel should be prepared to handle such
exceptions on context switches; and also emulate them if no FP hardware is
used.
I suspect a similar condition exists when a program writes to the saved
image of CP1.FCSR in a signal handler and then restores that context. I
don't know offhand if this is supported by any standard though;
intuitively it should.
Maciej
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] MIPS: prevent user from setting FCSR cause bits
2014-07-30 17:39 ` Paul Burton
(?)
@ 2014-07-31 7:19 ` Ralf Baechle
-1 siblings, 0 replies; 7+ messages in thread
From: Ralf Baechle @ 2014-07-31 7:19 UTC (permalink / raw)
To: Paul Burton; +Cc: linux-mips, stable
On Wed, Jul 30, 2014 at 06:39:16PM +0100, Paul Burton wrote:
> Any chance you could expand that acronym for me? Maybe I'm being slow
> since neither of the expansions that spring to mind make much sense.
UML - User Mode Linux. What I meant is something like UML might have a
legitimate reason to load values triggering exceptions into the FPU.
Obviously with UML not being supported on Linux that's hard to check
for sure ...
Ralf
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2014-07-31 7:20 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-22 13:21 [PATCH] MIPS: prevent user from setting FCSR cause bits Paul Burton
2014-07-22 13:21 ` Paul Burton
2014-07-30 17:34 ` Ralf Baechle
2014-07-30 17:39 ` Paul Burton
2014-07-30 17:39 ` Paul Burton
2014-07-31 7:19 ` Ralf Baechle
2014-07-30 17:53 ` Maciej W. Rozycki
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.