Skip to content

Commit cf6b836

Browse files
committed
efi/libstub: Make initrd file loader configurable
Loading an initrd passed via the kernel command line is deprecated: it is limited to files that reside in the same volume as the one the kernel itself was loaded from, and we have more flexible ways to achieve the same. So make it configurable so new architectures can decide not to enable it. Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent 2e0eb48 commit cf6b836

File tree

3 files changed

+47
-34
lines changed

3 files changed

+47
-34
lines changed

drivers/firmware/efi/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,17 @@ config EFI_ARMSTUB_DTB_LOADER
124124
functionality for bootloaders that do not have such support
125125
this option is necessary.
126126

127+
config EFI_GENERIC_STUB_INITRD_CMDLINE_LOADER
128+
bool "Enable the command line initrd loader"
129+
depends on EFI_GENERIC_STUB
130+
default y
131+
help
132+
Select this config option to add support for the initrd= command
133+
line parameter, allowing an initrd that resides on the same volume
134+
as the kernel image to be loaded into memory.
135+
136+
This method is deprecated.
137+
127138
config EFI_BOOTLOADER_CONTROL
128139
tristate "EFI Bootloader Control"
129140
depends on EFI_VARS

drivers/firmware/efi/libstub/efistub.h

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -651,15 +651,35 @@ efi_status_t efi_parse_options(char const *cmdline);
651651
efi_status_t efi_setup_gop(struct screen_info *si, efi_guid_t *proto,
652652
unsigned long size);
653653

654-
efi_status_t efi_load_dtb(efi_loaded_image_t *image,
655-
unsigned long *load_addr,
656-
unsigned long *load_size);
657-
658-
efi_status_t efi_load_initrd(efi_loaded_image_t *image,
659-
unsigned long *load_addr,
660-
unsigned long *load_size,
661-
unsigned long soft_limit,
662-
unsigned long hard_limit);
654+
efi_status_t handle_cmdline_files(efi_loaded_image_t *image,
655+
const efi_char16_t *optstr,
656+
int optstr_size,
657+
unsigned long soft_limit,
658+
unsigned long hard_limit,
659+
unsigned long *load_addr,
660+
unsigned long *load_size);
661+
662+
663+
static inline efi_status_t efi_load_dtb(efi_loaded_image_t *image,
664+
unsigned long *load_addr,
665+
unsigned long *load_size)
666+
{
667+
return handle_cmdline_files(image, L"dtb=", sizeof(L"dtb=") - 2,
668+
ULONG_MAX, ULONG_MAX, load_addr, load_size);
669+
}
670+
671+
static inline efi_status_t efi_load_initrd(efi_loaded_image_t *image,
672+
unsigned long *load_addr,
673+
unsigned long *load_size,
674+
unsigned long soft_limit,
675+
unsigned long hard_limit)
676+
{
677+
if (!IS_ENABLED(CONFIG_EFI_GENERIC_STUB_INITRD_CMDLINE_LOADER))
678+
return EFI_SUCCESS;
679+
680+
return handle_cmdline_files(image, L"initrd=", sizeof(L"initrd=") - 2,
681+
soft_limit, hard_limit, load_addr, load_size);
682+
}
663683

664684
efi_status_t efi_load_initrd_dev_path(unsigned long *load_addr,
665685
unsigned long *load_size,

drivers/firmware/efi/libstub/file.c

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,13 @@ static int find_file_option(const efi_char16_t *cmdline, int cmdline_len,
121121
* We only support loading a file from the same filesystem as
122122
* the kernel image.
123123
*/
124-
static efi_status_t handle_cmdline_files(efi_loaded_image_t *image,
125-
const efi_char16_t *optstr,
126-
int optstr_size,
127-
unsigned long soft_limit,
128-
unsigned long hard_limit,
129-
unsigned long *load_addr,
130-
unsigned long *load_size)
124+
efi_status_t handle_cmdline_files(efi_loaded_image_t *image,
125+
const efi_char16_t *optstr,
126+
int optstr_size,
127+
unsigned long soft_limit,
128+
unsigned long hard_limit,
129+
unsigned long *load_addr,
130+
unsigned long *load_size)
131131
{
132132
const efi_char16_t *cmdline = image->load_options;
133133
int cmdline_len = image->load_options_size / 2;
@@ -239,21 +239,3 @@ static efi_status_t handle_cmdline_files(efi_loaded_image_t *image,
239239
efi_free(alloc_size, alloc_addr);
240240
return status;
241241
}
242-
243-
efi_status_t efi_load_dtb(efi_loaded_image_t *image,
244-
unsigned long *load_addr,
245-
unsigned long *load_size)
246-
{
247-
return handle_cmdline_files(image, L"dtb=", sizeof(L"dtb=") - 2,
248-
ULONG_MAX, ULONG_MAX, load_addr, load_size);
249-
}
250-
251-
efi_status_t efi_load_initrd(efi_loaded_image_t *image,
252-
unsigned long *load_addr,
253-
unsigned long *load_size,
254-
unsigned long soft_limit,
255-
unsigned long hard_limit)
256-
{
257-
return handle_cmdline_files(image, L"initrd=", sizeof(L"initrd=") - 2,
258-
soft_limit, hard_limit, load_addr, load_size);
259-
}

0 commit comments

Comments
 (0)