Skip to content

Commit ac82d35

Browse files
ardbiesheuvelIngo Molnar
authored andcommitted
efi/libstub/x86: Use ULONG_MAX as upper bound for all allocations
The header flag XLF_CAN_BE_LOADED_ABOVE_4G will inform us whether allocations above 4 GiB for kernel, command line, etc are permitted, so we take it into account when calling efi_allocate_pages() etc. However, CONFIG_EFI_STUB implies CONFIG_RELOCATABLE, and so the flag is guaranteed to be set on x86_64 builds, whereas i386 builds are guaranteed to run under firmware that will not allocate above 4 GB in the first place. So drop the check, and just pass ULONG_MAX as the upper bound for all allocations. Signed-off-by: Ard Biesheuvel <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Link: https://lore.kernel.org/r/[email protected] Link: https://lore.kernel.org/r/[email protected]
1 parent 8d8ab66 commit ac82d35

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

drivers/firmware/efi/libstub/x86-stub.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,6 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
376376
char *cmdline_ptr;
377377
unsigned long ramdisk_addr;
378378
unsigned long ramdisk_size;
379-
bool above4g;
380379

381380
sys_table = sys_table_arg;
382381

@@ -394,10 +393,8 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
394393
image_offset = (void *)startup_32 - image_base;
395394

396395
hdr = &((struct boot_params *)image_base)->hdr;
397-
above4g = hdr->xloadflags & XLF_CAN_BE_LOADED_ABOVE_4G;
398396

399-
status = efi_allocate_pages(0x4000, (unsigned long *)&boot_params,
400-
above4g ? ULONG_MAX : UINT_MAX);
397+
status = efi_allocate_pages(0x4000, (unsigned long *)&boot_params, ULONG_MAX);
401398
if (status != EFI_SUCCESS) {
402399
efi_printk("Failed to allocate lowmem for boot params\n");
403400
efi_exit(handle, status);
@@ -421,8 +418,7 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
421418
hdr->type_of_loader = 0x21;
422419

423420
/* Convert unicode cmdline to ascii */
424-
cmdline_ptr = efi_convert_cmdline(image, &options_size,
425-
above4g ? ULONG_MAX : UINT_MAX);
421+
cmdline_ptr = efi_convert_cmdline(image, &options_size, ULONG_MAX);
426422
if (!cmdline_ptr)
427423
goto fail;
428424

@@ -442,8 +438,7 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
442438
status = efi_load_initrd(image, &ramdisk_addr,
443439
&ramdisk_size,
444440
hdr->initrd_addr_max,
445-
above4g ? ULONG_MAX
446-
: hdr->initrd_addr_max);
441+
ULONG_MAX);
447442
if (status != EFI_SUCCESS)
448443
goto fail2;
449444
hdr->ramdisk_image = ramdisk_addr & 0xffffffff;
@@ -795,12 +790,8 @@ unsigned long efi_main(efi_handle_t handle,
795790
*/
796791
if (!noinitrd()) {
797792
unsigned long addr, size;
798-
unsigned long max_addr = hdr->initrd_addr_max;
799793

800-
if (hdr->xloadflags & XLF_CAN_BE_LOADED_ABOVE_4G)
801-
max_addr = ULONG_MAX;
802-
803-
status = efi_load_initrd_dev_path(&addr, &size, max_addr);
794+
status = efi_load_initrd_dev_path(&addr, &size, ULONG_MAX);
804795
if (status == EFI_SUCCESS) {
805796
hdr->ramdisk_image = (u32)addr;
806797
hdr->ramdisk_size = (u32)size;

0 commit comments

Comments
 (0)