From: Arvind Sankar <nivedita@alum.mit.edu>
To: Ingo Molnar <mingo@kernel.org>
Cc: Ard Biesheuvel <ardb@kernel.org>,
linux-efi@vger.kernel.org, Thomas Gleixner <tglx@linutronix.de>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 1/1] x86/boot/compressed: Fix reloading of GDTR post-relocation
Date: Wed, 26 Feb 2020 18:00:31 -0500 [thread overview]
Message-ID: <20200226230031.3011645-2-nivedita@alum.mit.edu> (raw)
In-Reply-To: <20200226204515.2752095-1-nivedita@alum.mit.edu>
Commit ef5a7b5eb13e ("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.
Commit 32d009137a56 ("x86/boot: Reload GDTR after copying to the end of
the buffer") introduced a similar GDTR reload in the 64-bit kernel.
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.
Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
Fixes: ef5a7b5eb13e ("efi/x86: Remove GDT setup from efi_main")
Fixes: 32d009137a56 ("x86/boot: Reload GDTR after copying to the end of the buffer")
---
arch/x86/boot/compressed/head_32.S | 9 ++++-----
arch/x86/boot/compressed/head_64.S | 4 ++--
2 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
index 356060c5332c..2f8138b71ea9 100644
--- a/arch/x86/boot/compressed/head_32.S
+++ b/arch/x86/boot/compressed/head_32.S
@@ -139,12 +139,11 @@ SYM_FUNC_START(startup_32)
/*
* 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. EAX still contains the previously
- * calculated relocation offset of init_size - _end.
+ * to the new copy of the GDT.
*/
- leal gdt(%ebx), %edx
- addl %eax, 2(%edx)
- lgdt (%edx)
+ leal gdt(%ebx), %eax
+ movl %eax, 2(%eax)
+ lgdt (%eax)
/*
* Jump to the relocated address.
diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
index f7bacc4c1494..fcf8feaa57ea 100644
--- a/arch/x86/boot/compressed/head_64.S
+++ b/arch/x86/boot/compressed/head_64.S
@@ -456,8 +456,8 @@ trampoline_return:
* to the new copy of the GDT.
*/
leaq gdt64(%rbx), %rax
- subq %rbp, 2(%rax)
- addq %rbx, 2(%rax)
+ leaq gdt(%rbx), %rdx
+ movq %rdx, 2(%rax)
lgdt (%rax)
/*
--
2.24.1
next prev parent reply other threads:[~2020-02-26 23:00 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-24 13:38 [GIT PULL v2] EFI updates for v5.7 Ard Biesheuvel
2020-02-26 14:27 ` Ingo Molnar
2020-02-26 14:50 ` Ard Biesheuvel
2020-02-26 20:45 ` [PATCH 0/1] Small fix to boot-time GDT handling Arvind Sankar
2020-02-26 23:00 ` [PATCH v2 " Arvind Sankar
2020-02-26 23:00 ` Arvind Sankar [this message]
2020-02-27 8:12 ` [PATCH v2 1/1] x86/boot/compressed: Fix reloading of GDTR post-relocation Ingo Molnar
2020-02-27 15:16 ` Arvind Sankar
2020-02-27 15:21 ` Ard Biesheuvel
2020-02-27 15:54 ` Arvind Sankar
2020-02-27 17:47 ` Ard Biesheuvel
2020-02-27 18:03 ` Arvind Sankar
2020-02-29 9:24 ` Ingo Molnar
2020-02-29 16:50 ` Arvind Sankar
2020-02-26 20:45 ` [PATCH 1/1] x86/boot/compressed/32: " Arvind Sankar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200226230031.3011645-2-nivedita@alum.mit.edu \
--to=nivedita@alum.mit.edu \
--cc=ardb@kernel.org \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).