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

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