Skip to content

Commit 1547a4c

Browse files
tw4452852acrnsi
authored andcommitted
efi-stub: fix stack memory free issue
Because of this commit: commit 63e258b Author: Tianhua Sun <tianhuax.s.sun@intel.com> Date: Wed Jul 17 14:33:47 2019 +0800 efi-stub: update string operation in efi-stub Remove unsafe API in efi-stub 1, use Strnlen instead of StrLen except the parameter is a static string. 2, strlen() only work on static strings. Tracked-On: #3276 Signed-off-by: Tianhua Sun <tianhuax.s.sun@intel.com> Reviewed-by: Yonghua Huang <yonghua.huang@intel.com> In the default case, bootloader_name will be point to a separate ro section which hold the constant string, free this memory later will cause undefined behavior (memory corruption, exception and so on). Tracked-On: #3644 Signed-off-by: Tw <wei.tan@intel.com> Reviewed-by: Jack Ren <jack.ren@intel.com>
1 parent cd1ae7a commit 1547a4c

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

misc/efi-stub/boot.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *_table)
420420
err = get_pe_section(info->ImageBase, section, strlen(section), &sec_addr, &sec_size);
421421
if (EFI_ERROR(err)) {
422422
Print(L"Unable to locate section of ACRNHV %r ", err);
423-
goto failed;
423+
goto free_args;
424424
}
425425

426426
/* without relocateion enabled, hypervisor binary need to reside in
@@ -436,14 +436,14 @@ efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *_table)
436436
err = emalloc_fixed_addr(&hv_hpa, CONFIG_HV_RAM_SIZE, CONFIG_HV_RAM_START);
437437
#endif
438438
if (err != EFI_SUCCESS)
439-
goto failed;
439+
goto free_args;
440440

441441
memcpy((char *)hv_hpa, info->ImageBase + sec_addr, sec_size);
442442

443443
/* load hypervisor and begin to run on it */
444444
err = switch_to_guest_mode(image, hv_hpa);
445445
if (err != EFI_SUCCESS)
446-
goto failed;
446+
goto free_args;
447447

448448
/*
449449
* enable all AP here will reset all APs,
@@ -456,7 +456,7 @@ efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *_table)
456456
if (!path)
457457
goto free_args;
458458

459-
FreePool(bootloader_name);
459+
FreePool(cmdline16);
460460

461461
err = uefi_call_wrapper(boot->LoadImage, 6, FALSE, image,
462462
path, NULL, 0, &bootloader_image);
@@ -476,7 +476,7 @@ efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *_table)
476476
return EFI_SUCCESS;
477477

478478
free_args:
479-
FreePool(bootloader_name);
479+
FreePool(cmdline16);
480480
failed:
481481
/*
482482
* We need to be careful not to trash 'err' here. If we fail

0 commit comments

Comments
 (0)