Skip to content

Commit 80d01ce

Browse files
committed
efi/libstub: Fix command line fallback handling when loading files
CONFIG_CMDLINE, when set, is supposed to serve either as a fallback when no command line is provided by the bootloader, or to be taken into account unconditionally, depending on the configured options. The initrd and dtb loader ignores CONFIG_CMDLINE in either case, and only takes the EFI firmware provided load options into account. This means that configuring the kernel with initrd= or dtb= on the built-in command line does not produce the expected result. Fix this by doing a separate pass over the built-in command line when dealing with initrd= or dtb= options. Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent e6384c3 commit 80d01ce

File tree

1 file changed

+21
-0
lines changed
  • drivers/firmware/efi/libstub

1 file changed

+21
-0
lines changed

drivers/firmware/efi/libstub/file.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ static efi_status_t efi_open_device_path(efi_file_protocol_t **volume,
175175
return status;
176176
}
177177

178+
#ifndef CONFIG_CMDLINE
179+
#define CONFIG_CMDLINE
180+
#endif
181+
182+
static const efi_char16_t builtin_cmdline[] = L"" CONFIG_CMDLINE;
183+
178184
/*
179185
* Check the cmdline for a LILO-style file= arguments.
180186
*
@@ -189,6 +195,7 @@ efi_status_t handle_cmdline_files(efi_loaded_image_t *image,
189195
unsigned long *load_addr,
190196
unsigned long *load_size)
191197
{
198+
const bool ignore_load_options = false;
192199
const efi_char16_t *cmdline = efi_table_attr(image, load_options);
193200
u32 cmdline_len = efi_table_attr(image, load_options_size);
194201
unsigned long efi_chunk_size = ULONG_MAX;
@@ -197,6 +204,7 @@ efi_status_t handle_cmdline_files(efi_loaded_image_t *image,
197204
unsigned long alloc_addr;
198205
unsigned long alloc_size;
199206
efi_status_t status;
207+
bool twopass;
200208
int offset;
201209

202210
if (!load_addr || !load_size)
@@ -209,6 +217,16 @@ efi_status_t handle_cmdline_files(efi_loaded_image_t *image,
209217
efi_chunk_size = EFI_READ_CHUNK_SIZE;
210218

211219
alloc_addr = alloc_size = 0;
220+
221+
if (!ignore_load_options && cmdline_len > 0) {
222+
twopass = IS_ENABLED(CONFIG_CMDLINE_BOOL) ||
223+
IS_ENABLED(CONFIG_CMDLINE_EXTEND);
224+
} else {
225+
do_builtin: cmdline = builtin_cmdline;
226+
cmdline_len = ARRAY_SIZE(builtin_cmdline) - 1;
227+
twopass = false;
228+
}
229+
212230
do {
213231
struct finfo fi;
214232
unsigned long size;
@@ -290,6 +308,9 @@ efi_status_t handle_cmdline_files(efi_loaded_image_t *image,
290308
efi_call_proto(volume, close);
291309
} while (offset > 0);
292310

311+
if (twopass)
312+
goto do_builtin;
313+
293314
*load_addr = alloc_addr;
294315
*load_size = alloc_size;
295316

0 commit comments

Comments
 (0)