Blame SOURCES/0151-Initialized-initrd_ctx-so-we-don-t-free-a-random-poi.patch

a85e8e
From 22107f5857dd95a55f14fbdf8a78c6b26e9a134e Mon Sep 17 00:00:00 2001
a85e8e
From: Peter Jones <pjones@redhat.com>
a85e8e
Date: Wed, 17 Sep 2014 15:13:14 -0500
a85e8e
Subject: [PATCH 151/260] Initialized initrd_ctx so we don't free a random
a85e8e
 pointer from the stack.
a85e8e
a85e8e
Currently, if "linux" fails, the "goto fail;" in grub_cmd_initrd sends us
a85e8e
into grub_initrd_close() without grub_initrd_init() being called, and thus
a85e8e
it never clears initrd_ctx->components.  grub_initrd_close() then frees that
a85e8e
address, which is stale data from the stack.  If the stack happens to have a
a85e8e
stale *address* there that matches a recent allocation, then you'll get a
a85e8e
double free later.
a85e8e
a85e8e
So initialize the memory up front.
a85e8e
a85e8e
Signed-off-by: Peter Jones <pjones@redhat.com>
a85e8e
---
a85e8e
 grub-core/loader/arm/linux.c              | 2 +-
a85e8e
 grub-core/loader/arm64/linux.c            | 2 +-
a85e8e
 grub-core/loader/i386/linux.c             | 2 +-
a85e8e
 grub-core/loader/i386/pc/linux.c          | 2 +-
a85e8e
 grub-core/loader/ia64/efi/linux.c         | 2 +-
a85e8e
 grub-core/loader/mips/linux.c             | 2 +-
a85e8e
 grub-core/loader/powerpc/ieee1275/linux.c | 2 +-
a85e8e
 grub-core/loader/sparc64/ieee1275/linux.c | 2 +-
a85e8e
 8 files changed, 8 insertions(+), 8 deletions(-)
a85e8e
a85e8e
diff --git a/grub-core/loader/arm/linux.c b/grub-core/loader/arm/linux.c
a85e8e
index e6770d96d..62cbe75d3 100644
a85e8e
--- a/grub-core/loader/arm/linux.c
a85e8e
+++ b/grub-core/loader/arm/linux.c
a85e8e
@@ -396,7 +396,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
a85e8e
 {
a85e8e
   grub_file_t file;
a85e8e
   grub_size_t size = 0;
a85e8e
-  struct grub_linux_initrd_context initrd_ctx;
a85e8e
+  struct grub_linux_initrd_context initrd_ctx = { 0, };
a85e8e
 
a85e8e
   if (argc == 0)
a85e8e
     return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
a85e8e
diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c
a85e8e
index f1d10a164..0dc144e5d 100644
a85e8e
--- a/grub-core/loader/arm64/linux.c
a85e8e
+++ b/grub-core/loader/arm64/linux.c
a85e8e
@@ -328,7 +328,7 @@ static grub_err_t
a85e8e
 grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
a85e8e
 		 int argc, char *argv[])
