]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: gracefully handle LoadFile() implementations that return EFI_SUCCESS with a...
authorLennart Poettering <lennart@amutable.com>
Fri, 17 Apr 2026 12:58:46 +0000 (14:58 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 22 May 2026 12:32:04 +0000 (13:32 +0100)
LoadFile() with a NULL buffer is supposed to return the file size
without acquiring the data and return EFI_BUFFER_TOO_SMALL.

However it appears some firmware returns EFI_SUCCESS in case the file is
empty, i.e. the file size returned is zero. And I guess that's even
fine.

Let's handle this gracefully hence.

(cherry picked from commit c40f254cca5e96b876b90e20ced69c33115940c3)

src/boot/boot.c

index 2cf828cf91b79dcf0d21a3403760e22f910d276e..c92a1de0ede903be00dc56ad4b6be7881c151832 100644 (file)
@@ -2718,7 +2718,12 @@ static EFI_STATUS expand_path(
                 if (IN_SET(err, EFI_NOT_FOUND, EFI_INVALID_PARAMETER))
                         continue; /* Skip over LoadFile() handles that after all don't consider themselves
                                    * appropriate for this kind of path */
-                if (err != EFI_BUFFER_TOO_SMALL) {
+                if (!IN_SET(err, EFI_SUCCESS, EFI_BUFFER_TOO_SMALL)) {
+                        /* NB: firmwares are supposed to return EFI_BUFFER_TOO_SMALL whenever we pass a NULL
+                         * buffer. But for compatibility with quirky firmwares let's be lenient for the
+                         * special case of a zero sized file: the firmware might return EFI_SUCCESS here and
+                         * initialize the size to zero, as a buffer is not actually necessary for that
+                         * case. */
                         log_warning_status(err, "Failed to get file via LoadFile() protocol, ignoring: %m");
                         continue;
                 }