mirror of
https://src.fedoraproject.org/rpms/grub2.git
synced 2024-11-24 14:32:58 +00:00
9ba4d688c7
Signed-off-by: Leo Sandoval <lsandova@redhat.com>
95 lines
3.6 KiB
Diff
95 lines
3.6 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Jeremy Linton <jeremy.linton@arm.com>
|
|
Date: Tue, 16 Apr 2024 13:26:55 -0600
|
|
Subject: [PATCH] Correct BSS zeroing on aarch64
|
|
|
|
The aarch64 loader doesn't use efi bootservices, and
|
|
therefor it has a very minimal loader which makes a lot
|
|
of assumptions about the kernel layout. With the ZBOOT
|
|
changes, the layout has changed a bit and we not should
|
|
really be parsing the PE sections to determine how much
|
|
data to copy, otherwise the BSS won't be setup properly.
|
|
|
|
This code still makes a lot of assumptions about the
|
|
the kernel layout, so its far from ideal, but it works.
|
|
|
|
Resolves: rhbz#2125069
|
|
|
|
Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
|
|
---
|
|
grub-core/loader/efi/linux.c | 27 ++++++++++++++++++++++-----
|
|
1 file changed, 22 insertions(+), 5 deletions(-)
|
|
|
|
diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c
|
|
index ecaa8c18c4d..55c5c8600d4 100644
|
|
--- a/grub-core/loader/efi/linux.c
|
|
+++ b/grub-core/loader/efi/linux.c
|
|
@@ -517,10 +517,12 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
|
|
static grub_err_t
|
|
parse_pe_header (void *kernel, grub_uint64_t *total_size,
|
|
grub_uint32_t *entry_offset,
|
|
- grub_uint32_t *alignment)
|
|
+ grub_uint32_t *alignment, grub_uint32_t *code_size)
|
|
{
|
|
struct linux_arch_kernel_header *lh = kernel;
|
|
struct grub_armxx_linux_pe_header *pe;
|
|
+ grub_uint16_t i;
|
|
+ struct grub_pe32_section_table *sections;
|
|
|
|
pe = (void *)((unsigned long)kernel + lh->hdr_offset);
|
|
|
|
@@ -530,6 +532,19 @@ parse_pe_header (void *kernel, grub_uint64_t *total_size,
|
|
*total_size = pe->opt.image_size;
|
|
*entry_offset = pe->opt.entry_addr;
|
|
*alignment = pe->opt.section_alignment;
|
|
+ *code_size = pe->opt.section_alignment;
|
|
+
|
|
+ sections = (struct grub_pe32_section_table *) ((char *)&pe->opt +
|
|
+ pe->coff.optional_header_size);
|
|
+ grub_dprintf ("linux", "num_sections : %d\n", pe->coff.num_sections );
|
|
+ for (i = 0 ; i < pe->coff.num_sections; i++)
|
|
+ {
|
|
+ grub_dprintf ("linux", "raw_size : %lld\n",
|
|
+ (long long) sections[i].raw_data_size);
|
|
+ grub_dprintf ("linux", "virt_size : %lld\n",
|
|
+ (long long) sections[i].virtual_size);
|
|
+ *code_size += sections[i].raw_data_size;
|
|
+ }
|
|
|
|
return GRUB_ERR_NONE;
|
|
}
|
|
@@ -543,6 +558,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
|
struct linux_arch_kernel_header lh;
|
|
grub_off_t filelen;
|
|
grub_uint32_t align;
|
|
+ grub_uint32_t code_size;
|
|
void *kernel = NULL;
|
|
grub_err_t err;
|
|
|
|
@@ -610,11 +626,12 @@ fallback:
|
|
}
|
|
|
|
#if !defined(__i386__) && !defined(__x86_64__)
|
|
- if (parse_pe_header (kernel, &kernel_size, &handover_offset, &align) != GRUB_ERR_NONE)
|
|
+ if (parse_pe_header (kernel, &kernel_size, &handover_offset, &align, &code_size) != GRUB_ERR_NONE)
|
|
goto fail;
|
|
grub_dprintf ("linux", "kernel mem size : %lld\n", (long long) kernel_size);
|
|
grub_dprintf ("linux", "kernel entry offset : %d\n", handover_offset);
|
|
grub_dprintf ("linux", "kernel alignment : 0x%x\n", align);
|
|
+ grub_dprintf ("linux", "kernel size : 0x%x\n", code_size);
|
|
|
|
grub_loader_unset();
|
|
|
|
@@ -629,9 +646,9 @@ fallback:
|
|
kernel_addr = (void *)ALIGN_UP((grub_uint64_t)kernel_alloc_addr, align);
|
|
|
|
grub_dprintf ("linux", "kernel @ %p\n", kernel_addr);
|
|
- grub_memcpy (kernel_addr, kernel, grub_min(filelen, kernel_size));
|
|
- if (kernel_size > filelen)
|
|
- grub_memset ((char *)kernel_addr + filelen, 0, kernel_size - filelen);
|
|
+ grub_memcpy (kernel_addr, kernel, grub_min(code_size, kernel_size));
|
|
+ if (kernel_size > code_size)
|
|
+ grub_memset ((char *)kernel_addr + code_size, 0, kernel_size - code_size);
|
|
grub_free(kernel);
|
|
kernel = NULL;
|
|
#endif
|