Skip to contentSkip to conversation

x86/efi: Load fixmap GDT in efi_call_phys_epilog()

PATCH New Joerg Roedel 2 participants 2 messages Aug 31, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/efi: Load fixmap GDT in efi_call_phys_epilog()

From: Joerg Roedel <[email protected]>

When PTI is enabled on x86-32 the kernel uses the GDT mapped in the fixmap for the simple reason that this address is also mapped for user-space.

The efi_call_phys_prolog()/efi_call_phys_epilog() wrappers change the GDT to call EFI runtime services and switch back to the kernel GDT when they return. But the switch-back uses the writable GDT, not the fixmap GDT.

When that happened and and the CPU returns to user-space it switches to the user %cr3 and tries to restore user segment registers. This fails because the writable GDT is not mapped in the user page-table, and without a GDT the fault handlers also can't be launched. The result is a triple fault and reboot of the machine.

Fix that by restoring the GDT back to the fixmap GDT which is also mapped in the user page-table.

Fixes 7757d607c6b3 x86/pti: ('Allow CONFIG_PAGE_TABLE_ISOLATION for x86_32')
---
 arch/x86/platform/efi/efi_32.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
arch/x86/platform/efi/efi_32.c +2 -6
index 324b9332..05ca142 100644
@@ -85,14 +85,10 @@ pgd_t * __init efi_call_phys_prolog(void)
 
 void __init efi_call_phys_epilog(pgd_t *save_pgd)
 {
-	struct desc_ptr gdt_descr;
-
-	gdt_descr.address = (unsigned long)get_cpu_gdt_rw(0);
-	gdt_descr.size = GDT_SIZE - 1;
-	load_gdt(&gdt_descr);
-
 	load_cr3(save_pgd);
 	__flush_tlb_all();
+
+	load_fixmap_gdt(0);
 }
 
 void __init efi_runtime_update_mappings(void)
Signature · 1 line
2.7.4
#1 lore raw
x86/efi: Load fixmap GDT in efi_call_phys_epilog()
Commit-ID:  eeb89e2bb1ac45b0836d4170e97a988c3a746c62
Gitweb:     https://git.kernel.org/tip/eeb89e2bb1ac45b0836d4170e97a988c3a746c62
Author:     Joerg Roedel <[email protected]>
AuthorDate: Fri, 31 Aug 2018 10:05:38 +0200
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Fri, 31 Aug 2018 17:45:54 +0200

x86/efi: Load fixmap GDT in efi_call_phys_epilog()

When PTI is enabled on x86-32 the kernel uses the GDT mapped in the fixmap for the simple reason that this address is also mapped for user-space.

The efi_call_phys_prolog()/efi_call_phys_epilog() wrappers change the GDT to call EFI runtime services and switch back to the kernel GDT when they return. But the switch-back uses the writable GDT, not the fixmap GDT.

When that happened and and the CPU returns to user-space it switches to the user %cr3 and tries to restore user segment registers. This fails because the writable GDT is not mapped in the user page-table, and without a GDT the fault handlers also can't be launched. The result is a triple fault and reboot of the machine.

Fix that by restoring the GDT back to the fixmap GDT which is also mapped in the user page-table.

Fixes 7757d607c6b3 x86/pti: ('Allow CONFIG_PAGE_TABLE_ISOLATION for x86_32')
Cc Ard Biesheuvel <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Pavel Machek <[email protected]>
---
 arch/x86/platform/efi/efi_32.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
arch/x86/platform/efi/efi_32.c +2 -6
index 324b93328b37..05ca14222463 100644
@@ -85,14 +85,10 @@ pgd_t * __init efi_call_phys_prolog(void)
 
 void __init efi_call_phys_epilog(pgd_t *save_pgd)
 {
-	struct desc_ptr gdt_descr;
-
-	gdt_descr.address = (unsigned long)get_cpu_gdt_rw(0);
-	gdt_descr.size = GDT_SIZE - 1;
-	load_gdt(&gdt_descr);
-
 	load_cr3(save_pgd);
 	__flush_tlb_all();
+
+	load_fixmap_gdt(0);
 }
 
 void __init efi_runtime_update_mappings(void)