efi: Make rng_seed table handling local to efi.c

Move the rng_seed table address from struct efi into a static global
variable in efi.c, which is the only place we ever refer to it anyway.
This reduces the footprint of struct efi, which is a r/w data structure
that is shared with the world.

Tested-by: Tony Luck <tony.luck@intel.com> # arch/ia64
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
This commit is contained in:
Ard Biesheuvel 2020-01-22 14:58:15 +01:00
parent fd506e0cf9
commit 5d288dbd88
2 changed files with 10 additions and 12 deletions

View File

@ -44,13 +44,14 @@ struct efi __read_mostly efi = {
.config_table = EFI_INVALID_TABLE_ADDR, .config_table = EFI_INVALID_TABLE_ADDR,
.esrt = EFI_INVALID_TABLE_ADDR, .esrt = EFI_INVALID_TABLE_ADDR,
.mem_attr_table = EFI_INVALID_TABLE_ADDR, .mem_attr_table = EFI_INVALID_TABLE_ADDR,
.rng_seed = EFI_INVALID_TABLE_ADDR,
.tpm_log = EFI_INVALID_TABLE_ADDR, .tpm_log = EFI_INVALID_TABLE_ADDR,
.tpm_final_log = EFI_INVALID_TABLE_ADDR, .tpm_final_log = EFI_INVALID_TABLE_ADDR,
.mem_reserve = EFI_INVALID_TABLE_ADDR, .mem_reserve = EFI_INVALID_TABLE_ADDR,
}; };
EXPORT_SYMBOL(efi); EXPORT_SYMBOL(efi);
static unsigned long __ro_after_init rng_seed = EFI_INVALID_TABLE_ADDR;
struct mm_struct efi_mm = { struct mm_struct efi_mm = {
.mm_rb = RB_ROOT, .mm_rb = RB_ROOT,
.mm_users = ATOMIC_INIT(2), .mm_users = ATOMIC_INIT(2),
@ -467,7 +468,7 @@ static __initdata efi_config_table_type_t common_tables[] = {
{SMBIOS3_TABLE_GUID, "SMBIOS 3.0", &efi.smbios3}, {SMBIOS3_TABLE_GUID, "SMBIOS 3.0", &efi.smbios3},
{EFI_SYSTEM_RESOURCE_TABLE_GUID, "ESRT", &efi.esrt}, {EFI_SYSTEM_RESOURCE_TABLE_GUID, "ESRT", &efi.esrt},
{EFI_MEMORY_ATTRIBUTES_TABLE_GUID, "MEMATTR", &efi.mem_attr_table}, {EFI_MEMORY_ATTRIBUTES_TABLE_GUID, "MEMATTR", &efi.mem_attr_table},
{LINUX_EFI_RANDOM_SEED_TABLE_GUID, "RNG", &efi.rng_seed}, {LINUX_EFI_RANDOM_SEED_TABLE_GUID, "RNG", &rng_seed},
{LINUX_EFI_TPM_EVENT_LOG_GUID, "TPMEventLog", &efi.tpm_log}, {LINUX_EFI_TPM_EVENT_LOG_GUID, "TPMEventLog", &efi.tpm_log},
{LINUX_EFI_TPM_FINAL_LOG_GUID, "TPMFinalLog", &efi.tpm_final_log}, {LINUX_EFI_TPM_FINAL_LOG_GUID, "TPMFinalLog", &efi.tpm_final_log},
{LINUX_EFI_MEMRESERVE_TABLE_GUID, "MEMRESERVE", &efi.mem_reserve}, {LINUX_EFI_MEMRESERVE_TABLE_GUID, "MEMRESERVE", &efi.mem_reserve},
@ -535,11 +536,11 @@ int __init efi_config_parse_tables(void *config_tables, int count, int sz,
pr_cont("\n"); pr_cont("\n");
set_bit(EFI_CONFIG_TABLES, &efi.flags); set_bit(EFI_CONFIG_TABLES, &efi.flags);
if (efi.rng_seed != EFI_INVALID_TABLE_ADDR) { if (rng_seed != EFI_INVALID_TABLE_ADDR) {
struct linux_efi_random_seed *seed; struct linux_efi_random_seed *seed;
u32 size = 0; u32 size = 0;
seed = early_memremap(efi.rng_seed, sizeof(*seed)); seed = early_memremap(rng_seed, sizeof(*seed));
if (seed != NULL) { if (seed != NULL) {
size = seed->size; size = seed->size;
early_memunmap(seed, sizeof(*seed)); early_memunmap(seed, sizeof(*seed));
@ -547,8 +548,7 @@ int __init efi_config_parse_tables(void *config_tables, int count, int sz,
pr_err("Could not map UEFI random seed!\n"); pr_err("Could not map UEFI random seed!\n");
} }
if (size > 0) { if (size > 0) {
seed = early_memremap(efi.rng_seed, seed = early_memremap(rng_seed, sizeof(*seed) + size);
sizeof(*seed) + size);
if (seed != NULL) { if (seed != NULL) {
pr_notice("seeding entropy pool\n"); pr_notice("seeding entropy pool\n");
add_bootloader_randomness(seed->bits, seed->size); add_bootloader_randomness(seed->bits, seed->size);
@ -1048,7 +1048,7 @@ static int update_efi_random_seed(struct notifier_block *nb,
if (!kexec_in_progress) if (!kexec_in_progress)
return NOTIFY_DONE; return NOTIFY_DONE;
seed = memremap(efi.rng_seed, sizeof(*seed), MEMREMAP_WB); seed = memremap(rng_seed, sizeof(*seed), MEMREMAP_WB);
if (seed != NULL) { if (seed != NULL) {
size = min(seed->size, EFI_RANDOM_SEED_SIZE); size = min(seed->size, EFI_RANDOM_SEED_SIZE);
memunmap(seed); memunmap(seed);
@ -1056,8 +1056,7 @@ static int update_efi_random_seed(struct notifier_block *nb,
pr_err("Could not map UEFI random seed!\n"); pr_err("Could not map UEFI random seed!\n");
} }
if (size > 0) { if (size > 0) {
seed = memremap(efi.rng_seed, sizeof(*seed) + size, seed = memremap(rng_seed, sizeof(*seed) + size, MEMREMAP_WB);
MEMREMAP_WB);
if (seed != NULL) { if (seed != NULL) {
seed->size = size; seed->size = size;
get_random_bytes(seed->bits, seed->size); get_random_bytes(seed->bits, seed->size);
@ -1073,9 +1072,9 @@ static struct notifier_block efi_random_seed_nb = {
.notifier_call = update_efi_random_seed, .notifier_call = update_efi_random_seed,
}; };
static int register_update_efi_random_seed(void) static int __init register_update_efi_random_seed(void)
{ {
if (efi.rng_seed == EFI_INVALID_TABLE_ADDR) if (rng_seed == EFI_INVALID_TABLE_ADDR)
return 0; return 0;
return register_reboot_notifier(&efi_random_seed_nb); return register_reboot_notifier(&efi_random_seed_nb);
} }

View File

@ -540,7 +540,6 @@ extern struct efi {
unsigned long config_table; /* config tables */ unsigned long config_table; /* config tables */
unsigned long esrt; /* ESRT table */ unsigned long esrt; /* ESRT table */
unsigned long mem_attr_table; /* memory attributes table */ unsigned long mem_attr_table; /* memory attributes table */
unsigned long rng_seed; /* UEFI firmware random seed */
unsigned long tpm_log; /* TPM2 Event Log table */ unsigned long tpm_log; /* TPM2 Event Log table */
unsigned long tpm_final_log; /* TPM2 Final Events Log table */ unsigned long tpm_final_log; /* TPM2 Final Events Log table */
unsigned long mem_reserve; /* Linux EFI memreserve table */ unsigned long mem_reserve; /* Linux EFI memreserve table */