nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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