nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0197-loader-linux-do-not-pad-initrd-with-zeroes-at-the-en.patch

4fe85b
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
4fe85b
From: Andrei Borzenkov <arvidjaar@gmail.com>
4fe85b
Date: Thu, 7 May 2015 20:24:24 +0300
4fe85b
Subject: [PATCH] loader/linux: do not pad initrd with zeroes at the end
4fe85b
4fe85b
Syslinux memdisk is using initrd image and needs to know uncompressed
4fe85b
size in advance. For gzip uncompressed size is at the end of compressed
4fe85b
stream. Grub padded each input file to 4 bytes at the end, which means
4fe85b
syslinux got wrong size.
4fe85b
4fe85b
Linux initramfs loader apparently does not care about trailing alignment.
4fe85b
So change code to align beginning of each file instead which atomatically
4fe85b
gives us the correct size for single file.
4fe85b
4fe85b
Reported-By: David Shaw <dshaw@jabberwocky.com>
4fe85b
4fe85b
(cherry picked from commit a8c473288d3f0a5e17a903a5121dea1a695dda3b)
4fe85b
4fe85b
Resolves: rhbz#1219864
4fe85b
---
4fe85b
 grub-core/loader/linux.c | 11 +++++++----
4fe85b
 1 file changed, 7 insertions(+), 4 deletions(-)
4fe85b
4fe85b
diff --git a/grub-core/loader/linux.c b/grub-core/loader/linux.c
4fe85b
index 117232f0c95..d2cd591f604 100644
4fe85b
--- a/grub-core/loader/linux.c
4fe85b
+++ b/grub-core/loader/linux.c
4fe85b
@@ -161,6 +161,9 @@ grub_initrd_init (int argc, char *argv[],
4fe85b
   for (i = 0; i < argc; i++)
4fe85b
     {
4fe85b
       const char *fname = argv[i];
4fe85b
+
4fe85b
+      initrd_ctx->size = ALIGN_UP (initrd_ctx->size, 4);
4fe85b
+
4fe85b
       if (grub_memcmp (argv[i], "newc:", 5) == 0)
4fe85b
 	{
4fe85b
 	  const char *ptr, *eptr;
4fe85b
@@ -205,7 +208,7 @@ grub_initrd_init (int argc, char *argv[],
4fe85b
       initrd_ctx->nfiles++;
4fe85b
       initrd_ctx->components[i].size
4fe85b
 	= grub_file_size (initrd_ctx->components[i].file);
4fe85b
-      initrd_ctx->size += ALIGN_UP (initrd_ctx->components[i].size, 4);
4fe85b
+      initrd_ctx->size += initrd_ctx->components[i].size;
4fe85b
     }
4fe85b
 
4fe85b
   if (newc)
4fe85b
@@ -248,10 +251,12 @@ grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx,
4fe85b
   int i;
4fe85b
   int newc = 0;
4fe85b
   struct dir *root = 0;
4fe85b
+  grub_ssize_t cursize = 0;
4fe85b
 
4fe85b
   for (i = 0; i < initrd_ctx->nfiles; i++)
4fe85b
     {
4fe85b
-      grub_ssize_t cursize;
4fe85b
+      grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4));
4fe85b
+      ptr += ALIGN_UP_OVERHEAD (cursize, 4);
4fe85b
 
4fe85b
       if (initrd_ctx->components[i].newc_name)
4fe85b
 	{
4fe85b
@@ -283,8 +288,6 @@ grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx,
4fe85b
 	  return grub_errno;
4fe85b
 	}
4fe85b
       ptr += cursize;
4fe85b
-      grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4));
4fe85b
-      ptr += ALIGN_UP_OVERHEAD (cursize, 4);
4fe85b
     }
4fe85b
   if (newc)
4fe85b
     ptr = make_header (ptr, "TRAILER!!!", sizeof ("TRAILER!!!") - 1, 0, 0);