]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
kern/efi/mm: Fix use-after-free in finish boot services
authorAlec Brown <alec.r.brown@oracle.com>
Mon, 22 May 2023 20:52:49 +0000 (16:52 -0400)
committerDaniel Kiper <daniel.kiper@oracle.com>
Thu, 25 May 2023 14:48:00 +0000 (16:48 +0200)
In grub-core/kern/efi/mm.c, grub_efi_finish_boot_services() has an instance
where the memory for the variable finish_mmap_buf is freed, but on the next
iteration of a while loop, grub_efi_get_memory_map() uses finish_mmap_buf. To
prevent this, we can set finish_mmap_buf to NULL after the free.

Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/kern/efi/mm.c

index 2be0e697359d4ffd49e5e8c1a9acbe6e7b698020..6a6fba891846d6ea8ecd89e456ee9ad3613f7fc0 100644 (file)
@@ -263,6 +263,7 @@ grub_efi_finish_boot_services (grub_efi_uintn_t *outbuf_size, void *outbuf,
                                   &finish_desc_size, &finish_desc_version) <= 0)
        {
          grub_free (finish_mmap_buf);
+         finish_mmap_buf = NULL;
          return grub_error (GRUB_ERR_IO, "couldn't retrieve memory map");
        }
 
@@ -274,10 +275,12 @@ grub_efi_finish_boot_services (grub_efi_uintn_t *outbuf_size, void *outbuf,
       if (status != GRUB_EFI_INVALID_PARAMETER)
        {
          grub_free (finish_mmap_buf);
+         finish_mmap_buf = NULL;
          return grub_error (GRUB_ERR_IO, "couldn't terminate EFI services");
        }
 
       grub_free (finish_mmap_buf);
+      finish_mmap_buf = NULL;
       grub_printf ("Trying to terminate EFI services again\n");
     }
   grub_efi_is_finished = 1;