From: Ard Biesheuvel <ardb@kernel.org>
To: linux-efi@vger.kernel.org
Cc: xen-devel@lists.xenproject.org,
"Ard Biesheuvel" <ardb@kernel.org>,
"Demi Marie Obenour" <demi@invisiblethingslab.com>,
"Peter Jones" <pjones@redhat.com>,
"Juergen Gross" <jgross@suse.com>,
"Stefano Stabellini" <sstabellini@kernel.org>,
"Oleksandr Tyshchenko" <oleksandr_tyshchenko@epam.com>,
"Kees Cook" <keescook@chromium.org>,
"Anton Vorontsov" <anton@enomsg.org>,
"Colin Cross" <ccross@android.com>,
"Tony Luck" <tony.luck@intel.com>,
"Marek Marczykowski-Górecki" <marmarek@invisiblethingslab.com>
Subject: [RFC PATCH 5/5] efi: esrt: Omit region sanity check when no memory map is available
Date: Sun, 2 Oct 2022 11:56:26 +0200 [thread overview]
Message-ID: <20221002095626.484279-6-ardb@kernel.org> (raw)
In-Reply-To: <20221002095626.484279-1-ardb@kernel.org>
In order to permit the ESRT to be used when doing pseudo-EFI boot
without a EFI memory map, e.g., when booting inside a Xen dom0 on x86,
make the sanity checks optional based on whether the memory map is
available.
If additional validation is needed, it is up to the Xen EFI glue code to
implement this in its xen_efi_config_table_is_valid() helper, or provide
a EFI memory map like it does on other architectures.
Co-developed-by: Demi Marie Obenour <demi@invisiblethingslab.com>
Signed-off-by: Demi Marie Obenour <demi@invisiblethingslab.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/x86/platform/efi/quirks.c | 3 +
drivers/firmware/efi/esrt.c | 61 +++++++++++---------
2 files changed, 37 insertions(+), 27 deletions(-)
diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c
index b0b848d6933a..9307be2f4afa 100644
--- a/arch/x86/platform/efi/quirks.c
+++ b/arch/x86/platform/efi/quirks.c
@@ -250,6 +250,9 @@ void __init efi_arch_mem_reserve(phys_addr_t addr, u64 size)
int num_entries;
void *new;
+ if (!efi_enabled(EFI_MEMMAP))
+ return;
+
if (efi_mem_desc_lookup(addr, &md) ||
md.type != EFI_BOOT_SERVICES_DATA) {
pr_err("Failed to lookup EFI memory descriptor for %pa\n", &addr);
diff --git a/drivers/firmware/efi/esrt.c b/drivers/firmware/efi/esrt.c
index 2a2f52b017e7..adb31fba45ae 100644
--- a/drivers/firmware/efi/esrt.c
+++ b/drivers/firmware/efi/esrt.c
@@ -243,40 +243,45 @@ void __init efi_esrt_init(void)
void *va;
struct efi_system_resource_table tmpesrt;
size_t size, max, entry_size, entries_size;
- efi_memory_desc_t md;
- int rc;
+ bool reserve_esrt;
phys_addr_t end;
- if (!efi_enabled(EFI_MEMMAP))
- return;
-
pr_debug("esrt-init: loading.\n");
if (!esrt_table_exists())
return;
- rc = efi_mem_desc_lookup(efi.esrt, &md);
- if (rc < 0 ||
- (!(md.attribute & EFI_MEMORY_RUNTIME) &&
- md.type != EFI_BOOT_SERVICES_DATA &&
- md.type != EFI_RUNTIME_SERVICES_DATA)) {
- pr_warn("ESRT header is not in the memory map.\n");
- return;
- }
+ size = sizeof(*esrt);
+ if (efi_enabled(EFI_MEMMAP)) {
+ efi_memory_desc_t md;
+ int rc;
+
+ rc = efi_mem_desc_lookup(efi.esrt, &md);
+ if (rc < 0 ||
+ (!(md.attribute & EFI_MEMORY_RUNTIME) &&
+ md.type != EFI_BOOT_SERVICES_DATA &&
+ md.type != EFI_RUNTIME_SERVICES_DATA)) {
+ pr_warn("ESRT header is not in the memory map.\n");
+ return;
+ }
- max = efi_mem_desc_end(&md);
- if (max < efi.esrt) {
- pr_err("EFI memory descriptor is invalid. (esrt: %p max: %p)\n",
- (void *)efi.esrt, (void *)max);
- return;
- }
+ reserve_esrt = (md.type == EFI_BOOT_SERVICES_DATA);
+ max = efi_mem_desc_end(&md);
+ if (max < efi.esrt) {
+ pr_err("EFI memory descriptor is invalid. (esrt: %p max: %p)\n",
+ (void *)efi.esrt, (void *)max);
+ return;
+ }
- size = sizeof(*esrt);
- max -= efi.esrt;
+ max -= efi.esrt;
- if (max < size) {
- pr_err("ESRT header doesn't fit on single memory map entry. (size: %zu max: %zu)\n",
- size, max);
- return;
+ if (max < size) {
+ pr_err("ESRT header doesn't fit on single memory map entry. (size: %zu max: %zu)\n",
+ size, max);
+ return;
+ }
+ } else {
+ reserve_esrt = true;
+ max = SIZE_MAX;
}
va = early_memremap(efi.esrt, size);
@@ -332,9 +337,11 @@ void __init efi_esrt_init(void)
esrt_data_size = size;
end = esrt_data + size;
- pr_info("Reserving ESRT space from %pa to %pa.\n", &esrt_data, &end);
- if (md.type == EFI_BOOT_SERVICES_DATA)
+ if (reserve_esrt) {
+ pr_info("Reserving ESRT space from %pa to %pa.\n", &esrt_data,
+ &end);
efi_mem_reserve(esrt_data, esrt_data_size);
+ }
pr_debug("esrt-init: loaded.\n");
}
--
2.35.1
next prev parent reply other threads:[~2022-10-02 9:56 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-02 9:56 [RFC PATCH 0/5] efi/x86: Avoid corrupted config tables under Xen Ard Biesheuvel
2022-10-02 9:56 ` [RFC PATCH 1/5] efi: Move EFI fake memmap support into x86 arch tree Ard Biesheuvel
2022-10-02 9:56 ` [RFC PATCH 2/5] efi: memmap: Move manipulation routines " Ard Biesheuvel
2022-10-02 9:56 ` [RFC PATCH 3/5] efi: xen: Set EFI_PARAVIRT for Xen dom0 boot on all architectures Ard Biesheuvel
2022-10-02 9:56 ` [RFC PATCH 4/5] efi: Apply allowlist to EFI configuration tables when running under Xen Ard Biesheuvel
2022-10-02 16:27 ` Demi Marie Obenour
2022-10-02 21:22 ` Ard Biesheuvel
2022-10-02 23:00 ` Demi Marie Obenour
2022-10-02 9:56 ` Ard Biesheuvel [this message]
2022-10-02 16:27 ` [RFC PATCH 5/5] efi: esrt: Omit region sanity check when no memory map is available Demi Marie Obenour
2022-10-02 21:43 ` Ard Biesheuvel
2022-10-03 8:41 ` 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=20221002095626.484279-6-ardb@kernel.org \
--to=ardb@kernel.org \
--cc=anton@enomsg.org \
--cc=ccross@android.com \
--cc=demi@invisiblethingslab.com \
--cc=jgross@suse.com \
--cc=keescook@chromium.org \
--cc=linux-efi@vger.kernel.org \
--cc=marmarek@invisiblethingslab.com \
--cc=oleksandr_tyshchenko@epam.com \
--cc=pjones@redhat.com \
--cc=sstabellini@kernel.org \
--cc=tony.luck@intel.com \
--cc=xen-devel@lists.xenproject.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.