From: Ard Biesheuvel <ardb+git@google.com>
To: linux-efi@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org,
Ard Biesheuvel <ardb@kernel.org>,
Jason Gunthorpe <jgg@nvidia.com>, Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Huacai Chen <chenhuacai@kernel.org>,
loongarch@lists.linux.dev, linux-riscv@lists.infradead.org
Subject: [PATCH v3 11/15] efi/libstub: Make efi_remap_image() return efi_status_t
Date: Mon, 16 Nov 2026 15:26:30 +0100 [thread overview]
Message-ID: <20261116142618.1687025-28-ardb+git@google.com> (raw)
In-Reply-To: <20261116142618.1687025-17-ardb+git@google.com>
From: Ard Biesheuvel <ardb@kernel.org>
efi_remap_image() uses the EFI Memory Attributes Protocol to remap code
and data regions with the appropriate permissions. This could fail for a
variety of regions, all of which are currently ignored.
So relay the failure status code if any occur when invoking the
protocol. Locating the protocol itself is allowed to fail, as remapping
the image is likely unnecessary in the first place if the protocol does
not exist.
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
drivers/firmware/efi/libstub/efi-stub-helper.c | 15 ++++++++++-----
drivers/firmware/efi/libstub/efistub.h | 4 ++--
2 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c
index 8e43eb3f418b..e50deec99686 100644
--- a/drivers/firmware/efi/libstub/efi-stub-helper.c
+++ b/drivers/firmware/efi/libstub/efi-stub-helper.c
@@ -697,9 +697,11 @@ efi_status_t efi_wait_for_key(unsigned long usec, efi_input_key_t *key)
* region of the loaded image read-only/executable, and the remainder
* read-write/non-executable. The code region is assumed to start at the base
* of the image, and will therefore cover the PE/COFF header as well.
+ *
+ * Return: EFI_SUCCESS on success, other EFI status codes on failure.
*/
-void efi_remap_image(unsigned long image_base, unsigned alloc_size,
- unsigned long code_size)
+efi_status_t efi_remap_image(unsigned long image_base, unsigned alloc_size,
+ unsigned long code_size)
{
static efi_guid_t guid = EFI_MEMORY_ATTRIBUTE_PROTOCOL_GUID;
efi_memory_attribute_protocol_t *memattr;
@@ -710,10 +712,12 @@ void efi_remap_image(unsigned long image_base, unsigned alloc_size,
* If the firmware implements the EFI_MEMORY_ATTRIBUTE_PROTOCOL, let's
* invoke it to remap the text/rodata region of the decompressed image
* as read-only and the data/bss region as non-executable.
+ * Don't bother if the protocol does not exist: it means all memory is
+ * read-write-exec anyway.
*/
status = efi_bs_call(locate_protocol, &guid, NULL, (void **)&memattr);
if (status != EFI_SUCCESS)
- return;
+ return EFI_SUCCESS;
// Get the current attributes for the entire region
status = memattr->get_memory_attributes(memattr, image_base,
@@ -721,7 +725,7 @@ void efi_remap_image(unsigned long image_base, unsigned alloc_size,
if (status != EFI_SUCCESS) {
efi_warn("Failed to retrieve memory attributes for image region: 0x%lx\n",
status);
- return;
+ return status;
}
// Mark the code region as read-only
@@ -729,7 +733,7 @@ void efi_remap_image(unsigned long image_base, unsigned alloc_size,
EFI_MEMORY_RO);
if (status != EFI_SUCCESS) {
efi_warn("Failed to remap code region read-only\n");
- return;
+ return status;
}
// If the entire region was already mapped as non-exec, clear the
@@ -749,4 +753,5 @@ void efi_remap_image(unsigned long image_base, unsigned alloc_size,
if (status != EFI_SUCCESS)
efi_warn("Failed to remap data region non-executable\n");
}
+ return status;
}
diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h
index b985ababbe66..634e52aa6dcc 100644
--- a/drivers/firmware/efi/libstub/efistub.h
+++ b/drivers/firmware/efi/libstub/efistub.h
@@ -1293,8 +1293,8 @@ struct efi_smbios_type4_record {
const u8 *__efi_get_smbios_string(const struct efi_smbios_record *record,
const u8 *offset);
-void efi_remap_image(unsigned long image_base, unsigned alloc_size,
- unsigned long code_size);
+efi_status_t efi_remap_image(unsigned long image_base, unsigned alloc_size,
+ unsigned long code_size);
efi_status_t efi_kaslr_relocate_kernel(unsigned long *image_addr,
unsigned long *reserve_addr,
unsigned long *reserve_size,
--
2.56.0.611.g1030f0b940-goog
next prev parent reply other threads:[~2026-11-16 14:27 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 14:26 [PATCH v3 00/15] efi: Expose loaded image properties via info struct Ard Biesheuvel
2026-11-16 14:26 ` [PATCH v3 01/15] efi/zboot: arm64: Add missing barrier after cache maintenance Ard Biesheuvel
2026-11-16 14:33 ` sashiko-bot
2026-11-16 14:26 ` [PATCH v3 02/15] riscv: Use _stext not _text to denote the start of kernel code Ard Biesheuvel
2026-11-16 14:26 ` [PATCH v3 03/15] riscv: Make _text point to the start of the kernel image Ard Biesheuvel
2026-11-16 14:26 ` [PATCH v3 04/15] efi/riscv: Rename __init_text_end to __inittext_end like other archs Ard Biesheuvel
2026-11-16 14:26 ` [PATCH v3 05/15] efi/libstub: Avoid _end section marker in library code Ard Biesheuvel
2026-11-16 14:26 ` [PATCH v3 06/15] efi/libstub: Capture loaded image information in struct efi_image_info Ard Biesheuvel
2026-11-16 14:59 ` sashiko-bot
2026-11-16 14:26 ` [PATCH v3 07/15] efi/libstub: Pass kernel entrypoint down to efi_enter_kernel() Ard Biesheuvel
2026-11-16 14:39 ` sashiko-bot
2026-11-16 14:26 ` [PATCH v3 08/15] efi/libstub: arm64: Use struct efi_image_info to access image properties Ard Biesheuvel
2026-11-16 14:26 ` [PATCH v3 09/15] efi/libstub: loongarch: " Ard Biesheuvel
2026-11-16 14:40 ` sashiko-bot
2026-11-16 14:26 ` [PATCH v3 10/15] efi/libstub: riscv: " Ard Biesheuvel
2026-11-16 14:26 ` Ard Biesheuvel [this message]
2026-11-16 14:26 ` [PATCH v3 12/15] efi/zboot: Disentangle efi_remap_image() from efi_cache_sync_image() Ard Biesheuvel
2026-11-16 14:52 ` sashiko-bot
2026-11-16 14:26 ` [PATCH v3 13/15] efi/libstub: arm64: Drop zboot code_size hack Ard Biesheuvel
2026-11-16 14:26 ` [PATCH v3 14/15] efi: Make config table based primary display handover ARM-only again Ard Biesheuvel
2026-11-16 14:26 ` [PATCH v3 15/15] Revert "efi: earlycon: Reprobe after parsing config tables" Ard Biesheuvel
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=20261116142618.1687025-28-ardb+git@google.com \
--to=ardb+git@google.com \
--cc=aou@eecs.berkeley.edu \
--cc=ardb@kernel.org \
--cc=chenhuacai@kernel.org \
--cc=jgg@nvidia.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-efi@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=loongarch@lists.linux.dev \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox