lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <201908141353.043EF60B@keescook>
Date:   Wed, 14 Aug 2019 13:55:50 -0700
From:   Kees Cook <keescook@...omium.org>
To:     Will Deacon <will@...nel.org>
Cc:     Ard Biesheuvel <ard.biesheuvel@...aro.org>,
        linux-kernel@...r.kernel.org, Mark Rutland <mark.rutland@....com>
Subject: [PATCH] efi/libstub/arm64: Report meaningful relocation errors

When UEFI booting, if allocate_pages() fails (either via KASLR or
regular boot), efi_low_alloc() is used for fall back. If it, too, fails,
it reports "Failed to relocate kernel". Then handle_kernel_image()
reports the failure to its caller, which unhelpfully reports exactly
the same string again:

EFI stub: ERROR: Failed to relocate kernel
EFI stub: ERROR: Failed to relocate kernel

While debugging linker errors in the UEFI code that created insane memory
sizes that all the allocation attempts would fail at, this was a cause
for confusion. Knowing each allocation had failed would have helped me
isolate the issue sooner. To that end, this improves the error messages
to detail which specific allocations have failed.

Signed-off-by: Kees Cook <keescook@...omium.org>
---
 drivers/firmware/efi/libstub/arm64-stub.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/firmware/efi/libstub/arm64-stub.c b/drivers/firmware/efi/libstub/arm64-stub.c
index 1550d244e996..24022f956e01 100644
--- a/drivers/firmware/efi/libstub/arm64-stub.c
+++ b/drivers/firmware/efi/libstub/arm64-stub.c
@@ -111,6 +111,8 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table_arg,
 		status = efi_random_alloc(sys_table_arg, *reserve_size,
 					  MIN_KIMG_ALIGN, reserve_addr,
 					  (u32)phys_seed);
+		if (status != EFI_SUCCESS)
+			pr_efi_err(sys_table_arg, "KASLR allocate_pages() failed\n");
 
 		*image_addr = *reserve_addr + offset;
 	} else {
@@ -135,6 +137,8 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table_arg,
 					EFI_LOADER_DATA,
 					*reserve_size / EFI_PAGE_SIZE,
 					(efi_physical_addr_t *)reserve_addr);
+		if (status != EFI_SUCCESS)
+			pr_efi_err(sys_table_arg, "regular allocate_pages() failed\n");
 	}
 
 	if (status != EFI_SUCCESS) {
@@ -143,7 +147,7 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table_arg,
 				       MIN_KIMG_ALIGN, reserve_addr);
 
 		if (status != EFI_SUCCESS) {
-			pr_efi_err(sys_table_arg, "Failed to relocate kernel\n");
+			pr_efi_err(sys_table_arg, "efi_low_alloc() failed\n");
 			*reserve_size = 0;
 			return status;
 		}
-- 
2.17.1


-- 
Kees Cook

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