Skip to content

Commit 085e2ff

Browse files
committed
efi: libstub: Drop randomization of runtime memory map
Randomizing the UEFI runtime memory map requires the use of the SetVirtualAddressMap() EFI boot service, which we prefer to avoid. So let's drop randomization, which was already problematic in combination with hibernation, which means that distro kernels never enabled it in the first place. Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
1 parent f0c4d9f commit 085e2ff

File tree

1 file changed

+0
-29
lines changed

1 file changed

+0
-29
lines changed

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

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,6 @@
3535
* as well to minimize the code churn.
3636
*/
3737
#define EFI_RT_VIRTUAL_BASE SZ_512M
38-
#define EFI_RT_VIRTUAL_SIZE SZ_512M
39-
40-
#ifdef CONFIG_ARM64
41-
# define EFI_RT_VIRTUAL_LIMIT DEFAULT_MAP_WINDOW_64
42-
#elif defined(CONFIG_RISCV) || defined(CONFIG_LOONGARCH)
43-
# define EFI_RT_VIRTUAL_LIMIT TASK_SIZE_MIN
44-
#else /* Only if TASK_SIZE is a constant */
45-
# define EFI_RT_VIRTUAL_LIMIT TASK_SIZE
46-
#endif
4738

4839
/*
4940
* Some architectures map the EFI regions into the kernel's linear map using a
@@ -230,26 +221,6 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
230221
efi_novamap |= !(get_supported_rt_services() &
231222
EFI_RT_SUPPORTED_SET_VIRTUAL_ADDRESS_MAP);
232223

233-
/* hibernation expects the runtime regions to stay in the same place */
234-
if (!IS_ENABLED(CONFIG_HIBERNATION) && !efi_nokaslr && !flat_va_mapping) {
235-
/*
236-
* Randomize the base of the UEFI runtime services region.
237-
* Preserve the 2 MB alignment of the region by taking a
238-
* shift of 21 bit positions into account when scaling
239-
* the headroom value using a 32-bit random value.
240-
*/
241-
static const u64 headroom = EFI_RT_VIRTUAL_LIMIT -
242-
EFI_RT_VIRTUAL_BASE -
243-
EFI_RT_VIRTUAL_SIZE;
244-
u32 rnd;
245-
246-
status = efi_get_random_bytes(sizeof(rnd), (u8 *)&rnd);
247-
if (status == EFI_SUCCESS) {
248-
virtmap_base = EFI_RT_VIRTUAL_BASE +
249-
(((headroom >> 21) * rnd) >> (32 - 21));
250-
}
251-
}
252-
253224
install_memreserve_table();
254225

255226
status = efi_boot_kernel(handle, image, image_addr, cmdline_ptr);

0 commit comments

Comments
 (0)