forked from pool/grub2
005c99a035
- Fix CVE-2021-3981 (bsc#1189644) * 0001-grub-mkconfig-restore-umask-for-grub.cfg.patch - Fix can't allocate initrd error (bsc#1191378) * 0001-Factor-out-grub_efi_linux_boot.patch * 0002-Fix-race-in-EFI-validation.patch * 0003-Handle-multi-arch-64-on-32-boot-in-linuxefi-loader.patch * 0004-Try-to-pick-better-locations-for-kernel-and-initrd.patch * 0005-x86-efi-Use-bounce-buffers-for-reading-to-addresses-.patch * 0006-x86-efi-Re-arrange-grub_cmd_linux-a-little-bit.patch * 0007-x86-efi-Make-our-own-allocator-for-kernel-stuff.patch * 0008-x86-efi-Allow-initrd-params-cmdline-allocations-abov.patch * 0009-x86-efi-Reduce-maximum-bounce-buffer-size-to-16-MiB.patch * 0010-efilinux-Fix-integer-overflows-in-grub_cmd_initrd.patch * 0011-Also-define-GRUB_EFI_MAX_ALLOCATION_ADDRESS-for-RISC.patch OBS-URL: https://build.opensuse.org/request/show/942210 OBS-URL: https://build.opensuse.org/package/show/Base:System/grub2?expand=0&rev=400
134 lines
4.8 KiB
Diff
134 lines
4.8 KiB
Diff
From 24b5c0a3788c5c02b72ea61312f5cf8c39429db1 Mon Sep 17 00:00:00 2001
|
|
From: Peter Jones <pjones@redhat.com>
|
|
Date: Thu, 13 Sep 2018 14:42:34 -0400
|
|
Subject: [PATCH 06/11] x86-efi: Re-arrange grub_cmd_linux() a little bit.
|
|
|
|
This just helps the next patch be easier to read.
|
|
|
|
Signed-off-by: Peter Jones <pjones@redhat.com>
|
|
---
|
|
grub-core/loader/i386/efi/linux.c | 73 +++++++++++++++++--------------
|
|
1 file changed, 40 insertions(+), 33 deletions(-)
|
|
|
|
diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c
|
|
index d6bed4fb4..096a52eb5 100644
|
|
--- a/grub-core/loader/i386/efi/linux.c
|
|
+++ b/grub-core/loader/i386/efi/linux.c
|
|
@@ -227,32 +227,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
|
goto fail;
|
|
}
|
|
|
|
- params = grub_efi_allocate_pages_max (GRUB_EFI_MAX_ALLOCATION_ADDRESS,
|
|
- BYTES_TO_PAGES(sizeof(*params)));
|
|
- if (!params)
|
|
- params = grub_efi_allocate_pages_max (GRUB_EFI_MAX_USABLE_ADDRESS,
|
|
- BYTES_TO_PAGES(sizeof(*params)));
|
|
- if (! params)
|
|
- {
|
|
- grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate kernel parameters");
|
|
- goto fail;
|
|
- }
|
|
-
|
|
- grub_dprintf ("linux", "params = %p\n", params);
|
|
-
|
|
- grub_memset (params, 0, sizeof(*params));
|
|
+ lh = (struct linux_i386_kernel_header *)kernel;
|
|
+ grub_dprintf ("linux", "original lh is at %p\n", kernel);
|
|
|
|
- setup_header_end_offset = *((grub_uint8_t *)kernel + 0x201);
|
|
- grub_dprintf ("linux", "copying %lu bytes from %p to %p\n",
|
|
- MIN((grub_size_t)0x202+setup_header_end_offset,
|
|
- sizeof (*params)) - 0x1f1,
|
|
- (grub_uint8_t *)kernel + 0x1f1,
|
|
- (grub_uint8_t *)params + 0x1f1);
|
|
- grub_memcpy ((grub_uint8_t *)params + 0x1f1,
|
|
- (grub_uint8_t *)kernel + 0x1f1,
|
|
- MIN((grub_size_t)0x202+setup_header_end_offset,sizeof (*params)) - 0x1f1);
|
|
- lh = (struct linux_i386_kernel_header *)params;
|
|
- grub_dprintf ("linux", "lh is at %p\n", lh);
|
|
grub_dprintf ("linux", "checking lh->boot_flag\n");
|
|
if (lh->boot_flag != grub_cpu_to_le16 (0xaa55))
|
|
{
|
|
@@ -300,6 +277,34 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
|
}
|
|
#endif
|
|
|
|
+ params = grub_efi_allocate_pages_max (GRUB_EFI_MAX_ALLOCATION_ADDRESS,
|
|
+ BYTES_TO_PAGES(sizeof(*params)));
|
|
+ if (!params)
|
|
+ params = grub_efi_allocate_pages_max (GRUB_EFI_MAX_USABLE_ADDRESS,
|
|
+ BYTES_TO_PAGES(sizeof(*params)));
|
|
+ if (! params)
|
|
+ {
|
|
+ grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate kernel parameters");
|
|
+ goto fail;
|
|
+ }
|
|
+
|
|
+ grub_dprintf ("linux", "params = %p\n", params);
|
|
+
|
|
+ grub_memset (params, 0, sizeof(*params));
|
|
+
|
|
+ setup_header_end_offset = *((grub_uint8_t *)kernel + 0x201);
|
|
+ grub_dprintf ("linux", "copying %" PRIuGRUB_SIZE " bytes from %p to %p\n",
|
|
+ MIN((grub_size_t)0x202+setup_header_end_offset,
|
|
+ sizeof (*params)) - 0x1f1,
|
|
+ (grub_uint8_t *)kernel + 0x1f1,
|
|
+ (grub_uint8_t *)params + 0x1f1);
|
|
+ grub_memcpy ((grub_uint8_t *)params + 0x1f1,
|
|
+ (grub_uint8_t *)kernel + 0x1f1,
|
|
+ MIN((grub_size_t)0x202+setup_header_end_offset,sizeof (*params)) - 0x1f1);
|
|
+
|
|
+ lh = (struct linux_i386_kernel_header *)params;
|
|
+ grub_dprintf ("linux", "new lh is at %p\n", lh);
|
|
+
|
|
grub_dprintf ("linux", "setting up cmdline\n");
|
|
linux_cmdline = grub_efi_allocate_pages_max(GRUB_EFI_MAX_ALLOCATION_ADDRESS,
|
|
BYTES_TO_PAGES(lh->cmdline_size + 1));
|
|
@@ -324,8 +329,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
|
grub_dprintf ("linux", "setting lh->cmd_line_ptr\n");
|
|
lh->cmd_line_ptr = (grub_uint32_t)(grub_addr_t)linux_cmdline;
|
|
|
|
- grub_dprintf ("linux", "computing handover offset\n");
|
|
handover_offset = lh->handover_offset;
|
|
+ grub_dprintf("linux", "handover_offset: %08x\n", handover_offset);
|
|
|
|
start = (lh->setup_sects + 1) * 512;
|
|
|
|
@@ -342,24 +347,26 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
|
grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate kernel"));
|
|
goto fail;
|
|
}
|
|
-
|
|
- grub_dprintf ("linux", "kernel_mem = %lx\n", (unsigned long) kernel_mem);
|
|
+ grub_dprintf("linux", "kernel_mem = %p\n", kernel_mem);
|
|
|
|
grub_loader_set (grub_linuxefi_boot, grub_linuxefi_unload, 0);
|
|
- loaded=1;
|
|
+
|
|
+ loaded = 1;
|
|
+
|
|
grub_dprintf ("linux", "setting lh->code32_start to %p\n", kernel_mem);
|
|
lh->code32_start = (grub_uint32_t)(grub_addr_t) kernel_mem;
|
|
|
|
grub_memcpy (kernel_mem, (char *)kernel + start, filelen - start);
|
|
|
|
- grub_dprintf ("linux", "setting lh->type_of_loader\n");
|
|
lh->type_of_loader = 0x6;
|
|
+ grub_dprintf ("linux", "setting lh->type_of_loader = 0x%02x\n",
|
|
+ lh->type_of_loader);
|
|
|
|
- grub_dprintf ("linux", "setting lh->ext_loader_{type,ver}\n");
|
|
params->ext_loader_type = 0;
|
|
params->ext_loader_ver = 2;
|
|
- grub_dprintf("linux", "kernel_mem: %p handover_offset: %08x\n",
|
|
- kernel_mem, handover_offset);
|
|
+ grub_dprintf ("linux",
|
|
+ "setting lh->ext_loader_{type,ver} = {0x%02x,0x%02x}\n",
|
|
+ params->ext_loader_type, params->ext_loader_ver);
|
|
|
|
fail:
|
|
|
|
--
|
|
2.31.1
|
|
|