@@ -77,6 +77,7 @@
#include "hw/acpi/generic_event_device.h"
#include "hw/virtio/virtio-iommu.h"
#include "hw/char/pl011.h"
+#include "crypto/random.h"
#define DEFINE_VIRT_MACHINE_LATEST(major, minor, latest) \
static void virt_##major##_##minor##_class_init(ObjectClass *oc, \
@@ -1635,6 +1636,18 @@ static void finalize_gic_version(VirtMachineState *vms)
}
}
+static void create_secure_kaslr_seed(VirtMachineState *vms)
+{
+ Error *err = NULL;
+ uint64_t seed;
+
+ if (qcrypto_random_bytes(&seed, sizeof(seed), &err)) {
+ error_free(err);
+ return;
+ }
+ qemu_fdt_setprop_u64(vms->fdt, "/secure-chosen", "kaslr-seed", seed);
+}
+
static void machvirt_init(MachineState *machine)
{
VirtMachineState *vms = VIRT_MACHINE(machine);
@@ -1837,6 +1850,7 @@ static void machvirt_init(MachineState *machine)
if (vms->secure) {
create_secure_ram(vms, secure_sysmem);
create_uart(vms, VIRT_SECURE_UART, secure_sysmem, serial_hd(1));
+ create_secure_kaslr_seed(vms);
}
vms->highmem_ecam &= vms->highmem && (!firmware_loaded || aarch64);
This commit generates a random seed to be used by the secure OS for ASLR when the machine is secure. The seed is a 64-bit random value exported via the DT in /secure-chosen/kaslr-seed. This interface is used by OP-TEE [1]. [1] https://github.com/OP-TEE/optee_os/commit/ef262691fe0e Signed-off-by: Jerome Forissier <jerome@forissier.org> --- hw/arm/virt.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)