1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
From be9fee51de2cff287aeff055e2eb2fd98a0d187e Mon Sep 17 00:00:00 2001
From: Daniel Kiper <daniel.kiper@oracle.com>
Date: Sat, 18 Jul 2015 00:09:31 +0200
Subject: multiboot2: Do not pass memory maps to image if EFI boot services are
enabled
If image requested EFI boot services then skip multiboot2 memory maps.
Main reason for not providing maps is because they will likely be
invalid. We do a few allocations after filling them, e.g. for relocator
needs. Usually we do not care as we would have finished boot services.
If we keep boot services then it is easier/safer to not provide maps.
However, if image needs memory maps and they are not provided by bootloader
then it should get itself just before ExitBootServices() call.
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Vladimir Serbinenko <phcoder@gmail.com>
Origin: upstream, https://git.savannah.gnu.org/cgit/grub.git/commit/?id=f2b6c20a258b328ae8717cd5624d7b039328bcc0
Bug-Debian: https://bugs.debian.org/930028
Last-Update: 2019-06-12
Patch-Name: multiboot2-do-not-pass-mmaps-if-efi-boot-services.patch
---
grub-core/loader/multiboot_mbi2.c | 73 +++++++++++++++++++--------------------
1 file changed, 36 insertions(+), 37 deletions(-)
diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c
index 6c044024e..ad1553ba7 100644
--- a/grub-core/loader/multiboot_mbi2.c
+++ b/grub-core/loader/multiboot_mbi2.c
@@ -390,7 +390,7 @@ static grub_size_t
grub_multiboot_get_mbi_size (void)
{
#ifdef GRUB_MACHINE_EFI
- if (!efi_mmap_size)
+ if (!keep_bs && !efi_mmap_size)
find_efi_mmap_size ();
#endif
return 2 * sizeof (grub_uint32_t) + sizeof (struct multiboot_tag)
@@ -755,12 +755,13 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
}
}
- {
- struct multiboot_tag_mmap *tag = (struct multiboot_tag_mmap *) ptrorig;
- grub_fill_multiboot_mmap (tag);
- ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
- / sizeof (grub_properly_aligned_t);
- }
+ if (!keep_bs)
+ {
+ struct multiboot_tag_mmap *tag = (struct multiboot_tag_mmap *) ptrorig;
+ grub_fill_multiboot_mmap (tag);
+ ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
+ / sizeof (grub_properly_aligned_t);
+ }
{
struct multiboot_tag_elf_sections *tag
@@ -776,18 +777,19 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
/ sizeof (grub_properly_aligned_t);
}
- {
- struct multiboot_tag_basic_meminfo *tag
- = (struct multiboot_tag_basic_meminfo *) ptrorig;
- tag->type = MULTIBOOT_TAG_TYPE_BASIC_MEMINFO;
- tag->size = sizeof (struct multiboot_tag_basic_meminfo);
-
- /* Convert from bytes to kilobytes. */
- tag->mem_lower = grub_mmap_get_lower () / 1024;
- tag->mem_upper = grub_mmap_get_upper () / 1024;
- ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
- / sizeof (grub_properly_aligned_t);
- }
+ if (!keep_bs)
+ {
+ struct multiboot_tag_basic_meminfo *tag
+ = (struct multiboot_tag_basic_meminfo *) ptrorig;
+ tag->type = MULTIBOOT_TAG_TYPE_BASIC_MEMINFO;
+ tag->size = sizeof (struct multiboot_tag_basic_meminfo);
+
+ /* Convert from bytes to kilobytes. */
+ tag->mem_lower = grub_mmap_get_lower () / 1024;
+ tag->mem_upper = grub_mmap_get_upper () / 1024;
+ ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
+ / sizeof (grub_properly_aligned_t);
+ }
{
struct grub_net_network_level_interface *net;
@@ -886,27 +888,24 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
grub_efi_uintn_t efi_desc_size;
grub_efi_uint32_t efi_desc_version;
- tag->type = MULTIBOOT_TAG_TYPE_EFI_MMAP;
- tag->size = sizeof (*tag) + efi_mmap_size;
-
if (!keep_bs)
- err = grub_efi_finish_boot_services (&efi_mmap_size, tag->efi_mmap, NULL,
- &efi_desc_size, &efi_desc_version);
- else
{
- if (grub_efi_get_memory_map (&efi_mmap_size, (void *) tag->efi_mmap,
- NULL,
- &efi_desc_size, &efi_desc_version) <= 0)
- err = grub_error (GRUB_ERR_IO, "couldn't retrieve memory map");
- }
- if (err)
- return err;
- tag->descr_size = efi_desc_size;
- tag->descr_vers = efi_desc_version;
- tag->size = sizeof (*tag) + efi_mmap_size;
+ tag->type = MULTIBOOT_TAG_TYPE_EFI_MMAP;
+ tag->size = sizeof (*tag) + efi_mmap_size;
- ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
- / sizeof (grub_properly_aligned_t);
+ err = grub_efi_finish_boot_services (&efi_mmap_size, tag->efi_mmap, NULL,
+ &efi_desc_size, &efi_desc_version);
+
+ if (err)
+ return err;
+
+ tag->descr_size = efi_desc_size;
+ tag->descr_vers = efi_desc_version;
+ tag->size = sizeof (*tag) + efi_mmap_size;
+
+ ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
+ / sizeof (grub_properly_aligned_t);
+ }
}
if (keep_bs)
|