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

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