Skip to contentSkip to conversation

kern/efi/mm: Detect calls to grub_efi_drop_alloc() with wrong page counts

PATCH In review Mate Kukri 2 participants 2 messages Jun 12, 2024

lore
Share & tools
lore

Mate Kukri

author
#0 lore raw

PATCH 3/3 kern/efi/mm: Detect calls to grub_efi_drop_alloc() with wrong page counts

Silently keeping entries in the list if the address matches, but the page count doesn't is a bad idea, and can lead to double frees.

grub_efi_free_pages() have already freed parts of this block by this point, and thus keeping the whole block in the list and freeing it again at exit can lead to double frees.

---
 grub-core/kern/efi/mm.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
grub-core/kern/efi/mm.c +4 -2
index 661319194..d45d0e2ac 100644
@@ -95,8 +95,10 @@ grub_efi_drop_alloc (grub_efi_physical_address_t address,
 
   for (eap = NULL, ea = efi_allocated_memory; ea; eap = ea, ea = ea->next)
     {
-      if (ea->address != address || ea->pages != pages)
-         continue;
+      if (ea->address != address)
+	continue;
+      if (ea->pages != pages)
+	grub_fatal ("grub_efi_drop_alloc() called with wrong page count");
 
       /* Remove the current entry from the list. */
       if (eap)
Signature · 7 lines
2.39.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Reviewed-by on v1 3/3
#1 lore raw
Quoted 8 lines · Mate Kukri

Silently keeping entries in the list if the address matches, but the page count doesn't is a bad idea, and can lead to double frees.

grub_efi_free_pages() have already freed parts of this block by this point, and thus keeping the whole block in the list and freeing it again at exit can lead to double frees.

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel