Register a notifier so that when the RNG is initialized, the EFI variable containing the random seed can be refreshed. Signed-off-by: Jason A. Donenfeld <Jason@xxxxxxxxx> --- drivers/firmware/efi/efi.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index a46df5d1d094..db247a52d3c2 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -337,6 +337,19 @@ static void __init efi_debugfs_init(void) static inline void efi_debugfs_init(void) {} #endif +static int refresh_nv_rng_seed(struct notifier_block *nb, unsigned long action, void *data) +{ + u8 seed[EFI_RANDOM_SEED_SIZE]; + + get_random_bytes(seed, sizeof(seed)); + efi.set_variable(LINUX_EFI_RANDOM_NV_SEED_VAR, &LINUX_EFI_RANDOM_SEED_TABLE_GUID, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS, sizeof(seed), seed); + memzero_explicit(seed, sizeof(seed)); + return 0; +} +static struct notifier_block refresh_nv_rng_seed_nb = { .notifier_call = refresh_nv_rng_seed }; + /* * We register the efi subsystem with the firmware subsystem and the * efivars subsystem with the efi subsystem, if the system was booted with @@ -413,6 +426,7 @@ static int __init efisubsys_init(void) platform_device_register_simple("efi_secret", 0, NULL, 0); #endif + notify_on_rng_initialized(&refresh_nv_rng_seed_nb); return 0; err_remove_group: -- 2.38.1