Re: [tip:x86/efi] x86/efi: Check for unsafe dealing with FPU state in irq ctxt

From: Andy Lutomirski
Date: Thu Jun 05 2014 - 12:01:27 EST


On Thu, Jun 5, 2014 at 8:53 AM, Borislav Petkov <bp@xxxxxxxxx> wrote:
> On Thu, Jun 05, 2014 at 08:44:20AM -0700, Andy Lutomirski wrote:
>> Are there weird contexts from which EFI calls can happen? It looks
>> like the current code isn't necessarily safe in things that aren't
>> normal process context but aren't interrupts either (e.g. debug traps,
>> #GP, etc).
>
> The efi-pstore thing registers as a kmsg dumper which can be run in NMI
> context and efi can be called there.

NMI might be okay. I haven't checked.

>
>> I wonder if it would make sense at some point to maintain an explicit
>> stack of kernel entries. There doesn't seem to be a reliable way to
>> answer the question of "what context am I in" from C code right now.
>
> So that you can ask int ctxt = what_context_Im_in() and then that
> context can go and change right underneath you. :-)
>

It has to change back, though. Completely unrealistic and useless example:

int ctxt = what_context_im_in();

set_up_the_fpu(ctxt);

// kprobe fires and changes the context
// kprobe does something
// kprobe changes the context back

use the FPU. Life is good.

put_back_the_fpu(ctxt);

--Andy
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/