0115-io-gzio-Add-init_dynamic_block-clean-up-if-unpacking.patch 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. From 18490336d91da2b532277cba56473bfed1376fc4 Mon Sep 17 00:00:00 2001
  2. From: Daniel Axtens <dja@axtens.net>
  3. Date: Thu, 21 Jan 2021 00:05:58 +1100
  4. Subject: [PATCH] io/gzio: Add init_dynamic_block() clean up if unpacking codes
  5. fails
  6. init_dynamic_block() didn't clean up gzio->tl and td in some error
  7. paths. This left td pointing to part of tl. Then in grub_gzio_close(),
  8. when tl was freed the storage for td would also be freed. The code then
  9. attempts to free td explicitly, performing a UAF and then a double free.
  10. Explicitly clean up tl and td in the error paths.
  11. Signed-off-by: Daniel Axtens <dja@axtens.net>
  12. Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
  13. Signed-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com>
  14. ---
  15. grub-core/io/gzio.c | 12 +++++++++---
  16. 1 file changed, 9 insertions(+), 3 deletions(-)
  17. diff --git a/grub-core/io/gzio.c b/grub-core/io/gzio.c
  18. index 4a8eaea..4236f0f 100644
  19. --- a/grub-core/io/gzio.c
  20. +++ b/grub-core/io/gzio.c
  21. @@ -953,7 +953,7 @@ init_dynamic_block (grub_gzio_t gzio)
  22. if ((unsigned) i + j > n)
  23. {
  24. grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "too many codes found");
  25. - return;
  26. + goto fail;
  27. }
  28. while (j--)
  29. ll[i++] = l;
  30. @@ -966,7 +966,7 @@ init_dynamic_block (grub_gzio_t gzio)
  31. if ((unsigned) i + j > n)
  32. {
  33. grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "too many codes found");
  34. - return;
  35. + goto fail;
  36. }
  37. while (j--)
  38. ll[i++] = 0;
  39. @@ -981,7 +981,7 @@ init_dynamic_block (grub_gzio_t gzio)
  40. if ((unsigned) i + j > n)
  41. {
  42. grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "too many codes found");
  43. - return;
  44. + goto fail;
  45. }
  46. while (j--)
  47. ll[i++] = 0;
  48. @@ -1019,6 +1019,12 @@ init_dynamic_block (grub_gzio_t gzio)
  49. /* indicate we're now working on a block */
  50. gzio->code_state = 0;
  51. gzio->block_len++;
  52. + return;
  53. +
  54. + fail:
  55. + huft_free (gzio->tl);
  56. + gzio->td = NULL;
  57. + gzio->tl = NULL;
  58. }
  59. --
  60. 2.14.2