aboutsummaryrefslogtreecommitdiff
path: root/hw/arm/virt.c
diff options
context:
space:
mode:
authorJerome Forissier <jerome@forissier.org>2020-04-20 14:18:07 +0200
committerPeter Maydell <peter.maydell@linaro.org>2020-04-30 15:35:41 +0100
commit60592cfed2b685ef114a454d176ef539528cb0cf (patch)
tree71a4ba8cfc0a45ff8d9c38840d82bf1244c61341 /hw/arm/virt.c
parentef6a5c71c2f40e253712ad3d8826d5e84e325aeb (diff)
downloadqemu-60592cfed2b685ef114a454d176ef539528cb0cf.zip
qemu-60592cfed2b685ef114a454d176ef539528cb0cf.tar.gz
qemu-60592cfed2b685ef114a454d176ef539528cb0cf.tar.bz2
hw/arm/virt: dt: add kaslr-seed property
Generate random seeds to be used by the non-secure and/or secure OSes for ASLR. The seeds are 64-bit random values exported via the DT properties /chosen/kaslr-seed [1] and /secure-chosen/kaslr-seed, the latter being used by OP-TEE [2]. [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=e5bc0c37c97e1 [2] https://github.com/OP-TEE/optee_os/commit/ef262691fe0e Signed-off-by: Jerome Forissier <jerome@forissier.org> Message-id: 20200420121807.8204-3-jerome@forissier.org Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw/arm/virt.c')
-rw-r--r--hw/arm/virt.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 0d92674..6268225 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -77,6 +77,7 @@
#include "hw/acpi/generic_event_device.h"
#include "hw/virtio/virtio-iommu.h"
#include "hw/char/pl011.h"
+#include "qemu/guest-random.h"
#define DEFINE_VIRT_MACHINE_LATEST(major, minor, latest) \
static void virt_##major##_##minor##_class_init(ObjectClass *oc, \
@@ -213,6 +214,18 @@ static bool cpu_type_valid(const char *cpu)
return false;
}
+static void create_kaslr_seed(VirtMachineState *vms, const char *node)
+{
+ Error *err = NULL;
+ uint64_t seed;
+
+ if (qemu_guest_getrandom(&seed, sizeof(seed), &err)) {
+ error_free(err);
+ return;
+ }
+ qemu_fdt_setprop_u64(vms->fdt, node, "kaslr-seed", seed);
+}
+
static void create_fdt(VirtMachineState *vms)
{
MachineState *ms = MACHINE(vms);
@@ -233,9 +246,11 @@ static void create_fdt(VirtMachineState *vms)
/* /chosen must exist for load_dtb to fill in necessary properties later */
qemu_fdt_add_subnode(fdt, "/chosen");
+ create_kaslr_seed(vms, "/chosen");
if (vms->secure) {
qemu_fdt_add_subnode(fdt, "/secure-chosen");
+ create_kaslr_seed(vms, "/secure-chosen");
}
/* Clock node, for the benefit of the UART. The kernel device tree