Skip to content

Commit

Permalink
boot: bootflow_menu: fix crash for EFI BOOTMGR global bootmeth
Browse files Browse the repository at this point in the history
The global bootmeths don't set the dev in bootflow struct which means
the dev_get_parent(bflow->dev) triggers a NULL-pointer dereference and
crash U-Boot.

So before trying to handle a bootflow, check that the associated
bootmeth isn't global, otherwise skip it.

Suggested-by: Simon Glass <[email protected]>
Signed-off-by: Quentin Schulz <[email protected]>
Reviewed-by: Simon Glass <[email protected]>
  • Loading branch information
QSchulz authored and trini committed Jun 20, 2024
1 parent 8173166 commit 05b9665
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions boot/bootflow_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define LOG_CATEGORY UCLASS_BOOTSTD

#include <bootflow.h>
#include <bootmeth.h>
#include <bootstd.h>
#include <cli.h>
#include <dm.h>
Expand Down Expand Up @@ -76,13 +77,19 @@ int bootflow_menu_new(struct expo **expp)
last_bootdev = NULL;
for (ret = bootflow_first_glob(&bflow), i = 0; !ret && i < 36;
ret = bootflow_next_glob(&bflow), i++) {
struct bootmeth_uc_plat *ucp;
char str[2], *label, *key;
uint preview_id;
bool add_gap;

if (bflow->state != BOOTFLOWST_READY)
continue;

/* No media to show for BOOTMETHF_GLOBAL bootmeths */
ucp = dev_get_uclass_plat(bflow->method);
if (ucp->flags & BOOTMETHF_GLOBAL)
continue;

*str = i < 10 ? '0' + i : 'A' + i - 10;
str[1] = '\0';
key = strdup(str);
Expand Down
3 changes: 2 additions & 1 deletion include/bootflow.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ enum bootflow_flags_t {
*
* @bm_node: Points to siblings in the same bootdev
* @glob_node: Points to siblings in the global list (all bootdev)
* @dev: Bootdev device which produced this bootflow
* @dev: Bootdev device which produced this bootflow, NULL for flows created by
* BOOTMETHF_GLOBAL bootmeths
* @blk: Block device which contains this bootflow, NULL if this is a network
* device or sandbox 'host' device
* @part: Partition number (0 for whole device)
Expand Down

0 comments on commit 05b9665

Please sign in to comment.