bootmeth: efi_mgr: Report EFI boot manager failures to bootflow
cover bootmeth: efi_mgr: Report EFI boot manager failures to bootflow
When the EFI boot manager fails, efi_mgr_boot() assigns the status returned by efi_bootmgr_run() to a local variable and then returns 0. A zero return from a bootmeth's boot() method means "should not get here", so bootflow_boot() reports -EFAULT for every boot manager failure and the real cause (no boot option loadable, load error, ...) is lost. The unused assignment also trips -Wunused-but-set-variable on newer compilers.
Patch 1 maps the EFI status to an errno instead: EFI_NOT_FOUND (no BootOrder) becomes -ENOENT and any other failure -EIO, so 'bootflow boot' now prints an error that reflects what actually happened.
Patch 2 adds a bootstd test for the error path, which was previously unreachable from any test: it binds the efi_mgr bootmeth, points BootOrder at a load option that does not exist and checks that booting the bootflow returns -EIO rather than -EFAULT. Running the real boot manager initialises the EFI subsystem in the sandbox process, which would leak into later tests, so the test is also added to the restart list in test_ut.py like the other session-changing tests.
Tested on sandbox: the new test fails with -EFAULT before patch 1 and passes after it, and the full bootstd suite passes at each commit.
Aristo Chen (2):
bootmeth: efi_mgr: Do not discard the EFI boot manager error
test: boot: Check that efi_mgr boot failures are reported
boot/bootmeth_efi_mgr.c | 5 ++++- test/boot/bootflow.c | 35 +++++++++++++++++++++++++++++++++++ test/py/tests/test_ut.py | 3 ++- 3 files changed, 41 insertions(+), 2 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/2 bootmeth: efi_mgr: Do not discard the EFI boot manager error
efi_mgr_boot() assigns the status returned by efi_bootmgr_run() to a local variable and then returns 0. A zero return from a bootmeth's boot() method means "should not get here", so bootflow_boot() reports -EFAULT for every boot manager failure and the real cause (no boot option loadable, load error, ...) is lost. The unused assignment also trips -Wunused-but-set-variable on newer compilers.
Map the EFI status to an errno instead: EFI_NOT_FOUND (no BootOrder) becomes -ENOENT and any other failure -EIO.
--- boot/bootmeth_efi_mgr.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
boot/bootmeth_efi_mgr.c +4 -1
@@ -84,10 +84,13 @@ static int efi_mgr_read_file(struct udevice *dev, struct bootflow *bflow,static int efi_mgr_boot (struct udevice *dev,struct bootflow *bflow) { -int ret; +efi_status_t ret;/* Booting is handled by the 'bootefi bootmgr' command */ ret =efi_bootmgr_run (EFI_FDT_USE_INTERNAL ); +if (ret !=EFI_SUCCESS ) +return log_msg_ret ("mgr" , + ret ==EFI_NOT_FOUND ? -ENOENT : -EIO );return 0 ; }
Signature · 1 line
2.43.0
PATCH 2/2 test: boot: Check that efi_mgr boot failures are reported
In reply to Aristo Chen via U-BootAdd a bootstd test for the error path of the efi_mgr bootmeth: point BootOrder at a load option that does not exist and check that booting the bootflow returns -EIO rather than the generic -EFAULT that bootflow_boot() reports when a boot() method returns zero.
Running the real boot manager initialises the EFI subsystem in the sandbox process, which would leak into later tests, so restart U-Boot after this test in test_ut.py as is already done for other session-changing tests.
--- test/boot/bootflow.c | 35 +++++++++++++++++++++++++++++++++++ test/py/tests/test_ut.py | 3 ++- 2 files changed, 37 insertions(+), 1 deletion(-)
test/boot/bootflow.c +35 -0
@@ -470,6 +470,41 @@ static int bootflow_system(struct unit_test_state *uts) }BOOTSTD_TEST (bootflow_system,UTF_DM |UTF_SCAN_PDATA |UTF_SCAN_FDT |UTF_CONSOLE ); + +/* Check that a failed 'efi_mgr' boot reports the boot manager's error */ +static int bootflow_efi_mgr_err (struct unit_test_state *uts) +{ +struct udevice *bootstd, *dev; +struct bootflow *bflow; +int ret; + +if (!IS_ENABLED (CONFIG_EFI_BOOTMGR ) || !IS_ENABLED (CONFIG_CMD_EFIDEBUG )) +return -EAGAIN ; +ut_assertok (uclass_first_device_err (UCLASS_BOOTSTD , &bootstd)); +ut_assertok (device_bind (bootstd,DM_DRIVER_GET (bootmeth_3efi_mgr), +"efi_mgr" ,0 ,ofnode_null (), &dev)); +ut_assertok (device_probe (dev)); +sandbox_set_fake_efi_mgr_dev (dev, true); + +bootstd_clear_glob (); +ut_assertok (run_command ("bootflow scan -H" ,0 )); + +/* Point BootOrder at a load option that does not exist */ +ut_assertok (run_command ("efidebug boot order 00ff" ,0 )); + +for (ret =bootflow_first_glob (&bflow); !ret; + ret =bootflow_next_glob (&bflow)) { +if (!strcmp ("efi_mgr" , bflow->method->name)) +break ; + } +ut_assertok (ret); + +/* The boot manager cannot load anything; its error must not be lost */ +ut_asserteq (-EIO ,bootflow_boot (bflow)); + +return 0 ; +} +BOOTSTD_TEST (bootflow_efi_mgr_err,UTF_DM |UTF_SCAN_PDATA |UTF_SCAN_FDT );#endif /* Check disabling a bootmethod if it requests it */
test/py/tests/test_ut.py +2 -1
@@ -643,7 +643,8 @@ def ut_ubman_fixture(ubman, ut_subtest): yield ubman - if ut_subtest in ("bootstd bootflow_cmd_boot", "bootstd bootflow_scan_boot"): + if ut_subtest in ("bootstd bootflow_cmd_boot", "bootstd bootflow_scan_boot", + "bootstd bootflow_efi_mgr_err"): ubman.restart_uboot()
Signature · 1 line
2.43.0
Re: [PATCH v1 2/2] test: boot: Check that efi_mgr boot failures are reported
Quoted 35 lines · Aristo Chen via U-Boot
Add a bootstd test for the error path of the
efi_mgrbootmeth: point BootOrder at a load option that does not exist and check that booting the bootflow returns-EIOrather than the generic-EFAULTthatbootflow_boot()reports when aboot()method returns zero.Running the real boot manager initialises the EFI subsystem in the sandbox process, which would leak into later tests, so restart U-Boot after this test in
test_ut.pyas is already done for other session-changing tests.Signed-off-by Aristo Chen <[email protected]>--- test/boot/bootflow.c | 35 +++++++++++++++++++++++++++++++++++ test/py/tests/test_ut.py | 3 ++- 2 files changed, 37 insertions(+), 1 deletion(-)test/boot/bootflow.c +11
-0@@ -470,6 +470,41 @@ static int bootflow_system(struct unit_test_state *uts) }BOOTSTD_TEST (bootflow_system,UTF_DM |UTF_SCAN_PDATA |UTF_SCAN_FDT |UTF_CONSOLE ); + +/* Check that a failed 'efi_mgr' boot reports the boot manager's error */ +static int bootflow_efi_mgr_err (struct unit_test_state *uts) +{ +struct udevice *bootstd, *dev; +struct bootflow *bflow; +int ret; + +if (!IS_ENABLED (CONFIG_EFI_BOOTMGR ) || !IS_ENABLED (CONFIG_CMD_EFIDEBUG )) +return -EAGAIN ; +ut_assertok (uclass_first_device_err (UCLASS_BOOTSTD , &bootstd));
test/boot/bootflow.c static int bootflow_system(struct unit_test_state *uts) · line 493
Quoted 10 lines
test/boot/bootflow.c +10
-0+ut_assertok (device_bind (bootstd,DM_DRIVER_GET (bootmeth_3efi_mgr), +"efi_mgr" ,0 ,ofnode_null (), &dev)); +ut_assertok (device_probe (dev)); +sandbox_set_fake_efi_mgr_dev (dev, true); + +bootstd_clear_glob (); +ut_assertok (run_command ("bootflow scan -H" ,0 )); + +/* Point BootOrder at a load option that does not exist */ +ut_assertok (run_command ("efidebug boot order 00ff" ,0 ));
It should not be possible to add non-existent boot-options to BootOrder. We should fix this in the efidebug command.
Please, do not rely on this buggy behavior.
Best regards
Heinrich
Quoted 31 lines
test/boot/bootflow.c +14
-0+ +for (ret =bootflow_first_glob (&bflow); !ret; + ret =bootflow_next_glob (&bflow)) { +if (!strcmp ("efi_mgr" , bflow->method->name)) +break ; + } +ut_assertok (ret); + +/* The boot manager cannot load anything; its error must not be lost */ +ut_asserteq (-EIO ,bootflow_boot (bflow)); + + return 0; +} +BOOTSTD_TEST (bootflow_efi_mgr_err,UTF_DM |UTF_SCAN_PDATA |UTF_SCAN_FDT );#endif /* Check disabling a bootmethod if it requests it */ test/py/tests/test_ut.py +2
-1@@ -643,7 +643,8 @@ def ut_ubman_fixture(ubman, ut_subtest): yield ubman - if ut_subtest in ("bootstd bootflow_cmd_boot", "bootstd bootflow_scan_boot"): + if ut_subtest in ("bootstd bootflow_cmd_boot", "bootstd bootflow_scan_boot", + "bootstd bootflow_efi_mgr_err"): ubman.restart_uboot()
v2 cover bootmeth: efi_mgr: Report EFI boot manager failures to bootflow
In reply to Aristo Chen via U-BootWhen the EFI boot manager fails, efi_mgr_boot() assigns the status returned by efi_bootmgr_run() to a local variable and then returns 0. A zero return from a bootmeth's boot() method means "should not get here", so bootflow_boot() reports -EFAULT for every boot manager failure and the real cause (no boot option loadable, load error, ...) is lost. The unused assignment also trips -Wunused-but-set-variable on newer compilers.
Patch 1 maps the EFI status to an errno instead: EFI_NOT_FOUND (no BootOrder) becomes -ENOENT and any other failure -EIO, so 'bootflow boot' now prints an error that reflects what actually happened.
Patch 2 adds a bootstd test for the error path, which was previously unreachable from any test: it binds the efi_mgr bootmeth, removes the BootOrder variable so that the boot manager has nothing to load and checks that booting the bootflow returns -ENOENT rather than -EFAULT. Running the real boot manager initialises the EFI subsystem in the sandbox process, which would leak into later tests, so the test is also added to the restart list in test_ut.py like the other session-changing tests.
Tested on sandbox: the new test fails with -EFAULT before patch 1 and passes after it, and the full bootstd suite passes at each commit. The test also passes with Heinrich's "cmd/efidebug: do not allow invalid boot order" applied on top.
Changes in v2:
- Remove BootOrder in the test instead of pointing it at a non-existent load option, which relied on efidebug accepting invalid input (Heinrich)
Aristo Chen (2):
bootmeth: efi_mgr: Do not discard the EFI boot manager error
test: boot: Check that efi_mgr boot failures are reported
boot/bootmeth_efi_mgr.c | 5 ++++- test/boot/bootflow.c | 40 ++++++++++++++++++++++++++++++++++++++++ test/py/tests/test_ut.py | 3 ++- 3 files changed, 46 insertions(+), 2 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/2 bootmeth: efi_mgr: Do not discard the EFI boot manager error
efi_mgr_boot() assigns the status returned by efi_bootmgr_run() to a local variable and then returns 0. A zero return from a bootmeth's boot() method means "should not get here", so bootflow_boot() reports -EFAULT for every boot manager failure and the real cause (no boot option loadable, load error, ...) is lost. The unused assignment also trips -Wunused-but-set-variable on newer compilers.
Map the EFI status to an errno instead: EFI_NOT_FOUND (no BootOrder) becomes -ENOENT and any other failure -EIO.
---
(no changes since v1)
boot/bootmeth_efi_mgr.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
boot/bootmeth_efi_mgr.c +4 -1
@@ -84,10 +84,13 @@ static int efi_mgr_read_file(struct udevice *dev, struct bootflow *bflow,static int efi_mgr_boot (struct udevice *dev,struct bootflow *bflow) { -int ret; +efi_status_t ret;/* Booting is handled by the 'bootefi bootmgr' command */ ret =efi_bootmgr_run (EFI_FDT_USE_INTERNAL ); +if (ret !=EFI_SUCCESS ) +return log_msg_ret ("mgr" , + ret ==EFI_NOT_FOUND ? -ENOENT : -EIO );return 0 ; }
Signature · 1 line
2.43.0
PATCH v2 2/2 test: boot: Check that efi_mgr boot failures are reported
In reply to Aristo ChenAdd a bootstd test for the error path of the efi_mgr bootmeth: remove the BootOrder variable so that the boot manager has nothing to load and check that booting the bootflow returns -ENOENT rather than the generic -EFAULT that bootflow_boot() reports when a boot() method returns zero.
Running the real boot manager initialises the EFI subsystem in the sandbox process, which would leak into later tests, so restart U-Boot after this test in test_ut.py as is already done for other session-changing tests.
---
Changes in v2:
- Remove BootOrder instead of pointing it at a non-existent load option, which relied on efidebug accepting invalid input (Heinrich)
- Check for -ENOENT accordingly and drop the CMD_EFIDEBUG dependency
test/boot/bootflow.c | 40 ++++++++++++++++++++++++++++++++++++++++ test/py/tests/test_ut.py | 3 ++- 2 files changed, 42 insertions(+), 1 deletion(-)
test/boot/bootflow.c +40 -0
@@ -14,6 +14,7 @@#include <dm.h> #include <efi.h> #include <efi_loader.h> +#include <efi_variable.h> #include <env.h> #include <expo.h> #include <mapmem.h>
@@ -470,6 +471,45 @@ static int bootflow_system(struct unit_test_state *uts) }BOOTSTD_TEST (bootflow_system,UTF_DM |UTF_SCAN_PDATA |UTF_SCAN_FDT |UTF_CONSOLE ); + +/* Check that a failed 'efi_mgr' boot reports the boot manager's error */ +static int bootflow_efi_mgr_err (struct unit_test_state *uts) +{ +struct udevice *bootstd, *dev; +struct bootflow *bflow; +efi_status_t status; +int ret; + +if (!IS_ENABLED (CONFIG_EFI_BOOTMGR )) +return -EAGAIN ; +ut_assertok (uclass_first_device_err (UCLASS_BOOTSTD , &bootstd)); +ut_assertok (device_bind (bootstd,DM_DRIVER_GET (bootmeth_3efi_mgr), +"efi_mgr" ,0 ,ofnode_null (), &dev)); +ut_assertok (device_probe (dev)); +sandbox_set_fake_efi_mgr_dev (dev, true); + +bootstd_clear_glob (); +ut_assertok (run_command ("bootflow scan -H" ,0 )); + +/* Remove any BootOrder so that the boot manager has nothing to load */ +ut_asserteq (EFI_SUCCESS ,efi_init_obj_list ()); + status =efi_set_variable_int (u"BootOrder" , &efi_global_variable_guid, +0 ,0 ,NULL , false); +ut_assert (status ==EFI_SUCCESS || status ==EFI_NOT_FOUND ); + +for (ret =bootflow_first_glob (&bflow); !ret; + ret =bootflow_next_glob (&bflow)) { +if (!strcmp ("efi_mgr" , bflow->method->name)) +break ; + } +ut_assertok (ret); + +/* The boot manager finds no boot option; its error must not be lost */ +ut_asserteq (-ENOENT ,bootflow_boot (bflow)); + +return 0 ; +} +BOOTSTD_TEST (bootflow_efi_mgr_err,UTF_DM |UTF_SCAN_PDATA |UTF_SCAN_FDT );#endif /* Check disabling a bootmethod if it requests it */
test/py/tests/test_ut.py +2 -1
@@ -643,7 +643,8 @@ def ut_ubman_fixture(ubman, ut_subtest): yield ubman - if ut_subtest in ("bootstd bootflow_cmd_boot", "bootstd bootflow_scan_boot"): + if ut_subtest in ("bootstd bootflow_cmd_boot", "bootstd bootflow_scan_boot", + "bootstd bootflow_efi_mgr_err"): ubman.restart_uboot()
Signature · 1 line
2.43.0