From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1q1sIg-00033f-G2 for mharc-grub-devel@gnu.org; Wed, 24 May 2023 13:29:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q1sIe-00033S-U4 for grub-devel@gnu.org; Wed, 24 May 2023 13:29:25 -0400 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q1sIc-0008Fm-JJ for grub-devel@gnu.org; Wed, 24 May 2023 13:29:24 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EECE26358B; Wed, 24 May 2023 17:29:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 79807C4339B; Wed, 24 May 2023 17:29:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684949360; bh=yoLkQZIt4ESmq8B5N0fnc+ZZ5ZqmWPPkE/EcuHenNQg=; h=From:To:Cc:Subject:Date:From; b=sFWwqbpFg1qcv9ThLjaP7nfbP4URd9J4evB4Ao0dfGqvcCKrBXj3WilrCTfOSwxSe ouXfx90ZlYIeubSExo63RBt+t5rXYjp5Pb9+i7ER1YsfZ9ekq/QyQm16uA42l9Xo/U LJC0rxzs4mrpBZlLcwXBB3O4lVa442uJiQ6K7X6G7m1j6KoQbgya6cJliB/dmuIhKk 7IHtAgZIMCq6/zmf5ZORHGC1HodA0yp9ldDHaJOfI4bKfhPeo03teEUoARBmFzLH/o zo6sHtUFgqHSVGRTCjxVbWqisMSGuwPzBcwxPx6AuwJEWPgSy4YhiFH98AuILg7r8K vQeUJzlaLKm2g== From: Ard Biesheuvel To: grub-devel@gnu.org Cc: dkiper@net-space.pl, Ard Biesheuvel Subject: [PATCH v2] efi: Handle NULL return value when getting loaded image protocol Date: Wed, 24 May 2023 19:29:09 +0200 Message-Id: <20230524172909.995773-1-ardb@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1728; i=ardb@kernel.org; h=from:subject; bh=yoLkQZIt4ESmq8B5N0fnc+ZZ5ZqmWPPkE/EcuHenNQg=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JISXPM2WeVt+H9/OebLkV67IlcsWai49nmR5OjUmNfnbuZ ZloT4dmRykLgxgHg6yYIovA7L/vdp6eKFXrPEsWZg4rE8gQBi5OAZgI+zGG/1mPv5/R8J/iHMVZ 3LFmgs3yy1seTJn1Xv741SlTPsvfX9XM8L9UXn5O74LUJPYnsQc2X1wcqiqXdFfZ7t6Jzr0nDQ6 xfuYAAA== X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2604:1380:4641:c500::1; envelope-from=ardb@kernel.org; helo=dfw.source.kernel.org X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 May 2023 17:29:25 -0000 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 --- 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