dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0237-linux.c-Ensure-that-initrd-is-page-aligned.patch

f725e3
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
f725e3
From: Vladimir Serbinenko <phcoder@gmail.com>
f725e3
Date: Thu, 7 May 2015 16:23:39 +0200
f725e3
Subject: [PATCH] linux.c: Ensure that initrd is page-aligned.
f725e3
f725e3
---
f725e3
 grub-core/loader/i386/linux.c | 11 +++++------
f725e3
 1 file changed, 5 insertions(+), 6 deletions(-)
f725e3
f725e3
diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c
f725e3
index 53f74ae0685..764cde20318 100644
f725e3
--- a/grub-core/loader/i386/linux.c
f725e3
+++ b/grub-core/loader/i386/linux.c
f725e3
@@ -70,7 +70,6 @@ static grub_addr_t prot_mode_target;
f725e3
 static void *initrd_mem;
f725e3
 static grub_addr_t initrd_mem_target;
f725e3
 static grub_size_t prot_init_space;
f725e3
-static grub_uint32_t initrd_pages;
f725e3
 static struct grub_relocator *relocator = NULL;
f725e3
 static void *efi_mmap_buf;
f725e3
 static grub_size_t maximal_cmdline_size;
f725e3
@@ -1055,7 +1054,7 @@ static grub_err_t
f725e3
 grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
f725e3
 		 int argc, char *argv[])
f725e3
 {
f725e3
-  grub_size_t size = 0;
f725e3
+  grub_size_t size = 0, aligned_size = 0;
f725e3
   grub_addr_t addr_min, addr_max;
f725e3
   grub_addr_t addr;
f725e3
   grub_err_t err;
f725e3
@@ -1077,8 +1076,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
f725e3
     goto fail;
f725e3
 
f725e3
   size = grub_get_initrd_size (&initrd_ctx);
f725e3
-
f725e3
-  initrd_pages = (page_align (size) >> 12);
f725e3
+  aligned_size = ALIGN_UP (size, 4096);
f725e3
 
f725e3
   /* Get the highest address available for the initrd.  */
f725e3
   if (grub_le_to_cpu16 (linux_params.version) >= 0x0203)
f725e3
@@ -1106,7 +1104,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
f725e3
   addr_min = (grub_addr_t) prot_mode_target + prot_init_space;
f725e3
 
f725e3
   /* Put the initrd as high as possible, 4KiB aligned.  */
f725e3
-  addr = (addr_max - size) & ~0xFFF;
f725e3
+  addr = (addr_max - aligned_size) & ~0xFFF;
f725e3
 
f725e3
   if (addr < addr_min)
f725e3
     {
f725e3
@@ -1117,7 +1115,8 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
f725e3
   {
f725e3
     grub_relocator_chunk_t ch;
f725e3
     err = grub_relocator_alloc_chunk_align (relocator, &ch,
f725e3
-					    addr_min, addr, size, 0x1000,
f725e3
+					    addr_min, addr, aligned_size,
f725e3
+					    0x1000,
f725e3
 					    GRUB_RELOCATOR_PREFERENCE_HIGH,
f725e3
 					    1);
f725e3
     if (err)