Blame SOURCES/0450-io-gzio-Add-init_dynamic_block-clean-up-if-unpacking.patch

9723a8
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
9723a8
From: Daniel Axtens <dja@axtens.net>
9723a8
Date: Thu, 21 Jan 2021 00:05:58 +1100
9723a8
Subject: [PATCH] io/gzio: Add init_dynamic_block() clean up if unpacking codes
9723a8
 fails
9723a8
9723a8
init_dynamic_block() didn't clean up gzio->tl and td in some error
9723a8
paths. This left td pointing to part of tl. Then in grub_gzio_close(),
9723a8
when tl was freed the storage for td would also be freed. The code then
9723a8
attempts to free td explicitly, performing a UAF and then a double free.
9723a8
9723a8
Explicitly clean up tl and td in the error paths.
9723a8
9723a8
Signed-off-by: Daniel Axtens <dja@axtens.net>
9723a8
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
9723a8
---
9723a8
 grub-core/io/gzio.c | 12 +++++++++---
9723a8
 1 file changed, 9 insertions(+), 3 deletions(-)
9723a8
9723a8
diff --git a/grub-core/io/gzio.c b/grub-core/io/gzio.c
3efed6
index 6e9b9c9361a..97b34f88574 100644
9723a8
--- a/grub-core/io/gzio.c
9723a8
+++ b/grub-core/io/gzio.c
9723a8
@@ -953,7 +953,7 @@ init_dynamic_block (grub_gzio_t gzio)
9723a8
 	  if ((unsigned) i + j > n)
9723a8
 	    {
9723a8
 	      grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "too many codes found");
9723a8
-	      return;
9723a8
+	      goto fail;
9723a8
 	    }
9723a8
 	  while (j--)
9723a8
 	    ll[i++] = l;
9723a8
@@ -966,7 +966,7 @@ init_dynamic_block (grub_gzio_t gzio)
9723a8
 	  if ((unsigned) i + j > n)
9723a8
 	    {
9723a8
 	      grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "too many codes found");
9723a8
-	      return;
9723a8
+	      goto fail;
9723a8
 	    }
9723a8
 	  while (j--)
9723a8
 	    ll[i++] = 0;
9723a8
@@ -981,7 +981,7 @@ init_dynamic_block (grub_gzio_t gzio)
9723a8
 	  if ((unsigned) i + j > n)
9723a8
 	    {
9723a8
 	      grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "too many codes found");
9723a8
-	      return;
9723a8
+	      goto fail;
9723a8
 	    }
9723a8
 	  while (j--)
9723a8
 	    ll[i++] = 0;
9723a8
@@ -1019,6 +1019,12 @@ init_dynamic_block (grub_gzio_t gzio)
9723a8
   /* indicate we're now working on a block */
9723a8
   gzio->code_state = 0;
9723a8
   gzio->block_len++;
9723a8
+  return;
9723a8
+
9723a8
+ fail:
9723a8
+  huft_free (gzio->tl);
9723a8
+  gzio->td = NULL;
9723a8
+  gzio->tl = NULL;
9723a8
 }
9723a8
 
9723a8