From: Heinrich Schuchardt Date: Mon, 15 Dec 2025 12:42:51 +0000 (+0100) Subject: efi_selftest: Enhance LoadImage test X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7ed2098fa9a5d0132c4f37baca8a6247a8ef5548;p=thirdparty%2Fu-boot.git efi_selftest: Enhance LoadImage test Check that only a file system installed on a handle for the device-path node immediately preceding the file path node is used for LoadImage(). LoadImage() ends up invoking efi_dp_find_obj(). This test helped to demonstrate an issue in a suggested patch to change that function. The test can be run with: setenv efi_selftest load image from file bootefi selftest Reviewed-by: Ilias Apalodimas Signed-off-by: Heinrich Schuchardt --- diff --git a/lib/efi_selftest/efi_selftest_loadimage.c b/lib/efi_selftest/efi_selftest_loadimage.c index 24548f1ae63..967eaa58c69 100644 --- a/lib/efi_selftest/efi_selftest_loadimage.c +++ b/lib/efi_selftest/efi_selftest_loadimage.c @@ -125,6 +125,44 @@ static struct { } }; +/* Incorrect file device path */ +static struct { + struct efi_device_path_vendor vendor; + struct efi_device_path_controller ctrl; + struct efi_device_path path; + u16 file[sizeof(FILE_NAME)]; + struct efi_device_path end; +} __packed dp_file2 = { + .vendor = { + .dp = { + .type = DEVICE_PATH_TYPE_HARDWARE_DEVICE, + .sub_type = DEVICE_PATH_SUB_TYPE_VENDOR, + .length = sizeof(struct efi_device_path_vendor), + }, + .guid = EFI_GUID(0x4f9a0ebf, 0xa179, 0x88a6, 0x25, 0x68, + 0x10, 0x72, 0xb1, 0x93, 0x51, 0x71), + }, + .ctrl = { + .dp = { + .type = DEVICE_PATH_TYPE_HARDWARE_DEVICE, + .sub_type = DEVICE_PATH_SUB_TYPE_CONTROLLER, + .length = sizeof(struct efi_device_path_controller), + }, + .controller_number = 1, + }, + .path = { + .type = DEVICE_PATH_TYPE_MEDIA_DEVICE, + .sub_type = DEVICE_PATH_SUB_TYPE_FILE_PATH, + .length = sizeof(struct efi_device_path) + sizeof(dp_file.file), + }, + .file = FILE_NAME, + .end = { + .type = DEVICE_PATH_TYPE_END, + .sub_type = DEVICE_PATH_SUB_TYPE_END, + .length = sizeof(struct efi_device_path), + } +}; + /* File system info */ static struct file_system_info priv_file_system_info = { { @@ -517,6 +555,13 @@ static int execute(void) return EFI_ST_FAILURE; } + ret = boottime->load_image(false, handle_image, &dp_file2.vendor.dp, + NULL, 0, &handle); + if (ret == EFI_SUCCESS) { + efi_st_error("Invalid file path accepted\n"); + return EFI_ST_FAILURE; + } + return EFI_ST_SUCCESS; }