a85e8e
 {
a85e8e
-  struct grub_linux_initrd_context initrd_ctx;
a85e8e
+  struct grub_linux_initrd_context initrd_ctx = { 0, };
a85e8e
   int initrd_size, initrd_pages;
a85e8e
   void *initrd_mem = NULL;
a85e8e
 
a85e8e
diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c
a85e8e
index 31fb91e2c..2ae176315 100644
a85e8e
--- a/grub-core/loader/i386/linux.c
a85e8e
+++ b/grub-core/loader/i386/linux.c
a85e8e
@@ -1050,7 +1050,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
a85e8e
   grub_addr_t addr_min, addr_max;
a85e8e
   grub_addr_t addr;
a85e8e
   grub_err_t err;
a85e8e
-  struct grub_linux_initrd_context initrd_ctx;
a85e8e
+  struct grub_linux_initrd_context initrd_ctx = { 0, };
a85e8e
 
a85e8e
   if (argc == 0)
a85e8e
     {
a85e8e
diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c
a85e8e
index 672c013e7..b481e4668 100644
a85e8e
--- a/grub-core/loader/i386/pc/linux.c
a85e8e
+++ b/grub-core/loader/i386/pc/linux.c
a85e8e
@@ -388,7 +388,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
a85e8e
   grub_uint8_t *initrd_chunk;
a85e8e
   grub_addr_t initrd_addr;
a85e8e
   grub_err_t err;
a85e8e
-  struct grub_linux_initrd_context initrd_ctx;
a85e8e
+  struct grub_linux_initrd_context initrd_ctx = { 0, };
a85e8e
 
a85e8e
   if (argc == 0)
a85e8e
     {
a85e8e
diff --git a/grub-core/loader/ia64/efi/linux.c b/grub-core/loader/ia64/efi/linux.c
a85e8e
index 87ac49f8c..eb78e6e62 100644
a85e8e
--- a/grub-core/loader/ia64/efi/linux.c
a85e8e
+++ b/grub-core/loader/ia64/efi/linux.c
a85e8e
@@ -568,7 +568,7 @@ static grub_err_t
a85e8e
 grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
a85e8e
 		 int argc, char *argv[])
a85e8e
 {
a85e8e
-  struct grub_linux_initrd_context initrd_ctx;
a85e8e
+  struct grub_linux_initrd_context initrd_ctx = { 0, };
a85e8e
 
a85e8e
   if (argc == 0)
a85e8e
     {
a85e8e
diff --git a/grub-core/loader/mips/linux.c b/grub-core/loader/mips/linux.c
a85e8e
index ef64a5b1d..4a3e8c5df 100644
a85e8e
--- a/grub-core/loader/mips/linux.c
a85e8e
+++ b/grub-core/loader/mips/linux.c
a85e8e
@@ -415,7 +415,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
a85e8e
   void *initrd_src;
a85e8e
   grub_addr_t initrd_dest;
a85e8e
   grub_err_t err;
a85e8e
-  struct grub_linux_initrd_context initrd_ctx;
a85e8e
+  struct grub_linux_initrd_context initrd_ctx = { 0, };
a85e8e
 
a85e8e
   if (argc == 0)
a85e8e
     return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
a85e8e
diff --git a/grub-core/loader/powerpc/ieee1275/linux.c b/grub-core/loader/powerpc/ieee1275/linux.c
a85e8e
index 4a14f66de..787d7dc2a 100644
a85e8e
--- a/grub-core/loader/powerpc/ieee1275/linux.c
a85e8e
+++ b/grub-core/loader/powerpc/ieee1275/linux.c
a85e8e
@@ -333,7 +333,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
a85e8e
   grub_size_t size = 0;
a85e8e
   grub_addr_t first_addr;
a85e8e
   grub_addr_t addr;
a85e8e
-  struct grub_linux_initrd_context initrd_ctx;
a85e8e
+  struct grub_linux_initrd_context initrd_ctx = { 0, };
a85e8e
 
a85e8e
   if (argc == 0)
a85e8e
     {
a85e8e
diff --git a/grub-core/loader/sparc64/ieee1275/linux.c b/grub-core/loader/sparc64/ieee1275/linux.c
a85e8e
index de6ee2f75..c5e8dfab2 100644
a85e8e
--- a/grub-core/loader/sparc64/ieee1275/linux.c
a85e8e
+++ b/grub-core/loader/sparc64/ieee1275/linux.c
a85e8e
@@ -373,7 +373,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
a85e8e
   grub_addr_t paddr;
a85e8e
   grub_addr_t addr;
a85e8e
   int ret;
a85e8e
-  struct grub_linux_initrd_context initrd_ctx;
a85e8e
+  struct grub_linux_initrd_context initrd_ctx = { 0, };
a85e8e
 
a85e8e
   if (argc == 0)
a85e8e
     {
a85e8e
-- 
a85e8e
2.13.0
a85e8e