From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1q1s5g-0006AB-5b for mharc-grub-devel@gnu.org; Wed, 24 May 2023 13:16:00 -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 1q1s5e-00069u-18 for grub-devel@gnu.org; Wed, 24 May 2023 13:15:58 -0400 Received: from dfw.source.kernel.org ([139.178.84.217]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q1s5X-0005v3-4d for grub-devel@gnu.org; Wed, 24 May 2023 13:15:57 -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 070F9638B6; Wed, 24 May 2023 17:15:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 932F0C433D2; Wed, 24 May 2023 17:15:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684948541; bh=2XlettglnxH9vxTNaIV/93YNwN2hFpXNr4HNUkyrDFo=; h=From:To:Cc:Subject:Date:From; b=eH8jQZvgUlogGdsPs3OsqF/EOG+MlQTIc6yqjezpWI31JxJtNFCLCuYVbupMJB0Qy hxrkOnMDw6MxtVGzGezZfSKh98/xuz85HHLKPHr9aXw2ABZnVEh2q+g7fpGMx6S9Oq 9Jkfrcn0NmcUyGO8oLUfR4R1fQmQuuxAqMrAz2WVUagF5MrMsn1fiCxPoJB9vsKVmE MjiQyUbJxGNtE6YWwz02F1fUBuc9oj7XvPQYoG7zyw4ErO59CRzAcBbO2ah9PXjlWk ZpN9BMGySHIbmeWYADl0Dfs/jB3f/5bx6o7YNfpUpxjLXMsfFKf3EBqCj746KsgFga qiQ0MXEYiO0Yg== From: Ard Biesheuvel To: grub-devel@gnu.org Cc: dkiper@net-space.pl, Ard Biesheuvel Subject: [PATCH] efi: Handle NULL return value when getting loaded image protocol Date: Wed, 24 May 2023 19:15:29 +0200 Message-Id: <20230524171529.974233-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=1546; i=ardb@kernel.org; h=from:subject; bh=2XlettglnxH9vxTNaIV/93YNwN2hFpXNr4HNUkyrDFo=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JISXPzXDO749yDJvKot+Vnw6a8eSRyvmSF5qJUeee+xyf3 Gbz0/dtRykLgxgHg6yYIovA7L/vdp6eKFXrPEsWZg4rE8gQBi5OAZjIsTWMDCusVJ7puuh25y9S L5YLrry2+9utJ8xJXIca+DcybmH0eMvwP61DYbWzBGOesJpvAtPEKSy3e/zfivgp600T3de3rIG TAwA= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=139.178.84.217; envelope-from=ardb@kernel.org; helo=dfw.source.kernel.org X-Spam_score_int: -70 X-Spam_score: -7.1 X-Spam_bar: ------- X-Spam_report: (-7.1 / 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_HI=-5, 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:15:58 -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 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c index 90ad1a7b82a76066..b434c56ae67d665e 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 = @@ -228,6 +233,7 @@ grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args) grub_dprintf ("linux", "starting image %p\n", image_handle); status = b->start_image (image_handle, 0, NULL); +unload: /* When successful, not reached */ b->unload_image (image_handle); grub_efi_free_pages ((grub_addr_t) loaded_image->load_options, -- 2.39.2