[PATCH v3 21/21] arm64: efi: invoke EFI_RNG_PROTOCOL to supply KASLR randomness

From
Matt Fleming <hidden>
Date
2016-01-21 16:31:56
Also in
lkml
Reply to
Ard Biesheuvel, 2016-01-11
On Mon, 11 Jan, at 02:19:15PM, Ard Biesheuvel wrote:
Since arm64 does not use a decompressor that supplies an execution
environment where it is feasible to some extent to provide a source of
randomness, the arm64 KASLR kernel depends on the bootloader to supply
some random bits in register x1 upon kernel entry.

On UEFI systems, we can use the EFI_RNG_PROTOCOL, if supplied, to obtain
some random bits. At the same time, use it to randomize the offset of the
kernel Image in physical memory.

Signed-off-by: Ard Biesheuvel <redacted>
---
 arch/arm64/Kconfig                             |  5 ++
 arch/arm64/kernel/efi-entry.S                  |  7 +-
 drivers/firmware/efi/libstub/arm-stub.c        | 17 ++---
 drivers/firmware/efi/libstub/arm64-stub.c      | 67 +++++++++++++++-----
 drivers/firmware/efi/libstub/efi-stub-helper.c | 10 +++
 drivers/firmware/efi/libstub/efistub.h         |  2 +
 6 files changed, 82 insertions(+), 26 deletions(-)
[...]
quoted hunk ↗ jump to hunk
diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c
index 2a7a3015d7e0..e8a3b8cd53cc 100644
--- a/drivers/firmware/efi/libstub/efi-stub-helper.c
+++ b/drivers/firmware/efi/libstub/efi-stub-helper.c
@@ -32,6 +32,10 @@
 
 static unsigned long __chunk_size = EFI_READ_CHUNK_SIZE;
 
+#ifdef CONFIG_RANDOMIZE_BASE
+bool __nokaslr;
+#endif
+
 /*
  * Allow the platform to override the allocation granularity: this allows
  * systems that have the capability to run with a larger page size to deal
@@ -317,6 +321,12 @@ efi_status_t efi_parse_options(char *cmdline)
 {
 	char *str;
 
+#ifdef CONFIG_RANDOMIZE_BASE
+	str = strstr(cmdline, "nokaslr");
+	if (str && (str == cmdline || *(str - 1) == ' '))
+		__nokaslr = true;
+#endif
+
 	/*
 	 * If no EFI parameters were specified on the cmdline we've got
 	 * nothing to do.
Could we not keep the "nokaslr" parsing inside of arm-stub.c? It's not
really specific to EFI and doesn't make use of any of the code in
efi_parse_options() anyhow.

As an added bonus, __nokaslr could then become static.
Thread (69 messages) 69 messages, 4 authors, last reply 2016-01-27
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help