From: Ard Biesheuvel <ardb@kernel.org>
To: grub-devel@gnu.org
Cc: dkiper@net-space.pl, Ard Biesheuvel <ardb@kernel.org>
Subject: [PATCH v2] efi: Handle NULL return value when getting loaded image protocol
Date: Wed, 24 May 2023 19:29:09 +0200 [thread overview]
Message-ID: <20230524172909.995773-1-ardb@kernel.org> (raw)
The EFI spec mandates that the handle produced by the LoadImage boot
service has a LoadedImage protocol instance installed on it, but for
robustness, we should still deal with a NULL return value from the
helper routine that obtains this protocol pointer.
If this happens, don't try to start the image but unload it and return
an error.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
grub-core/loader/efi/linux.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c
index 90ad1a7b82a76066..8211f7892ad391f1 100644
--- a/grub-core/loader/efi/linux.c
+++ b/grub-core/loader/efi/linux.c
@@ -214,6 +214,11 @@ grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args)
/* Convert command line to UCS-2 */
loaded_image = grub_efi_get_loaded_image (image_handle);
+ if (loaded_image == NULL)
+ {
+ grub_error (GRUB_ERR_BAD_FIRMWARE, "missing loaded_image proto");
+ goto unload;
+ }
loaded_image->load_options_size = len =
(grub_strlen (args) + 1) * sizeof (grub_efi_char16_t);
loaded_image->load_options =
@@ -229,9 +234,11 @@ grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args)
status = b->start_image (image_handle, 0, NULL);
/* When successful, not reached */
- b->unload_image (image_handle);
+ grub_error (GRUB_ERR_BAD_OS, "start_image() returned %" PRIuGRUB_EFI_UINTN_T, status);
grub_efi_free_pages ((grub_addr_t) loaded_image->load_options,
GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size));
+unload:
+ b->unload_image (image_handle);
return grub_errno;
}
--
2.39.2
next reply other threads:[~2023-05-24 17:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-24 17:29 Ard Biesheuvel [this message]
2023-05-24 20:23 ` [PATCH v2] efi: Handle NULL return value when getting loaded image protocol Daniel Kiper
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230524172909.995773-1-ardb@kernel.org \
--to=ardb@kernel.org \
--cc=dkiper@net-space.pl \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.