Skip to content

Commit

Permalink
efi/arm64: libstub: Deal gracefully with EFI_RNG_PROTOCOL failure
Browse files Browse the repository at this point in the history
Currently, on arm64, we abort on any failure from efi_get_random_bytes()
other than EFI_NOT_FOUND when it comes to setting the physical seed for
KASLR, but ignore such failures when obtaining the seed for virtual
KASLR or for early seeding of the kernel's entropy pool via the config
table. This is inconsistent, and may lead to unexpected boot failures.

So let's permit any failure for the physical seed, and simply report
the error code if it does not equal EFI_NOT_FOUND.

Cc: <stable@vger.kernel.org> # v5.8+
Reported-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
  • Loading branch information
ardbiesheuvel committed Sep 29, 2020
1 parent 336af6a commit d32de91
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 5 additions & 3 deletions drivers/firmware/efi/libstub/arm64-stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
status = efi_get_random_bytes(sizeof(phys_seed),
(u8 *)&phys_seed);
if (status == EFI_NOT_FOUND) {
efi_info("EFI_RNG_PROTOCOL unavailable, no randomness supplied\n");
efi_info("EFI_RNG_PROTOCOL unavailable, KASLR will be disabled\n");
efi_nokaslr = true;
} else if (status != EFI_SUCCESS) {
efi_err("efi_get_random_bytes() failed\n");
return status;
efi_err("efi_get_random_bytes() failed (0x%lx), KASLR will be disabled\n",
status);
efi_nokaslr = true;
}
} else {
efi_info("KASLR disabled on kernel command line\n");
Expand Down
4 changes: 1 addition & 3 deletions drivers/firmware/efi/libstub/fdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ static efi_status_t update_fdt(void *orig_fdt, unsigned long orig_fdt_size,
if (status)
goto fdt_set_fail;

if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) {
if (IS_ENABLED(CONFIG_RANDOMIZE_BASE) && !efi_nokaslr) {
efi_status_t efi_status;

efi_status = efi_get_random_bytes(sizeof(fdt_val64),
Expand All @@ -145,8 +145,6 @@ static efi_status_t update_fdt(void *orig_fdt, unsigned long orig_fdt_size,
status = fdt_setprop_var(fdt, node, "kaslr-seed", fdt_val64);
if (status)
goto fdt_set_fail;
} else if (efi_status != EFI_NOT_FOUND) {
return efi_status;
}
}

Expand Down

0 comments on commit d32de91

Please sign in to comment.