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

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