mirror of
https://src.fedoraproject.org/rpms/grub2.git
synced 2024-11-28 07:44:52 +00:00
70 lines
2.2 KiB
Diff
70 lines
2.2 KiB
Diff
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||
|
From: Leo Sandoval <lsandova@redhat.com>
|
||
|
Date: Wed, 29 May 2024 17:35:35 -0600
|
||
|
Subject: [PATCH] loader/efi/linux.c: read the kernel image before header
|
||
|
|
||
|
Signed-off-by: Leo Sandoval <lsandova@redhat.com>
|
||
|
---
|
||
|
grub-core/loader/efi/linux.c | 34 ++++++++++++++++++++--------------
|
||
|
1 file changed, 20 insertions(+), 14 deletions(-)
|
||
|
|
||
|
diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c
|
||
|
index d9ded7c4f12..3ada50ed969 100644
|
||
|
--- a/grub-core/loader/efi/linux.c
|
||
|
+++ b/grub-core/loader/efi/linux.c
|
||
|
@@ -559,6 +559,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||
|
grub_file_t file = 0;
|
||
|
struct linux_arch_kernel_header lh;
|
||
|
grub_off_t filelen;
|
||
|
+ grub_off_t filereadlen;
|
||
|
grub_uint32_t align;
|
||
|
grub_uint32_t code_size;
|
||
|
void *kernel = NULL;
|
||
|
@@ -592,6 +593,25 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||
|
if (!file)
|
||
|
goto fail;
|
||
|
|
||
|
+ filelen = grub_file_size (file);
|
||
|
+ kernel = grub_malloc(filelen);
|
||
|
+ if (!kernel)
|
||
|
+ {
|
||
|
+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("cannot allocate kernel load buffer"));
|
||
|
+ goto fail;
|
||
|
+ }
|
||
|
+
|
||
|
+ filereadlen = grub_file_read (file, kernel, filelen);
|
||
|
+ grub_dprintf ("linux", "filelen : %lld\n", (long long) filelen);
|
||
|
+ grub_dprintf ("linux", "filereadlen : %lld\n", (long long) filereadlen);
|
||
|
+
|
||
|
+ if (filereadlen < filelen)
|
||
|
+ {
|
||
|
+ grub_error (GRUB_ERR_FILE_READ_ERROR, N_("Can't read kernel %s"),
|
||
|
+ argv[0]);
|
||
|
+ goto fail;
|
||
|
+ }
|
||
|
+
|
||
|
if (grub_arch_efi_linux_load_image_header (file, &lh) != GRUB_ERR_NONE)
|
||
|
#if !defined(__i386__) && !defined(__x86_64__)
|
||
|
goto fail;
|
||
|
@@ -612,20 +632,6 @@ fallback:
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
- filelen = grub_file_size (file);
|
||
|
- kernel = grub_malloc(filelen);
|
||
|
- if (!kernel)
|
||
|
- {
|
||
|
- grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("cannot allocate kernel load buffer"));
|
||
|
- goto fail;
|
||
|
- }
|
||
|
-
|
||
|
- if (grub_file_read (file, kernel, filelen) < (grub_ssize_t)filelen)
|
||
|
- {
|
||
|
- grub_error (GRUB_ERR_FILE_READ_ERROR, N_("Can't read kernel %s"),
|
||
|
- argv[0]);
|
||
|
- goto fail;
|
||
|
- }
|
||
|
|
||
|
#if !defined(__i386__) && !defined(__x86_64__)
|
||
|
if (parse_pe_header (kernel, &kernel_size, &handover_offset, &align, &code_size) != GRUB_ERR_NONE)
|