From: Lukas Date: Sun, 8 Oct 2023 17:45:34 +0000 (+0200) Subject: stub: NULL checks for DeviceHandle and FilePath X-Git-Tag: v255-rc1~235 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c7fda707163f1779ce74cba3f79f5da0d63b10dc;p=thirdparty%2Fsystemd.git stub: NULL checks for DeviceHandle and FilePath UKIs may be loaded in a way, that there can not be a device handle to the filesystem, that contains the image, for example when using a bootloader to load the image from a partition with a file system that is not supported by the firmware. With the current systemd stub, this causes a failed assertion, because stub gets passed a NULL DeviceHandle and FilePath. Inserting two explicit checks enables proper boot even in this case. Fixes: #29331 --- diff --git a/src/boot/efi/stub.c b/src/boot/efi/stub.c index 2366dfd42b6..d38f0206cfd 100644 --- a/src/boot/efi/stub.c +++ b/src/boot/efi/stub.c @@ -520,8 +520,9 @@ static EFI_STATUS run(EFI_HANDLE image) { if (err != EFI_SUCCESS) return log_error_status(err, "Error getting a LoadedImageProtocol handle: %m"); - if (efivar_get_uint64_le(MAKE_GUID_PTR(LOADER), u"LoaderFeatures", &loader_features) != EFI_SUCCESS || - !FLAGS_SET(loader_features, EFI_LOADER_FEATURE_RANDOM_SEED)) { + if (loaded_image->DeviceHandle && /* Handle case, where bootloader doesn't support DeviceHandle. */ + (efivar_get_uint64_le(MAKE_GUID_PTR(LOADER), u"LoaderFeatures", &loader_features) != EFI_SUCCESS || + !FLAGS_SET(loader_features, EFI_LOADER_FEATURE_RANDOM_SEED))) { _cleanup_(file_closep) EFI_FILE *esp_dir = NULL; err = partition_open(MAKE_GUID_PTR(ESP), loaded_image->DeviceHandle, NULL, &esp_dir); @@ -556,19 +557,22 @@ static EFI_STATUS run(EFI_HANDLE image) { if (err != EFI_SUCCESS) log_error_status(err, "Error loading global addons, ignoring: %m"); - _cleanup_free_ char16_t *dropin_dir = get_extra_dir(loaded_image->FilePath); - err = load_addons( - image, - loaded_image, - dropin_dir, - uname, - &cmdline_addons_uki, - &dt_bases_addons_uki, - &dt_sizes_addons_uki, - &dt_filenames_addons_uki, - &n_dts_addons_uki); - if (err != EFI_SUCCESS) - log_error_status(err, "Error loading UKI-specific addons, ignoring: %m"); + /* Some bootloaders always pass NULL in FilePath, so we need to check for it here. */ + if (loaded_image->FilePath) { + _cleanup_free_ char16_t *dropin_dir = get_extra_dir(loaded_image->FilePath); + err = load_addons( + image, + loaded_image, + dropin_dir, + uname, + &cmdline_addons_uki, + &dt_bases_addons_uki, + &dt_sizes_addons_uki, + &dt_filenames_addons_uki, + &n_dts_addons_uki); + if (err != EFI_SUCCESS) + log_error_status(err, "Error loading UKI-specific addons, ignoring: %m"); + } /* Measure all "payload" of this PE image into a separate PCR (i.e. where nothing else is written * into so far), so that we have one PCR that we can nicely write policies against because it