efi: random: zero out secret after use and do not take minimum
Subsystems (2)
PATCH 1/1 efi: random: zero out secret after use and do not take minimum
Taking the minimum is wrong, if the bootloader or EFI stub is actually passing on a bunch of bytes that it expects the kernel to hash itself. Ideally, a bootloader will hash it for us, but STUB won't do that, so we should map all the bytes. Also, all those bytes must be zeroed out after use to preserve forward secrecy.
--- drivers/firmware/efi/efi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/firmware/efi/efi.c +2 -1
@@ -630,7 +630,7 @@ int __init efi_config_parse_tables(const efi_config_table_t *config_tables, seed =early_memremap (efi_rng_seed,sizeof (*seed));if (seed !=NULL ) { - size =min (seed->size,EFI_RANDOM_SEED_SIZE ); + size = seed->size;early_memunmap (seed,sizeof (*seed)); }else {pr_err ("Could not map UEFI random seed!\n" );
@@ -641,6 +641,7 @@ int __init efi_config_parse_tables(const efi_config_table_t *config_tables,if (seed !=NULL ) {pr_notice ("seeding entropy pool\n" );add_bootloader_randomness (seed->bits, size); +memzero_explicit (seed->bits, size);early_memunmap (seed,sizeof (*seed) + size); }else {pr_err ("Could not map UEFI random seed!\n" );
Signature · 1 line
2.38.1
Ard Biesheuvel
maintainerQuoted 3 lines · Jason A. Donenfeld
Taking the minimum is wrong, if the bootloader or EFI stub is actually passing on a bunch of bytes that it expects the kernel to hash itself.
We still need some kind of limit, just so things don't explode if seed->size is bogus.
Quoted 37 lines
Ideally, a bootloader will hash it for us, but STUB won't do that, so we should map all the bytes. Also, all those bytes must be zeroed out after use to preserve forward secrecy.
Fixes 161a438d730d ("efi: random: reduce seed size to 32 bytes")Cc [email protected] # v4.14+Cc Ard Biesheuvel <[email protected]>Cc Ilias Apalodimas <[email protected]>Signed-off-by Jason A. Donenfeld <[email protected]>--- drivers/firmware/efi/efi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/firmware/efi/efi.c +2
-2@@ -630,7 +630,7 @@ int __init efi_config_parse_tables(const efi_config_table_t *config_tables, seed =early_memremap (efi_rng_seed,sizeof (*seed));if (seed !=NULL ) { - size =min (seed->size,EFI_RANDOM_SEED_SIZE ); + size = seed->size;early_memunmap (seed,sizeof (*seed)); }else {pr_err ("Could not map UEFI random seed!\n" );@@ -641,6 +641,7 @@ int __init efi_config_parse_tables(const efi_config_table_t *config_tables,if (seed !=NULL ) {pr_notice ("seeding entropy pool\n" );add_bootloader_randomness (seed->bits, size); +memzero_explicit (seed->bits, size);early_memunmap (seed,sizeof (*seed) + size); }else {pr_err ("Could not map UEFI random seed!\n" ); --2.38.1
Quoted 7 lines · Ard Biesheuvel
Quoted 3 lines · Jason A. Donenfeld
Taking the minimum is wrong, if the bootloader or EFI stub is actually passing on a bunch of bytes that it expects the kernel to hash itself.
We still need some kind of limit, just so things don't explode if
seed->sizeis bogus.
Alright, let's just say 1k then. Will send a v2.
Jason
PATCH v2 1/1 efi: random: zero out secret after use and do not take minimum
Taking the minimum is wrong, if the bootloader or EFI stub is actually passing on a bunch of bytes that it expects the kernel to hash itself. Ideally, a bootloader will hash it for us, but STUB won't do that, so we should map all the bytes. Also, all those bytes must be zeroed out after use to preserve forward secrecy.
---
Changes v1->v2:
- Cap size to 1k.
drivers/firmware/efi/efi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/firmware/efi/efi.c +2 -1
@@ -611,7 +611,7 @@ int __init efi_config_parse_tables(const efi_config_table_t *config_tables, seed =early_memremap (efi_rng_seed,sizeof (*seed));if (seed !=NULL ) { - size =min (seed->size,EFI_RANDOM_SEED_SIZE ); + size =min_t (u32,SZ_1K , seed->size);early_memunmap (seed,sizeof (*seed)); }else {pr_err ("Could not map UEFI random seed!\n" );
@@ -622,6 +622,7 @@ int __init efi_config_parse_tables(const efi_config_table_t *config_tables,if (seed !=NULL ) {pr_notice ("seeding entropy pool\n" );add_bootloader_randomness (seed->bits, size); +memzero_explicit (seed->bits, size);early_memunmap (seed,sizeof (*seed) + size); }else {pr_err ("Could not map UEFI random seed!\n" );
Signature · 1 line
2.38.1
Ard Biesheuvel
maintainerQuoted 12 lines · Jason A. Donenfeld
Taking the minimum is wrong, if the bootloader or EFI stub is actually passing on a bunch of bytes that it expects the kernel to hash itself. Ideally, a bootloader will hash it for us, but STUB won't do that, so we should map all the bytes. Also, all those bytes must be zeroed out after use to preserve forward secrecy.
Fixes 161a438d730d ("efi: random: reduce seed size to 32 bytes")Cc [email protected] # v4.14+Cc Ard Biesheuvel <[email protected]>Cc Ilias Apalodimas <[email protected]>Signed-off-by Jason A. Donenfeld <[email protected]>
Quoted 6 lines
---
Changesv1->v2:
- Cap size to 1k.drivers/firmware/efi/efi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Thanks. I'll just incorporate this into the patch that does the concatenation of seeds in the stub, which is queued up for v6.2
Quoted 24 lines
drivers/firmware/efi/efi.c +2
-2@@ -611,7 +611,7 @@ int __init efi_config_parse_tables(const efi_config_table_t *config_tables, seed =early_memremap (efi_rng_seed,sizeof (*seed));if (seed !=NULL ) { - size =min (seed->size,EFI_RANDOM_SEED_SIZE ); + size =min_t (u32,SZ_1K , seed->size);early_memunmap (seed,sizeof (*seed)); }else {pr_err ("Could not map UEFI random seed!\n" );@@ -622,6 +622,7 @@ int __init efi_config_parse_tables(const efi_config_table_t *config_tables,if (seed !=NULL ) {pr_notice ("seeding entropy pool\n" );add_bootloader_randomness (seed->bits, size); +memzero_explicit (seed->bits, size);early_memunmap (seed,sizeof (*seed) + size); }else {pr_err ("Could not map UEFI random seed!\n" ); --2.38.1