Skip to content

Commit 66bbfa3

Browse files
ardbiesheuvel0x011011110
authored andcommitted
hack: efi: stub: override RT_PROP table supported mask based on EFI variable
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 <[email protected]>, Cc: Bjorn Andersson <[email protected]> Cc: Shawn Guo <[email protected]> Cc: Rob Clark <[email protected]> Cc: Leif Lindholm <[email protected]> Cc: [email protected] Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent f8d0517 commit 66bbfa3

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

drivers/firmware/efi/libstub/efi-stub.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,41 @@ static void install_memreserve_table(void)
9898
efi_err("Failed to install memreserve config table!\n");
9999
}
100100

101+
static void check_rt_properties_table_override(void)
102+
{
103+
static const efi_guid_t rt_prop_guid = EFI_RT_PROPERTIES_TABLE_GUID;
104+
efi_rt_properties_table_t *table;
105+
unsigned long size = sizeof(u32);
106+
efi_status_t status;
107+
u32 override;
108+
109+
status = get_efi_var(L"OverrideSupported", &rt_prop_guid, NULL, &size, &override);
110+
if (status != EFI_SUCCESS || size != sizeof(override))
111+
return;
112+
113+
table = get_efi_config_table(rt_prop_guid);
114+
if (!table) {
115+
/* no table exists yet - allocate a new one */
116+
status = efi_bs_call(allocate_pool, EFI_RUNTIME_SERVICES_DATA,
117+
sizeof(*table), (void **)&table);
118+
if (status != EFI_SUCCESS)
119+
return;
120+
table->version = EFI_RT_PROPERTIES_TABLE_VERSION;
121+
table->length = sizeof(*table);
122+
table->runtime_services_supported = EFI_RT_SUPPORTED_ALL;
123+
124+
status = efi_bs_call(install_configuration_table,
125+
(efi_guid_t *)&rt_prop_guid, table);
126+
if (status != EFI_SUCCESS) {
127+
efi_warn("Failed to install RT_PROP override table\n");
128+
return;
129+
}
130+
}
131+
132+
efi_info("Applying RT_PROP table override from EFI variable\n");
133+
table->runtime_services_supported &= override;
134+
}
135+
101136
static u32 get_supported_rt_services(void)
102137
{
103138
const efi_rt_properties_table_t *rt_prop_table;
@@ -203,6 +238,8 @@ efi_status_t efi_alloc_virtmap(efi_memory_desc_t **virtmap,
203238
unsigned long size, mmap_key;
204239
efi_status_t status;
205240

241+
check_rt_properties_table_override();
242+
206243
/*
207244
* Use the size of the current memory map as an upper bound for the
208245
* size of the buffer we need to pass to SetVirtualAddressMap() to

0 commit comments

Comments
 (0)