Blob Blame History Raw
From: Arvind Sankar <nivedita@alum.mit.edu>
Date: Sun, 2 Feb 2020 12:13:49 -0500
Subject: x86/boot: Reload GDTR after copying to the end of the buffer
Git-commit: 32d009137a5646947d450da6fa641a1f4dc1e42c
Patch-mainline: v5.7-rc1
References: jsc#SLE-14337

The GDT may get overwritten during the copy or during extract_kernel,
which will cause problems if any segment register is touched before the
GDTR is reloaded by the decompressed kernel. For safety update the GDTR
to point to the GDT within the copied kernel.

Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
Link: https://lore.kernel.org/r/20200202171353.3736319-4-nivedita@alum.mit.edu
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Acked-by: Joerg Roedel <jroedel@suse.de>
---
 arch/x86/boot/compressed/head_64.S |    9 +++++++++
 1 file changed, 9 insertions(+)

--- a/arch/x86/boot/compressed/head_64.S
+++ b/arch/x86/boot/compressed/head_64.S
@@ -523,6 +523,15 @@ relocated:
 	shrq	$3, %rcx
 	rep	stosq
 
+	/*
+	 * The GDT may get overwritten either during the copy we just did or
+	 * during extract_kernel below. To avoid any issues, repoint the GDTR
+	 * to the new copy of the GDT.
+	 */
+	leaq	gdt(%rip), %rax
+	movq	%rax, gdt64+2(%rip)
+	lgdt	gdt64(%rip)
+
 /*
  * Do the extraction, and jump to the new kernel..
  */