]> git.baikalelectronics.ru Git - kernel.git/commit
efi: stub: prefer mirrored memory for randomized allocations
authorArd Biesheuvel <ardb@kernel.org>
Tue, 3 May 2022 12:29:39 +0000 (14:29 +0200)
committerArd Biesheuvel <ardb@kernel.org>
Fri, 6 May 2022 07:51:22 +0000 (09:51 +0200)
commitea018bdf8f369f2188878ab20b9781d53f398053
treec4352b79e52aa376e96fb5096b89a05df6939779
parent0889bc49b525e72e5e49220bb7cdb62944271ebf
efi: stub: prefer mirrored memory for randomized allocations

If the system exposes memory regions with the EFI_MORE_RELIABLE
attribute, it is implied that it is intended to be used for allocations
that are relatively important, such as the kernel's static image.

Since efi_random_alloc() is mostly (only) used for allocating space for
the kernel image, let's update it to take this into account, and
disregard all memory without the EFI_MORE_RELIABLE attribute if there is
sufficient memory available that does have this attribute.

Note that this change only affects booting with randomization enabled.
In other cases, the EFI stub runs the kernel image in place unless its
placement is unsuitable for some reason (i.e., misaligned, or its BSS
overlaps with another allocation), and it is left to the bootloader to
ensure that the kernel was loaded into EFI_MORE_RELIABLE memory if this
is desired.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Kefeng Wang <wangkefeng.wang@huawei.com>
drivers/firmware/efi/libstub/randomalloc.c