Skip to content

Commit 055042b

Browse files
nivedita76ardbiesheuvel
authored andcommitted
efi/libstub: Check return value of efi_parse_options
efi_parse_options can fail if it is unable to allocate space for a copy of the command line. Check the return value to make sure it succeeded. Signed-off-by: Arvind Sankar <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent 7dde67f commit 055042b

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,21 @@ efi_status_t efi_entry(efi_handle_t handle, efi_system_table_t *sys_table_arg)
207207

208208
if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) ||
209209
IS_ENABLED(CONFIG_CMDLINE_FORCE) ||
210-
cmdline_size == 0)
211-
efi_parse_options(CONFIG_CMDLINE);
210+
cmdline_size == 0) {
211+
status = efi_parse_options(CONFIG_CMDLINE);
212+
if (status != EFI_SUCCESS) {
213+
efi_err("Failed to parse options\n");
214+
goto fail_free_cmdline;
215+
}
216+
}
212217

213-
if (!IS_ENABLED(CONFIG_CMDLINE_FORCE) && cmdline_size > 0)
214-
efi_parse_options(cmdline_ptr);
218+
if (!IS_ENABLED(CONFIG_CMDLINE_FORCE) && cmdline_size > 0) {
219+
status = efi_parse_options(cmdline_ptr);
220+
if (status != EFI_SUCCESS) {
221+
efi_err("Failed to parse options\n");
222+
goto fail_free_cmdline;
223+
}
224+
}
215225

216226
efi_info("Booting Linux Kernel...\n");
217227

@@ -223,7 +233,7 @@ efi_status_t efi_entry(efi_handle_t handle, efi_system_table_t *sys_table_arg)
223233
dram_base, image);
224234
if (status != EFI_SUCCESS) {
225235
efi_err("Failed to relocate kernel\n");
226-
goto fail_free_cmdline;
236+
goto fail_free_screeninfo;
227237
}
228238

229239
efi_retrieve_tpm2_eventlog();
@@ -326,8 +336,9 @@ efi_status_t efi_entry(efi_handle_t handle, efi_system_table_t *sys_table_arg)
326336
fail_free_image:
327337
efi_free(image_size, image_addr);
328338
efi_free(reserve_size, reserve_addr);
329-
fail_free_cmdline:
339+
fail_free_screeninfo:
330340
free_screen_info(si);
341+
fail_free_cmdline:
331342
efi_free(cmdline_size, (unsigned long)cmdline_ptr);
332343
fail:
333344
return status;

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,12 +739,20 @@ unsigned long efi_main(efi_handle_t handle,
739739
}
740740

741741
#ifdef CONFIG_CMDLINE_BOOL
742-
efi_parse_options(CONFIG_CMDLINE);
742+
status = efi_parse_options(CONFIG_CMDLINE);
743+
if (status != EFI_SUCCESS) {
744+
efi_err("Failed to parse options\n");
745+
goto fail;
746+
}
743747
#endif
744748
if (!IS_ENABLED(CONFIG_CMDLINE_OVERRIDE)) {
745749
unsigned long cmdline_paddr = ((u64)hdr->cmd_line_ptr |
746750
((u64)boot_params->ext_cmd_line_ptr << 32));
747-
efi_parse_options((char *)cmdline_paddr);
751+
status = efi_parse_options((char *)cmdline_paddr);
752+
if (status != EFI_SUCCESS) {
753+
efi_err("Failed to parse options\n");
754+
goto fail;
755+
}
748756
}
749757

750758
/*

0 commit comments

Comments
 (0)