File 689b0c0c-EFI-cond-FreePages.patch of Package xen

# Commit 7fddedd530561797d8ce5fba78e83cc9cc6b58dd
# Date 2025-08-12 11:40:28 +0200
# Author Ross Lagerwall <ross.lagerwall@citrix.com>
# Committer Jan Beulich <jbeulich@suse.com>
efi: Call FreePages() only if needed

If the config file is builtin, cfg.addr will be zero but Xen
unconditionally calls FreePages() on the address.

Xen may also call FreePages() with a zero address if blexit() is called
after this point since cfg.need_to_free is not set to false.

The UEFI specification does not say whether calling FreePages() with a
zero address is allowed so let's be cautious and use cfg.need_to_free
properly.

Fixes: 8a71d50ed40b ("efi: Enable booting unified hypervisor/kernel/initrd images")
Fixes: 04be2c3a0678 ("efi/boot.c: add file.need_to_free")
Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by Daniel P. Smith <dpsmith@apertussolutions.com>

--- a/xen/common/efi/boot.c
+++ b/xen/common/efi/boot.c
@@ -1484,8 +1484,11 @@ void EFIAPI __init noreturn efi_start(EF
 
         efi_arch_cfg_file_late(loaded_image, dir_handle, section.s);
 
-        efi_bs->FreePages(cfg.addr, PFN_UP(cfg.size));
-        cfg.addr = 0;
+        if ( cfg.need_to_free )
+        {
+            efi_bs->FreePages(cfg.addr, PFN_UP(cfg.size));
+            cfg.need_to_free = false;
+        }
 
         dir_handle->Close(dir_handle);
 
openSUSE Build Service is sponsored by