Skip to content

Commit 18ecb3b

Browse files
suryasaimadhuIngo Molnar
authored andcommitted
x86/fpu: Load xsave pointer *after* initialization
So I was playing with gdb today and did this simple thing: gdb /bin/ls ... (gdb) run Box exploded with this splat: BUG: unable to handle kernel NULL pointer dereference at 00000000000001d0 IP: [<ffffffff8100fe5a>] xstateregs_get+0x7a/0x120 [...] Call Trace: ptrace_regset ptrace_request ? wait_task_inactive ? preempt_count_sub arch_ptrace ? ptrace_get_task_struct SyS_ptrace system_call_fastpath ... because we do cache &target->thread.fpu.state->xsave into the local variable xsave but that pointer is NULL at that time and it gets initialized later, in init_fpu(), see: e7f180d ("x86/fpu: Change xstateregs_get()/set() to use ->xsave.i387 rather than ->fxsave") The fix is simple: load xsave *after* init_fpu() has run. Also do the same in xstateregs_set(), as suggested by Oleg Nesterov. Signed-off-by: Borislav Petkov <bp@suse.de> Acked-by: Oleg Nesterov <oleg@redhat.com> Cc: Andy Lutomirski <luto@amacapital.net> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Rik van Riel <riel@redhat.com> Cc: Tavis Ormandy <taviso@google.com> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/1429209697-5902-1-git-send-email-bp@alien8.de Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent fd0f86b commit 18ecb3b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

arch/x86/kernel/i387.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
341341
unsigned int pos, unsigned int count,
342342
void *kbuf, void __user *ubuf)
343343
{
344-
struct xsave_struct *xsave = &target->thread.fpu.state->xsave;
344+
struct xsave_struct *xsave;
345345
int ret;
346346

347347
if (!cpu_has_xsave)
@@ -351,6 +351,8 @@ int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
351351
if (ret)
352352
return ret;
353353

354+
xsave = &target->thread.fpu.state->xsave;
355+
354356
/*
355357
* Copy the 48bytes defined by the software first into the xstate
356358
* memory layout in the thread struct, so that we can copy the entire
@@ -369,7 +371,7 @@ int xstateregs_set(struct task_struct *target, const struct user_regset *regset,
369371
unsigned int pos, unsigned int count,
370372
const void *kbuf, const void __user *ubuf)
371373
{
372-
struct xsave_struct *xsave = &target->thread.fpu.state->xsave;
374+
struct xsave_struct *xsave;
373375
int ret;
374376

375377
if (!cpu_has_xsave)
@@ -379,6 +381,8 @@ int xstateregs_set(struct task_struct *target, const struct user_regset *regset,
379381
if (ret)
380382
return ret;
381383

384+
xsave = &target->thread.fpu.state->xsave;
385+
382386
ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, xsave, 0, -1);
383387
/*
384388
* mxcsr reserved bits must be masked to zero for security reasons.

0 commit comments

Comments
 (0)