aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAKASHI Takahiro <takahiro.akashi@linaro.org>2018-04-06 10:55:38 +0900
committerAKASHI Takahiro <takahiro.akashi@linaro.org>2018-07-11 11:41:14 +0900
commit0dc412d1f7427604f291985ffdbaf1763fac7751 (patch)
treec25723904b4c58140136be822e3ff21966be6a0a
parent0ea445f81078dd67058cb1fd9841e81691cb53a5 (diff)
downloadlinux-aarch64-0dc412d1f7427604f291985ffdbaf1763fac7751.tar.gz
arm64: kexec_file: add kaslr support
Adding "kaslr-seed" to dtb enables triggering kaslr, or kernel virtual address randomization, at secondary kernel boot. We always do this as it will have no harm on kaslr-incapable kernel. We don't have any "switch" to turn off this feature directly, but still can suppress it by passing "nokaslr" as a kernel boot argument. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Will Deacon <will.deacon@arm.com>
-rw-r--r--arch/arm64/kernel/machine_kexec_file.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c
index 261564df7210..99d771afe88e 100644
--- a/arch/arm64/kernel/machine_kexec_file.c
+++ b/arch/arm64/kernel/machine_kexec_file.c
@@ -16,6 +16,7 @@
#include <linux/libfdt.h>
#include <linux/memblock.h>
#include <linux/of_fdt.h>
+#include <linux/random.h>
#include <linux/slab.h>
#include <linux/types.h>
#include <linux/vmalloc.h>
@@ -161,6 +162,12 @@ static int setup_dtb(struct kimage *image,
}
}
+ /* add kaslr-seed */
+ get_random_bytes(&value, sizeof(value));
+ ret = fdt_setprop(buf, nodeoffset, "kaslr-seed", &value, sizeof(value));
+ if (ret)
+ goto out_err;
+
/* trim a buffer */
fdt_pack(buf);
*dtb_buf = buf;