aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/firmware/efi/libstub/arm-stub.c
diff options
context:
space:
mode:
authorArd Biesheuvel <ard.biesheuvel@linaro.org>2016-01-26 08:48:29 -0500
committerCatalin Marinas <catalin.marinas@arm.com>2016-02-24 09:57:29 -0500
commit2b5fe07a78a09a32002642b8a823428ade611f16 (patch)
treedb8929655f2d9de7827d68fbfad1ea08d1cd0e29 /drivers/firmware/efi/libstub/arm-stub.c
parent48fcb2d0216103d15306caa4814e2381104df6d8 (diff)
arm64: efi: invoke EFI_RNG_PROTOCOL to supply KASLR randomness
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 the /chosen/kaslr-seed DT property 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. Reviewed-by: Matt Fleming <matt@codeblueprint.co.uk> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Diffstat (limited to 'drivers/firmware/efi/libstub/arm-stub.c')
-rw-r--r--drivers/firmware/efi/libstub/arm-stub.c40
1 files changed, 27 insertions, 13 deletions
diff --git a/drivers/firmware/efi/libstub/arm-stub.c b/drivers/firmware/efi/libstub/arm-stub.c
index 3397902e4040..4deb3e7faa0e 100644
--- a/drivers/firmware/efi/libstub/arm-stub.c
+++ b/drivers/firmware/efi/libstub/arm-stub.c
@@ -18,6 +18,8 @@
18 18
19#include "efistub.h" 19#include "efistub.h"
20 20
21bool __nokaslr;
22
21static int efi_secureboot_enabled(efi_system_table_t *sys_table_arg) 23static int efi_secureboot_enabled(efi_system_table_t *sys_table_arg)
22{ 24{
23 static efi_guid_t const var_guid = EFI_GLOBAL_VARIABLE_GUID; 25 static efi_guid_t const var_guid = EFI_GLOBAL_VARIABLE_GUID;
@@ -207,14 +209,6 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table,
207 pr_efi_err(sys_table, "Failed to find DRAM base\n"); 209 pr_efi_err(sys_table, "Failed to find DRAM base\n");
208 goto fail; 210 goto fail;
209 } 211 }
210 status = handle_kernel_image(sys_table, image_addr, &image_size,
211 &reserve_addr,
212 &reserve_size,
213 dram_base, image);
214 if (status != EFI_SUCCESS) {
215 pr_efi_err(sys_table, "Failed to relocate kernel\n");
216 goto fail;
217 }
218 212
219 /* 213 /*
220 * Get the command line from EFI, using the LOADED_IMAGE 214 * Get the command line from EFI, using the LOADED_IMAGE
@@ -224,7 +218,28 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table,
224 cmdline_ptr = efi_convert_cmdline(sys_table, image, &cmdline_size); 218 cmdline_ptr = efi_convert_cmdline(sys_table, image, &cmdline_size);
225 if (!cmdline_ptr) { 219 if (!cmdline_ptr) {
226 pr_efi_err(sys_table, "getting command line via LOADED_IMAGE_PROTOCOL\n"); 220 pr_efi_err(sys_table, "getting command line via LOADED_IMAGE_PROTOCOL\n");
227 goto fail_free_image; 221 goto fail;
222 }
223
224 /* check whether 'nokaslr' was passed on the command line */
225 if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) {
226 static const u8 default_cmdline[] = CONFIG_CMDLINE;
227 const u8 *str, *cmdline = cmdline_ptr;
228
229 if (IS_ENABLED(CONFIG_CMDLINE_FORCE))
230 cmdline = default_cmdline;
231 str = strstr(cmdline, "nokaslr");
232 if (str == cmdline || (str > cmdline && *(str - 1) == ' '))
233 __nokaslr = true;
234 }
235
236 status = handle_kernel_image(sys_table, image_addr, &image_size,
237 &reserve_addr,
238 &reserve_size,
239 dram_base, image);
240 if (status != EFI_SUCCESS) {
241 pr_efi_err(sys_table, "Failed to relocate kernel\n");
242 goto fail_free_cmdline;
228 } 243 }
229 244
230 status = efi_parse_options(cmdline_ptr); 245 status = efi_parse_options(cmdline_ptr);
@@ -244,7 +259,7 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table,
244 259
245 if (status != EFI_SUCCESS) { 260 if (status != EFI_SUCCESS) {
246 pr_efi_err(sys_table, "Failed to load device tree!\n"); 261 pr_efi_err(sys_table, "Failed to load device tree!\n");
247 goto fail_free_cmdline; 262 goto fail_free_image;
248 } 263 }
249 } 264 }
250 265
@@ -286,12 +301,11 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table,
286 efi_free(sys_table, initrd_size, initrd_addr); 301 efi_free(sys_table, initrd_size, initrd_addr);
287 efi_free(sys_table, fdt_size, fdt_addr); 302 efi_free(sys_table, fdt_size, fdt_addr);
288 303
289fail_free_cmdline:
290 efi_free(sys_table, cmdline_size, (unsigned long)cmdline_ptr);
291
292fail_free_image: 304fail_free_image:
293 efi_free(sys_table, image_size, *image_addr); 305 efi_free(sys_table, image_size, *image_addr);
294 efi_free(sys_table, reserve_size, reserve_addr); 306 efi_free(sys_table, reserve_size, reserve_addr);
307fail_free_cmdline:
308 efi_free(sys_table, cmdline_size, (unsigned long)cmdline_ptr);
295fail: 309fail:
296 return EFI_ERROR; 310 return EFI_ERROR;
297} 311}