]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
stub: NULL checks for DeviceHandle and FilePath
authorLukas <lu.schwager@gmail.com>
Sun, 8 Oct 2023 17:45:34 +0000 (19:45 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 16 Oct 2023 08:44:03 +0000 (10:44 +0200)
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
src/boot/efi/stub.c

index 2366dfd42b6b4e7337ad1eed0c1ee2ea229727fe..d38f0206cfde1f35188d744bb10ba1390050db9d 100644 (file)
@@ -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