From: Ard Biesheuvel <ardb@google.com>
To: linux-efi@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel <ardb@kernel.org>,
Evgeniy Baskov <baskov@ispras.ru>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
Ingo Molnar <mingo@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
Peter Jones <pjones@redhat.com>,
Matthew Garrett <mjg59@srcf.ucam.org>,
Gerd Hoffmann <kraxel@redhat.com>,
Kees Cook <keescook@chromium.org>,
"H. Peter Anvin" <hpa@zytor.com>
Subject: [PATCH v2 05/15] x86/boot: Omit compression buffer from PE/COFF image memory footprint
Date: Tue, 12 Sep 2023 09:00:56 +0000 [thread overview]
Message-ID: <20230912090051.4014114-22-ardb@google.com> (raw)
In-Reply-To: <20230912090051.4014114-17-ardb@google.com>
From: Ard Biesheuvel <ardb@kernel.org>
Now that the EFI stub decompresses the kernel and hands over to the
decompressed image directly, there is no longer a need to provide a
decompression buffer as part of the .BSS allocation of the PE/COFF
image. It also means the PE/COFF image can be loaded anywhere in memory,
and setting the preferred image base is unnecessary. So drop the
handling of this from the header and from the build tool.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
| 6 +--
arch/x86/boot/tools/build.c | 50 +++-----------------
2 files changed, 8 insertions(+), 48 deletions(-)
--git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
index b24fa50a9898..a87d9133384b 100644
--- a/arch/x86/boot/header.S
+++ b/arch/x86/boot/header.S
@@ -90,12 +90,10 @@ optional_header:
#endif
extra_header_fields:
- # PE specification requires ImageBase to be 64k aligned
- .set image_base, (LOAD_PHYSICAL_ADDR + 0xffff) & ~0xffff
#ifdef CONFIG_X86_32
- .long image_base # ImageBase
+ .long 0 # ImageBase
#else
- .quad image_base # ImageBase
+ .quad 0 # ImageBase
#endif
.long 0x20 # SectionAlignment
.long 0x20 # FileAlignment
diff --git a/arch/x86/boot/tools/build.c b/arch/x86/boot/tools/build.c
index bd247692b701..0354c223e354 100644
--- a/arch/x86/boot/tools/build.c
+++ b/arch/x86/boot/tools/build.c
@@ -65,7 +65,6 @@ static unsigned long efi_pe_entry;
static unsigned long efi32_pe_entry;
static unsigned long kernel_info;
static unsigned long startup_64;
-static unsigned long _ehead;
static unsigned long _end;
/*----------------------------------------------------------------------*/
@@ -229,27 +228,14 @@ static void update_pecoff_setup_and_reloc(unsigned int size)
#endif
}
-static void update_pecoff_text(unsigned int text_start, unsigned int file_sz,
- unsigned int init_sz)
+static void update_pecoff_text(unsigned int text_start, unsigned int file_sz)
{
unsigned int pe_header;
unsigned int text_sz = file_sz - text_start;
- unsigned int bss_sz = init_sz - file_sz;
+ unsigned int bss_sz = _end - text_sz;
pe_header = get_unaligned_le32(&buf[0x3c]);
- /*
- * The PE/COFF loader may load the image at an address which is
- * misaligned with respect to the kernel_alignment field in the setup
- * header.
- *
- * In order to avoid relocating the kernel to correct the misalignment,
- * add slack to allow the buffer to be aligned within the declared size
- * of the image.
- */
- bss_sz += CONFIG_PHYSICAL_ALIGN;
- init_sz += CONFIG_PHYSICAL_ALIGN;
-
/*
* Size of code: Subtract the size of the first sector (512 bytes)
* which includes the header.
@@ -257,7 +243,7 @@ static void update_pecoff_text(unsigned int text_start, unsigned int file_sz,
put_unaligned_le32(file_sz - 512 + bss_sz, &buf[pe_header + 0x1c]);
/* Size of image */
- put_unaligned_le32(init_sz, &buf[pe_header + 0x50]);
+ put_unaligned_le32(file_sz + bss_sz, &buf[pe_header + 0x50]);
/*
* Address of entry point for PE/COFF executable
@@ -308,8 +294,7 @@ static void efi_stub_entry_update(void)
static inline void update_pecoff_setup_and_reloc(unsigned int size) {}
static inline void update_pecoff_text(unsigned int text_start,
- unsigned int file_sz,
- unsigned int init_sz) {}
+ unsigned int file_sz) {}
static inline void efi_stub_defaults(void) {}
static inline void efi_stub_entry_update(void) {}
@@ -360,7 +345,6 @@ static void parse_zoffset(char *fname)
PARSE_ZOFS(p, efi32_pe_entry);
PARSE_ZOFS(p, kernel_info);
PARSE_ZOFS(p, startup_64);
- PARSE_ZOFS(p, _ehead);
PARSE_ZOFS(p, _end);
p = strchr(p, '\n');
@@ -371,7 +355,7 @@ static void parse_zoffset(char *fname)
int main(int argc, char ** argv)
{
- unsigned int i, sz, setup_sectors, init_sz;
+ unsigned int i, sz, setup_sectors;
int c;
u32 sys_size;
struct stat sb;
@@ -442,31 +426,9 @@ int main(int argc, char ** argv)
buf[0x1f1] = setup_sectors-1;
put_unaligned_le32(sys_size, &buf[0x1f4]);
- init_sz = get_unaligned_le32(&buf[0x260]);
-#ifdef CONFIG_EFI_STUB
- /*
- * The decompression buffer will start at ImageBase. When relocating
- * the compressed kernel to its end, we must ensure that the head
- * section does not get overwritten. The head section occupies
- * [i, i + _ehead), and the destination is [init_sz - _end, init_sz).
- *
- * At present these should never overlap, because 'i' is at most 32k
- * because of SETUP_SECT_MAX, '_ehead' is less than 1k, and the
- * calculation of INIT_SIZE in boot/header.S ensures that
- * 'init_sz - _end' is at least 64k.
- *
- * For future-proofing, increase init_sz if necessary.
- */
-
- if (init_sz - _end < i + _ehead) {
- init_sz = (i + _ehead + _end + 4095) & ~4095;
- put_unaligned_le32(init_sz, &buf[0x260]);
- }
-#endif
- update_pecoff_text(setup_sectors * 512, i + (sys_size * 16), init_sz);
+ update_pecoff_text(setup_sectors * 512, i + (sys_size * 16));
efi_stub_entry_update();
-
/* Update kernel_info offset. */
put_unaligned_le32(kernel_info, &buf[0x268]);
--
2.42.0.283.g2d96d420d3-goog
next prev parent reply other threads:[~2023-09-12 9:02 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-12 9:00 [PATCH v2 00/15] x86/boot: Rework PE header generation Ard Biesheuvel
2023-09-12 9:00 ` [PATCH v2 01/15] x86/efi: Drop EFI stub .bss from .data section Ard Biesheuvel
2023-09-12 9:00 ` [PATCH v2 02/15] x86/efi: Disregard setup header of loaded image Ard Biesheuvel
2023-09-12 9:00 ` [PATCH v2 03/15] x86/efi: Drop alignment flags from PE section headers Ard Biesheuvel
2023-09-12 9:00 ` [PATCH v2 04/15] x86/boot: Remove the 'bugger off' message Ard Biesheuvel
2023-09-12 9:00 ` Ard Biesheuvel [this message]
2023-09-12 9:00 ` [PATCH v2 06/15] x86/boot: Drop redundant code setting the root device Ard Biesheuvel
2023-09-12 9:00 ` [PATCH v2 07/15] x86/boot: Grab kernel_info offset from zoffset header directly Ard Biesheuvel
2023-09-12 9:00 ` [PATCH v2 08/15] x86/boot: Drop references to startup_64 Ard Biesheuvel
2023-09-15 9:15 ` Ingo Molnar
2023-09-15 13:48 ` Ard Biesheuvel
2023-09-15 15:40 ` Ingo Molnar
2023-09-15 15:45 ` Ingo Molnar
2023-09-15 15:48 ` Ard Biesheuvel
2023-09-12 9:01 ` [PATCH v2 09/15] x86/boot: Set EFI handover offset directly in header asm Ard Biesheuvel
2023-09-12 9:01 ` [PATCH v2 10/15] x86/boot: Define setup size in linker script Ard Biesheuvel
2023-09-12 9:01 ` [PATCH v2 11/15] x86/boot: Derive file size from _edata symbol Ard Biesheuvel
2023-09-12 9:01 ` [PATCH v2 12/15] x86/boot: Construct PE/COFF .text section from assembler Ard Biesheuvel
2023-09-12 9:01 ` [PATCH v2 13/15] x86/boot: Drop PE/COFF .reloc section Ard Biesheuvel
2023-09-12 9:01 ` [PATCH v2 14/15] x86/boot: Split off PE/COFF .data section Ard Biesheuvel
2023-09-12 9:01 ` [PATCH v2 15/15] x86/boot: Increase section and file alignment to 4k/512 Ard Biesheuvel
2023-09-15 9:22 ` [PATCH v2 00/15] x86/boot: Rework PE header generation Ingo Molnar
2023-09-15 11:30 ` Ingo Molnar
2023-09-15 13:21 ` Ard Biesheuvel
2023-09-15 13:28 ` Ard Biesheuvel
2023-09-16 9:10 ` Ingo Molnar
2023-09-16 19:14 ` Ard Biesheuvel
2023-09-17 17:50 ` Ingo Molnar
2023-10-03 2:02 ` Jan Hendrik Farr
2023-10-23 11:22 ` Ard Biesheuvel
2023-10-23 17:35 ` Jan Hendrik Farr
2023-10-24 8:21 ` Dave Young
2023-10-24 8:31 ` Dave Young
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=20230912090051.4014114-22-ardb@google.com \
--to=ardb@google.com \
--cc=ardb@kernel.org \
--cc=baskov@ispras.ru \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=keescook@chromium.org \
--cc=kraxel@redhat.com \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=mjg59@srcf.ucam.org \
--cc=pjones@redhat.com \
--cc=tglx@linutronix.de \
/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).