Skip to content

Commit c98a76e

Browse files
nivedita76Ingo Molnar
authored andcommitted
x86/boot/compressed: Fix reloading of GDTR post-relocation
The following commit: ef5a7b5 ("efi/x86: Remove GDT setup from efi_main") introduced GDT setup into the 32-bit kernel's startup_32, and reloads the GDTR after relocating the kernel for paranoia's sake. A followup commit: 32d0091 ("x86/boot: Reload GDTR after copying to the end of the buffer") introduced a similar GDTR reload in the 64-bit kernel as well. The GDTR is adjusted by (init_size-_end), however this may not be the correct offset to apply if the kernel was loaded at a misaligned address or below LOAD_PHYSICAL_ADDR, as in that case the decompression buffer has an additional offset from the original load address. This should never happen for a conformant bootloader, but we're being paranoid anyway, so just store the new GDT address in there instead of adding any offsets, which is simpler as well. Fixes: ef5a7b5 ("efi/x86: Remove GDT setup from efi_main") Fixes: 32d0091 ("x86/boot: Reload GDTR after copying to the end of the buffer") Signed-off-by: Arvind Sankar <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: [email protected] Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected]
1 parent 3e03dca commit c98a76e

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

arch/x86/boot/compressed/head_32.S

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,11 @@ SYM_FUNC_START(startup_32)
139139
/*
140140
* The GDT may get overwritten either during the copy we just did or
141141
* during extract_kernel below. To avoid any issues, repoint the GDTR
142-
* to the new copy of the GDT. EAX still contains the previously
143-
* calculated relocation offset of init_size - _end.
142+
* to the new copy of the GDT.
144143
*/
145-
leal gdt(%ebx), %edx
146-
addl %eax, 2(%edx)
147-
lgdt (%edx)
144+
leal gdt(%ebx), %eax
145+
movl %eax, 2(%eax)
146+
lgdt (%eax)
148147

149148
/*
150149
* Jump to the relocated address.

arch/x86/boot/compressed/head_64.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,8 @@ trampoline_return:
456456
* to the new copy of the GDT.
457457
*/
458458
leaq gdt64(%rbx), %rax
459-
subq %rbp, 2(%rax)
460-
addq %rbx, 2(%rax)
459+
leaq gdt(%rbx), %rdx
460+
movq %rdx, 2(%rax)
461461
lgdt (%rax)
462462

463463
/*

0 commit comments

Comments
 (0)