]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
x86/efi: Avoid triple faults during EFI mixed mode calls
authorMatt Fleming <matt.fleming@intel.com>
Tue, 13 Jan 2015 15:25:00 +0000 (15:25 +0000)
committerBen Hutchings <ben@decadent.org.uk>
Thu, 12 Oct 2017 14:28:15 +0000 (15:28 +0100)
commit910b687e06273ba8b112c984aae35cb648ff9330
tree409875b77a1521f8f5fe924d1b513c4cf218a1e7
parentac500cd3863d7f89c448d77416b5fb25b2c734bc
x86/efi: Avoid triple faults during EFI mixed mode calls

commit 96738c69a7fcdbf0d7c9df0c8a27660011e82a7b upstream.

Andy pointed out that if an NMI or MCE is received while we're in the
middle of an EFI mixed mode call a triple fault will occur. This can
happen, for example, when issuing an EFI mixed mode call while running
perf.

The reason for the triple fault is that we execute the mixed mode call
in 32-bit mode with paging disabled but with 64-bit kernel IDT handlers
installed throughout the call.

At Andy's suggestion, stop playing the games we currently do at runtime,
such as disabling paging and installing a 32-bit GDT for __KERNEL_CS. We
can simply switch to the __KERNEL32_CS descriptor before invoking
firmware services, and run in compatibility mode. This way, if an
NMI/MCE does occur the kernel IDT handler will execute correctly, since
it'll jump to __KERNEL_CS automatically.

However, this change is only possible post-ExitBootServices(). Before
then the firmware "owns" the machine and expects for its 32-bit IDT
handlers to be left intact to service interrupts, etc.

So, we now need to distinguish between early boot and runtime
invocations of EFI services. During early boot, we need to restore the
GDT that the firmware expects to be present. We can only jump to the
__KERNEL32_CS code segment for mixed mode calls after ExitBootServices()
has been invoked.

A liberal sprinkling of comments in the thunking code should make the
differences in early and late environments more apparent.

Reported-by: Andy Lutomirski <luto@amacapital.net>
Tested-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
[bwh: Backported to 3.16: in arch/x86/boot/compressed/Makefile, add the new
 object file to VMLINUX_OBJS]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
arch/x86/boot/compressed/Makefile
arch/x86/boot/compressed/efi_stub_64.S
arch/x86/boot/compressed/efi_thunk_64.S [new file with mode: 0644]
arch/x86/platform/efi/efi_stub_64.S
arch/x86/platform/efi/efi_thunk_64.S