linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/efi: Load fixmap GDT in efi_call_phys_epilog()
@ 2018-08-31  8:05 Joerg Roedel
  2018-08-31 15:48 ` [tip:x86/urgent] " tip-bot for Joerg Roedel
  0 siblings, 1 reply; 2+ messages in thread
From: Joerg Roedel @ 2018-08-31  8:05 UTC (permalink / raw)
  To: Ard Biesheuvel, Thomas Gleixner, Ingo Molnar
  Cc: Michal Hocko, Andi Kleen, Linus Torvalds, Dave Hansen,
	Pavel Machek, hpa, x86, linux-efi, linux-kernel, Joerg Roedel

From: Joerg Roedel <jroedel@suse.de>

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')
Reported-by: Guenter Roeck <linux@roeck-us.net>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
 arch/x86/platform/efi/efi_32.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
index 324b9332..05ca142 100644
--- a/arch/x86/platform/efi/efi_32.c
+++ b/arch/x86/platform/efi/efi_32.c
@@ -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)
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [tip:x86/urgent] x86/efi: Load fixmap GDT in efi_call_phys_epilog()
  2018-08-31  8:05 [PATCH] x86/efi: Load fixmap GDT in efi_call_phys_epilog() Joerg Roedel
@ 2018-08-31 15:48 ` tip-bot for Joerg Roedel
  0 siblings, 0 replies; 2+ messages in thread
From: tip-bot for Joerg Roedel @ 2018-08-31 15:48 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: ard.biesheuvel, torvalds, linux, ak, dave.hansen, mhocko, hpa,
	linux-kernel, tglx, mingo, jroedel, pavel

Commit-ID:  eeb89e2bb1ac45b0836d4170e97a988c3a746c62
Gitweb:     https://git.kernel.org/tip/eeb89e2bb1ac45b0836d4170e97a988c3a746c62
Author:     Joerg Roedel <jroedel@suse.de>
AuthorDate: Fri, 31 Aug 2018 10:05:38 +0200
Committer:  Thomas Gleixner <tglx@linutronix.de>
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')
Reported-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: hpa@zytor.com
Cc: linux-efi@vger.kernel.org
Link: https://lkml.kernel.org/r/1535702738-10971-1-git-send-email-joro@8bytes.org

---
 arch/x86/platform/efi/efi_32.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
index 324b93328b37..05ca14222463 100644
--- a/arch/x86/platform/efi/efi_32.c
+++ b/arch/x86/platform/efi/efi_32.c
@@ -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)

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-08-31 15:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-31  8:05 [PATCH] x86/efi: Load fixmap GDT in efi_call_phys_epilog() Joerg Roedel
2018-08-31 15:48 ` [tip:x86/urgent] " tip-bot for Joerg Roedel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).