Skip to content

Commit

Permalink
hack: efi: stub: override RT_PROP table supported mask based on EFI v…
Browse files Browse the repository at this point in the history
…ariable

Allow EFI systems to override the set of supported runtime services
declared via the RT_PROP table, by checking for the existence of a
'OverrideSupported' EFI variable of the appropriate size under the
RT_PROP table GUID, and if it does, combine the supported mask using
logical AND. (This means the override can only remove support, not
add it back).

Cc: Jeffrey Hugo <jhugo@codeaurora.org>,
Cc: Bjorn Andersson <bjorn.andersson@linaro.org>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Rob Clark <robdclark@gmail.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: linux-arm-msm@vger.kernel.org

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
  • Loading branch information
ardbiesheuvel authored and 0x011011110 committed Jul 14, 2023
1 parent ff5d8be commit 089846c
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions drivers/firmware/efi/libstub/efi-stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,41 @@ static void install_memreserve_table(void)
efi_err("Failed to install memreserve config table!\n");
}

static void check_rt_properties_table_override(void)
{
static const efi_guid_t rt_prop_guid = EFI_RT_PROPERTIES_TABLE_GUID;
efi_rt_properties_table_t *table;
unsigned long size = sizeof(u32);
efi_status_t status;
u32 override;

status = get_efi_var(L"OverrideSupported", &rt_prop_guid, NULL, &size, &override);
if (status != EFI_SUCCESS || size != sizeof(override))
return;

table = get_efi_config_table(rt_prop_guid);
if (!table) {
/* no table exists yet - allocate a new one */
status = efi_bs_call(allocate_pool, EFI_RUNTIME_SERVICES_DATA,
sizeof(*table), (void **)&table);
if (status != EFI_SUCCESS)
return;
table->version = EFI_RT_PROPERTIES_TABLE_VERSION;
table->length = sizeof(*table);
table->runtime_services_supported = EFI_RT_SUPPORTED_ALL;

status = efi_bs_call(install_configuration_table,
(efi_guid_t *)&rt_prop_guid, table);
if (status != EFI_SUCCESS) {
efi_warn("Failed to install RT_PROP override table\n");
return;
}
}

efi_info("Applying RT_PROP table override from EFI variable\n");
table->runtime_services_supported &= override;
}

static u32 get_supported_rt_services(void)
{
const efi_rt_properties_table_t *rt_prop_table;
Expand Down Expand Up @@ -203,6 +238,8 @@ efi_status_t efi_alloc_virtmap(efi_memory_desc_t **virtmap,
unsigned long size, mmap_key;
efi_status_t status;

check_rt_properties_table_override();

/*
* Use the size of the current memory map as an upper bound for the
* size of the buffer we need to pass to SetVirtualAddressMap() to
Expand Down

0 comments on commit 089846c

Please sign in to comment.