From patchwork Tue Mar 21 16:18:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 665714 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7AD2BC6FD1D for ; Tue, 21 Mar 2023 16:18:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229679AbjCUQSg (ORCPT ); Tue, 21 Mar 2023 12:18:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229639AbjCUQSg (ORCPT ); Tue, 21 Mar 2023 12:18:36 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A4BD2CC41 for ; Tue, 21 Mar 2023 09:18:14 -0700 (PDT) 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 sin.source.kernel.org (Postfix) with ESMTPS id BC02CCE19FC for ; Tue, 21 Mar 2023 16:18:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98E99C433EF; Tue, 21 Mar 2023 16:18:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679415489; bh=5NkzRSSf2ER5qjOYkcH3vxSdxpVrfZwhlZzLzqMydXs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nsX5VC/sYFX9Vg3kxRtHB2mWvBi/btMTOVuQaDTNfdQZnHyZrLOCIXRKvyCYTvs89 bkkgmYv3e7N2QvIQL3ImiZhIjrBAR/l/LmEPXjM4ToaChwvdQq568CUg8LKl++5DyA UbZdFaH6oXzxHCWju24ifG5dhTZTE3QfaPfbVfzVzULLrAunSyQJu/E7kTmjjkkrkf ooyEKV7eZ/9zHGWDbRIjyytA3oxCS1/g6OgTdcZIF/HkAeGFSDQ0njD5wYkObqc93+ qOIso/fl07HcKoUmoIYDz8kGGrRMgMQlvKtHLTN26ESlmcovNLPz912Xi0qZrc6NwK Wzv1KxGs8sw4g== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: Ard Biesheuvel , Michael Brown , Ilias Apalodimas Subject: [PATCH v2 1/3] efi/libstub: Use const qualified device path protocol pointers Date: Tue, 21 Mar 2023 17:18:01 +0100 Message-Id: <20230321161803.3289140-2-ardb@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230321161803.3289140-1-ardb@kernel.org> References: <20230321161803.3289140-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3231; i=ardb@kernel.org; h=from:subject; bh=5NkzRSSf2ER5qjOYkcH3vxSdxpVrfZwhlZzLzqMydXs=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIUXyxo6LfbFrEpxKqp26F6l+iXoeoXIsSl1nXvqZXy+f2 Ds/DFjWUcrCIMbBICumyCIw+++7nacnStU6z5KFmcPKBDKEgYtTACYicJnhf+4cBx0B9cQGuTNb Z3iofPkdVTHpwZ6D3Y5VkbO97KQPdDEynFVV/fh1tovVXP09Ey9sCBA48/7Ha4/Fl+cEhy77Xli 6iwkA X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org The EFI APIs that deal with device path protocol instances never modify them, but given that these APIs do not use const qualified pointers at all, but instead uses IN and OUT modifiers that are #define'd to empty tokens, we cannot currently pass a device path protocol pointer that refers to a read-only object. So add the const qualification where appropriate, and drop a cast that is no longer necessary. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/efi-stub-helper.c | 4 ++-- drivers/firmware/efi/libstub/efistub.h | 4 ++-- drivers/firmware/efi/libstub/file.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c index 1e0203d74691ffcc..ff60e3a78337ce5c 100644 --- a/drivers/firmware/efi/libstub/efi-stub-helper.c +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c @@ -499,12 +499,12 @@ efi_status_t efi_load_initrd_dev_path(struct linux_efi_initrd *initrd, unsigned long max) { efi_guid_t lf2_proto_guid = EFI_LOAD_FILE2_PROTOCOL_GUID; - efi_device_path_protocol_t *dp; + const efi_device_path_protocol_t *dp; efi_load_file2_protocol_t *lf2; efi_handle_t handle; efi_status_t status; - dp = (efi_device_path_protocol_t *)&initrd_dev_path; + dp = &initrd_dev_path.vendor.header; status = efi_bs_call(locate_device_path, &lf2_proto_guid, &dp, &handle); if (status != EFI_SUCCESS) return status; diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h index 6bd3bb86d9679a1c..96a04ee05cdbb8bf 100644 --- a/drivers/firmware/efi/libstub/efistub.h +++ b/drivers/firmware/efi/libstub/efistub.h @@ -285,7 +285,7 @@ union efi_boot_services { void *, unsigned long *, efi_handle_t *); efi_status_t (__efiapi *locate_device_path)(efi_guid_t *, - efi_device_path_protocol_t **, + const efi_device_path_protocol_t **, efi_handle_t *); efi_status_t (__efiapi *install_configuration_table)(efi_guid_t *, void *); @@ -894,7 +894,7 @@ typedef union efi_load_file_protocol efi_load_file2_protocol_t; union efi_load_file_protocol { struct { efi_status_t (__efiapi *load_file)(efi_load_file_protocol_t *, - efi_device_path_protocol_t *, + const efi_device_path_protocol_t *, bool, unsigned long *, void *); }; struct { diff --git a/drivers/firmware/efi/libstub/file.c b/drivers/firmware/efi/libstub/file.c index d6a025df07dcf9ef..207dc578db910336 100644 --- a/drivers/firmware/efi/libstub/file.c +++ b/drivers/firmware/efi/libstub/file.c @@ -131,7 +131,7 @@ static efi_status_t efi_open_device_path(efi_file_protocol_t **volume, efi_guid_t text_to_dp_guid = EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL_GUID; static efi_device_path_from_text_protocol_t *text_to_dp = NULL; efi_guid_t fs_proto = EFI_FILE_SYSTEM_GUID; - efi_device_path_protocol_t *initrd_dp; + const efi_device_path_protocol_t *initrd_dp; efi_simple_file_system_protocol_t *io; struct efi_file_path_dev_path *fpath; efi_handle_t handle; From patchwork Tue Mar 21 16:18:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 665715 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08083C74A5B for ; Tue, 21 Mar 2023 16:18:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229496AbjCUQS2 (ORCPT ); Tue, 21 Mar 2023 12:18:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229639AbjCUQS1 (ORCPT ); Tue, 21 Mar 2023 12:18:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6D732127 for ; Tue, 21 Mar 2023 09:18:13 -0700 (PDT) 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 8D4EE61D1D for ; Tue, 21 Mar 2023 16:18:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0145FC4339C; Tue, 21 Mar 2023 16:18:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679415490; bh=kcQcpLl/g+mSgfiafsN4yuibM6kuFy26F9+w/ioXlX4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dnKslAjblcqIzf/QLudfNM4rRrbsjwogir+qs0qdbD88WiMEJT+cAUP4L4NKk2hCC 4G1FdUGD/YIetirJEToQf15SVnM7m8zbiQOxTFnzlziCXwf5+lLa2segkDNARfgeQ7 N8+Bcrz4Hc3WJAHr9w0xYrk74dfbAQCGDl8DM6hMgOi/8BJIB8lE9Z98Mihn8fXFLb 5wHvLICaICJjfBePi4IIYda+hWZP2tJVPsODho6l1lHqqXHbfpwPFMT5B3Ofr1cjld PAN57wj475drYkgm8uK4HXVyhzXdtSI+Na98rC3vu9MNFPtS53Fvfzc4I1VzHBUPQl OPQXsCSJa3Gbw== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: Ard Biesheuvel , Michael Brown , Ilias Apalodimas Subject: [PATCH v2 2/3] efi/libstub: Pass loaded image EFI handle to efi_load_initrd() Date: Tue, 21 Mar 2023 17:18:02 +0100 Message-Id: <20230321161803.3289140-3-ardb@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230321161803.3289140-1-ardb@kernel.org> References: <20230321161803.3289140-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3364; i=ardb@kernel.org; h=from:subject; bh=kcQcpLl/g+mSgfiafsN4yuibM6kuFy26F9+w/ioXlX4=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIUXyxk4RuVq5+7Hn9rwIiG0/UpmSuur+6mvOqpasV1tqz eSFdll3lLIwiHEwyIopsgjM/vtu5+mJUrXOs2Rh5rAygQxh4OIUgInELWJkeFBp7rOqUfMGX8oB ySmJRcxZEdIhmez+X6VKD6/ca/65iOGfpmDP1xXvFFbHG5z798XVwJrLbUd3jPCSrhtH+6LkK8v 5AA== X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org In preparation for allowing loaders to pass the initrd loadfile2 protocol implementation via the loaded image handle instead of a global singleton device path, pass the loaded image EFI handle down to the code that loads the initrd. Tested-by: Ilias Apalodimas Reviewed-by: Ilias Apalodimas Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/efi-stub-helper.c | 3 ++- drivers/firmware/efi/libstub/efi-stub.c | 4 ++-- drivers/firmware/efi/libstub/efistub.h | 3 ++- drivers/firmware/efi/libstub/x86-stub.c | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c index ff60e3a78337ce5c..d1026c6a544058b4 100644 --- a/drivers/firmware/efi/libstub/efi-stub-helper.c +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c @@ -554,7 +554,8 @@ efi_status_t efi_load_initrd_cmdline(efi_loaded_image_t *image, * * Return: status code */ -efi_status_t efi_load_initrd(efi_loaded_image_t *image, +efi_status_t efi_load_initrd(efi_handle_t handle, + efi_loaded_image_t *image, unsigned long soft_limit, unsigned long hard_limit, const struct linux_efi_initrd **out) diff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi/libstub/efi-stub.c index 2955c1ac6a36ee00..a5eb773a574143cf 100644 --- a/drivers/firmware/efi/libstub/efi-stub.c +++ b/drivers/firmware/efi/libstub/efi-stub.c @@ -177,8 +177,8 @@ efi_status_t efi_stub_common(efi_handle_t handle, /* Ask the firmware to clear memory on unclean shutdown */ efi_enable_reset_attack_mitigation(); - efi_load_initrd(image, ULONG_MAX, efi_get_max_initrd_addr(image_addr), - NULL); + efi_load_initrd(handle, image, ULONG_MAX, + efi_get_max_initrd_addr(image_addr), NULL); efi_random_get_seed(); diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h index 96a04ee05cdbb8bf..d772f2e33af7c270 100644 --- a/drivers/firmware/efi/libstub/efistub.h +++ b/drivers/firmware/efi/libstub/efistub.h @@ -1019,7 +1019,8 @@ static inline efi_status_t efi_load_dtb(efi_loaded_image_t *image, ULONG_MAX, ULONG_MAX, load_addr, load_size); } -efi_status_t efi_load_initrd(efi_loaded_image_t *image, +efi_status_t efi_load_initrd(efi_handle_t handle, + efi_loaded_image_t *image, unsigned long soft_limit, unsigned long hard_limit, const struct linux_efi_initrd **out); diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c index a0bfd31358ba97b1..e79f6977b41c15c2 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -867,8 +867,8 @@ asmlinkage unsigned long efi_main(efi_handle_t handle, * arguments will be processed only if image is not NULL, which will be * the case only if we were loaded via the PE entry point. */ - status = efi_load_initrd(image, hdr->initrd_addr_max, ULONG_MAX, - &initrd); + status = efi_load_initrd(handle, image, hdr->initrd_addr_max, + ULONG_MAX, &initrd); if (status != EFI_SUCCESS) goto fail; if (initrd && initrd->size > 0) { From patchwork Tue Mar 21 16:18:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 665968 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2EF4C74A5B for ; Tue, 21 Mar 2023 16:18:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229705AbjCUQSe (ORCPT ); Tue, 21 Mar 2023 12:18:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229700AbjCUQSe (ORCPT ); Tue, 21 Mar 2023 12:18:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D6A94EE7 for ; Tue, 21 Mar 2023 09:18:14 -0700 (PDT) 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 DAB4861D1E for ; Tue, 21 Mar 2023 16:18:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C326C4339B; Tue, 21 Mar 2023 16:18:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679415492; bh=dbtmv3DkDXA5APX5F+bxL0IQv0w/YWAqvuqPBppE7xY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WpjDV6Oa/Myw0nTLXggApJSUfMA9TmYOGUvIuQ4Tgta8H8FPakpEv4kaJPl/1VY2Y evDW5cT9vmnQie0KgMhzVNqyoy4DrTI2vUFIogsqx2xdJsHg/q1MBUoFbw3xx8MIhf H+aBhabW0wQSg4Dz2zbmVO7uq02lWljljWg/qmLk/ohu/MFFVjPSoVUnzvKYjdSTxX +FII3/Um3K8BVdZJd7BZODe0tcuM/BqgeGH6PlK4Zlw40R6B/vWFbyloGXvcDom5DH DYoh7pZV/zLnYQfFmfOLDhO89jCGTOYICnfy968tf9dWQ2kVDlsvwNHUQVUF0NiW6T nAHrMksr6J8Pw== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: Ard Biesheuvel , Michael Brown , Ilias Apalodimas Subject: [PATCH v2 3/3] efi/libstub: Look for initrd LoadFile2 protocol on image handle Date: Tue, 21 Mar 2023 17:18:03 +0100 Message-Id: <20230321161803.3289140-4-ardb@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230321161803.3289140-1-ardb@kernel.org> References: <20230321161803.3289140-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=6729; i=ardb@kernel.org; h=from:subject; bh=dbtmv3DkDXA5APX5F+bxL0IQv0w/YWAqvuqPBppE7xY=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIUXyxu6rslbLewQv1L/QM509ifuN3oKSX7W8VmqqWz7f0 LtwYHlURykLgxgHg6yYIovA7L/vdp6eKFXrPEsWZg4rE8gQBi5OAZjI9giGv+JXN8jWXFub1hGo m1z/iWWiOx/Po32nr6vHfYyU+jnnywyG/66hWdOdynkrlm+3y7Dp/pHHcfSZhfmDqD2Vgs8uZRV HsQEA X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org The use of a global singleton device path for describing the initrd to be loaded by the kernel implies that only a single handle can exist that carries the initrd LoadFile2 protocol implementation. This avoids the need on the part of the EFI stub to reason about which initrd is the preferred one when several are being provided - we already have initrd loading via the setup header on x86 and via DT on other architectures, in addition to the initrd= command line option, and so having a single loader provided initrd that supersedes all of them was deemed preferable over having multiple sources. However, this means that intermediate loader stages cannot simply install the LoadFile2 initrd device path, and will need to check for failures and deal with them. It also means that such stages will have to reason about whether or not the subsequent stage being loaded is the final one, or whether it may attempt to install the initrd device path itself. We can solve this by associating the initrd LoadFile2 protocol with the loaded image instead of with a global singleton device path. That way, each stage can associate any initrd it provides with the image that it is loading. Tested-by: Ilias Apalodimas Reviewed-by: Ilias Apalodimas Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/efi-stub-helper.c | 53 ++++++++++++-------- include/linux/efi.h | 1 + include/linux/pe.h | 2 +- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c index d1026c6a544058b4..7ca993fd0e331637 100644 --- a/drivers/firmware/efi/libstub/efi-stub-helper.c +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c @@ -482,37 +482,50 @@ static const struct { }; /** - * efi_load_initrd_dev_path() - load the initrd from the Linux initrd device path - * @initrd: pointer of struct to store the address where the initrd was loaded - * and the size of the loaded initrd - * @max: upper limit for the initrd memory allocation + * efi_load_initrd_lf2() - load the initrd either from the LoadFile2 initrd + * loading protocol installed on the loaded image + * handle, or from the Linux initrd device path + * @image_handle: EFI handle of the loaded image + * @initrd: pointer of struct to store the address where the initrd was + * loaded and the size of the loaded initrd + * @max: upper limit for the initrd memory allocation * * Return: - * * %EFI_SUCCESS if the initrd was loaded successfully, in which - * case @load_addr and @load_size are assigned accordingly - * * %EFI_NOT_FOUND if no LoadFile2 protocol exists on the initrd device path + * * %EFI_SUCCESS if the initrd was loaded successfully, in which case the base + * and size members of @initrd are assigned accordingly + * * %EFI_NOT_FOUND if no LoadFile2 protocol exists on the loaded image handle + * or on the initrd device path * * %EFI_OUT_OF_RESOURCES if memory allocation failed * * %EFI_LOAD_ERROR in all other cases */ static -efi_status_t efi_load_initrd_dev_path(struct linux_efi_initrd *initrd, - unsigned long max) +efi_status_t efi_load_initrd_lf2(efi_handle_t image_handle, + struct linux_efi_initrd *initrd, + unsigned long max) { efi_guid_t lf2_proto_guid = EFI_LOAD_FILE2_PROTOCOL_GUID; - const efi_device_path_protocol_t *dp; + efi_guid_t initrd_lf2_proto_guid = LINUX_EFI_INITRD_LF2_PROTOCOL_GUID; + const efi_device_path_protocol_t *dp = &initrd_dev_path.end; efi_load_file2_protocol_t *lf2; efi_handle_t handle; efi_status_t status; - dp = &initrd_dev_path.vendor.header; - status = efi_bs_call(locate_device_path, &lf2_proto_guid, &dp, &handle); - if (status != EFI_SUCCESS) - return status; - - status = efi_bs_call(handle_protocol, handle, &lf2_proto_guid, + /* first look for a initrd loading protocol specific to this image */ + status = efi_bs_call(handle_protocol, image_handle, &initrd_lf2_proto_guid, (void **)&lf2); - if (status != EFI_SUCCESS) - return status; + if (status != EFI_SUCCESS) { + /* look for the global singleton initrd loading protocol */ + dp = &initrd_dev_path.vendor.header; + status = efi_bs_call(locate_device_path, &lf2_proto_guid, &dp, + &handle); + if (status != EFI_SUCCESS) + return status; + + status = efi_bs_call(handle_protocol, handle, &lf2_proto_guid, + (void **)&lf2); + if (status != EFI_SUCCESS) + return status; + } initrd->size = 0; status = efi_call_proto(lf2, load_file, dp, false, &initrd->size, NULL); @@ -567,9 +580,9 @@ efi_status_t efi_load_initrd(efi_handle_t handle, if (!IS_ENABLED(CONFIG_BLK_DEV_INITRD) || efi_noinitrd) return EFI_SUCCESS; - status = efi_load_initrd_dev_path(&initrd, hard_limit); + status = efi_load_initrd_lf2(handle, &initrd, hard_limit); if (status == EFI_SUCCESS) { - efi_info("Loaded initrd from LINUX_EFI_INITRD_MEDIA_GUID device path\n"); + efi_info("Loaded initrd using LoadFile2 protocol\n"); if (initrd.size > 0 && efi_measure_tagged_event(initrd.base, initrd.size, EFISTUB_EVT_INITRD) == EFI_SUCCESS) diff --git a/include/linux/efi.h b/include/linux/efi.h index 04a733f0ba956211..08a1518de0fb4921 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -417,6 +417,7 @@ void efi_native_runtime_setup(void); #define LINUX_EFI_MOK_VARIABLE_TABLE_GUID EFI_GUID(0xc451ed2b, 0x9694, 0x45d3, 0xba, 0xba, 0xed, 0x9f, 0x89, 0x88, 0xa3, 0x89) #define LINUX_EFI_COCO_SECRET_AREA_GUID EFI_GUID(0xadf956ad, 0xe98c, 0x484c, 0xae, 0x11, 0xb5, 0x1c, 0x7d, 0x33, 0x64, 0x47) #define LINUX_EFI_BOOT_MEMMAP_GUID EFI_GUID(0x800f683f, 0xd08b, 0x423a, 0xa2, 0x93, 0x96, 0x5c, 0x3c, 0x6f, 0xe2, 0xb4) +#define LINUX_EFI_INITRD_LF2_PROTOCOL_GUID EFI_GUID(0xf9e3378e, 0xb3b1, 0x423a, 0xbd, 0x9a, 0x2d, 0x08, 0x60, 0x28, 0x7f, 0x72) #define RISCV_EFI_BOOT_PROTOCOL_GUID EFI_GUID(0xccd15fec, 0x6f73, 0x4eec, 0x83, 0x95, 0x3e, 0x69, 0xe4, 0xb9, 0x40, 0xbf) diff --git a/include/linux/pe.h b/include/linux/pe.h index 6ffabf1e6d039e67..934e3a15ea7ddc07 100644 --- a/include/linux/pe.h +++ b/include/linux/pe.h @@ -29,7 +29,7 @@ * handover_offset and xloadflags fields in the bootparams structure. */ #define LINUX_EFISTUB_MAJOR_VERSION 0x1 -#define LINUX_EFISTUB_MINOR_VERSION 0x1 +#define LINUX_EFISTUB_MINOR_VERSION 0x2 /* * LINUX_PE_MAGIC appears at offset 0x38 into the MS-DOS header of EFI bootable