mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 02:01:24 +01:00
EFI: adjust cfg file buffer freeing
The boot services FreePages() needs passing the size. Since we allocated one more byte to put a trailing nul there, we also need to bump the size passed there. Make a small helper function to centralize this. Note that there's no permanent memory leak because of the oversight: The allocation is done using EfiLoaderData, and all memory of that type is later reclaimed anyway. Fixes:df75f77092("EFI: avoid OOB config file reads") Reported-by: Bernhard Kaindl <bernhard.kaindl@citrix.com> Signed-off-by: Jan Beulich <jbeulich@suse.com> Reviewed-by: Bernhard Kaindl <bernhard.kaindl@citrix.com> Acked-by: Daniel P. Smith <dpsmith@apertussolutions.com> master commit:4ff927133emaster date: 2026-05-06 15:11:11 +0200
This commit is contained in:
1 parent
a99d16079d
commit
4563f9c147
1 file changed
+13
-12
+13
-12
@@ -702,6 +702,16 @@ static void __init efi_relocate_esrt(EFI_SYSTEM_TABLE *SystemTable)
|
||||
*/
|
||||
#include "efi-boot.h"
|
||||
|
||||
static void __init free_cfg(void)
|
||||
{
|
||||
if ( !cfg.need_to_free )
|
||||
return;
|
||||
|
||||
/* One extra byte was allocated to put a nul character there. */
|
||||
efi_bs->FreePages(cfg.addr, PFN_UP(cfg.size + 1));
|
||||
cfg.need_to_free = false;
|
||||
}
|
||||
|
||||
void __init noreturn blexit(const CHAR16 *str)
|
||||
{
|
||||
if ( str )
|
||||
@@ -711,8 +721,7 @@ void __init noreturn blexit(const CHAR16 *str)
|
||||
if ( !efi_bs )
|
||||
efi_arch_halt();
|
||||
|
||||
if ( cfg.need_to_free )
|
||||
efi_bs->FreePages(cfg.addr, PFN_UP(cfg.size));
|
||||
free_cfg();
|
||||
if ( kernel.need_to_free )
|
||||
efi_bs->FreePages(kernel.addr, PFN_UP(kernel.size));
|
||||
if ( ramdisk.need_to_free )
|
||||
@@ -1435,11 +1444,7 @@ void EFIAPI __init noreturn efi_start(EFI_HANDLE ImageHandle,
|
||||
name.s = get_value(&cfg, "global", "chain");
|
||||
if ( !name.s )
|
||||
break;
|
||||
if ( cfg.need_to_free )
|
||||
{
|
||||
efi_bs->FreePages(cfg.addr, PFN_UP(cfg.size));
|
||||
cfg.need_to_free = false;
|
||||
}
|
||||
free_cfg();
|
||||
if ( !read_file(dir_handle, s2w(&name), &cfg, NULL) )
|
||||
{
|
||||
PrintStr(L"Chained configuration file '");
|
||||
@@ -1504,11 +1509,7 @@ void EFIAPI __init noreturn efi_start(EFI_HANDLE ImageHandle,
|
||||
|
||||
efi_arch_cfg_file_late(loaded_image, dir_handle, section.s);
|
||||
|
||||
if ( cfg.need_to_free )
|
||||
{
|
||||
efi_bs->FreePages(cfg.addr, PFN_UP(cfg.size));
|
||||
cfg.need_to_free = false;
|
||||
}
|
||||
free_cfg();
|
||||
|
||||
dir_handle->Close(dir_handle);
|
||||
|
||||
|
||||