-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
x86/boot/compressed: Handle unaccepted memory
The firmware will pre-accept the memory used to run the stub. But, the stub is responsible for accepting the memory into which it decompresses the main kernel. Accept memory just before decompression starts. The stub is also responsible for choosing a physical address in which to place the decompressed kernel image. The KASLR mechanism will randomize this physical address. Since the accepted memory region is relatively small, KASLR would be quite ineffective if it only used the pre-accepted area (EFI_CONVENTIONAL_MEMORY). Ensure that KASLR randomizes among the entire physical address space by also including EFI_UNACCEPTED_MEMORY. Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Liam Merwick <liam.merwick@oracle.com> Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com> Link: https://lore.kernel.org/r/20230606142637.5171-5-kirill.shutemov@linux.intel.com
- Loading branch information
Kirill A. Shutemov
authored and
Borislav Petkov (AMD)
committed
Jun 6, 2023
1 parent
745e3ed
commit 3fd1239
Showing
5 changed files
with
95 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,50 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only | ||
|
||
#include "error.h" | ||
#include "misc.h" | ||
|
||
void arch_accept_memory(phys_addr_t start, phys_addr_t end) | ||
{ | ||
/* Platform-specific memory-acceptance call goes here */ | ||
error("Cannot accept memory"); | ||
} | ||
|
||
bool init_unaccepted_memory(void) | ||
{ | ||
guid_t guid = LINUX_EFI_UNACCEPTED_MEM_TABLE_GUID; | ||
struct efi_unaccepted_memory *table; | ||
unsigned long cfg_table_pa; | ||
unsigned int cfg_table_len; | ||
enum efi_type et; | ||
int ret; | ||
|
||
et = efi_get_type(boot_params); | ||
if (et == EFI_TYPE_NONE) | ||
return false; | ||
|
||
ret = efi_get_conf_table(boot_params, &cfg_table_pa, &cfg_table_len); | ||
if (ret) { | ||
warn("EFI config table not found."); | ||
return false; | ||
} | ||
|
||
table = (void *)efi_find_vendor_table(boot_params, cfg_table_pa, | ||
cfg_table_len, guid); | ||
if (!table) | ||
return false; | ||
|
||
if (table->version != 1) | ||
error("Unknown version of unaccepted memory table\n"); | ||
|
||
/* | ||
* In many cases unaccepted_table is already set by EFI stub, but it | ||
* has to be initialized again to cover cases when the table is not | ||
* allocated by EFI stub or EFI stub copied the kernel image with | ||
* efi_relocate_kernel() before the variable is set. | ||
* | ||
* It must be initialized before the first usage of accept_memory(). | ||
*/ | ||
unaccepted_table = table; | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters