hw/arm/virt: dt: add kaslr-seed property
v2 cover hw/arm/virt: dt: add kaslr-seed property
This patchset creates the DT property /chosen/kaslr-seed which is used by the OS for Address Space Layout Randomization. If the machine is secure, a similar property is created under /secure-chosen.
Changes since v1:
- Move creation of /secure-chosen to create_fdt()
- Use qemu_guest_getrandom() instead of qcrypto_random_bytes()
- Create kaslr-seed for the non-secure OS too
Jerome Forissier (2):
hw/arm/virt: dt: move creation of /secure-chosen to create_fdt() hw/arm/virt: dt: add kaslr-seed property
hw/arm/virt.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
Signature · 1 line
2.20.1
PATCH v2 1/2 hw/arm/virt: dt: move creation of /secure-chosen to create_fdt()
The /secure-chosen node is currently used only by create_uart(), but this will change. Therefore move the creation of this node to create_fdt().
--- hw/arm/virt.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
hw/arm/virt.c +4 -1
@@ -234,6 +234,10 @@ static void create_fdt(VirtMachineState *vms)/* /chosen must exist for load_dtb to fill in necessary properties later */ qemu_fdt_add_subnode (fdt,"/chosen" ); +if (vms->secure) { +qemu_fdt_add_subnode (fdt,"/secure-chosen" ); + } +/* Clock node, for the benefit of the UART. The kernel device tree * binding documentation claims the PL011 node clock properties are * optional but in practice if you omit them the kernel refuses to
@@ -761,7 +765,6 @@ static void create_uart(const VirtMachineState *vms, int uart,qemu_fdt_setprop_string (vms->fdt, nodename,"status" ,"disabled" );qemu_fdt_setprop_string (vms->fdt, nodename,"secure-status" ,"okay" ); -qemu_fdt_add_subnode (vms->fdt,"/secure-chosen" );qemu_fdt_setprop_string (vms->fdt,"/secure-chosen" ,"stdout-path" , nodename); }
Signature · 1 line
2.20.1
PATCH v2 2/2 hw/arm/virt: dt: add kaslr-seed property
In reply to Jerome ForissierGenerate 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
--- hw/arm/virt.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
hw/arm/virt.c +15 -0
@@ -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
Signature · 1 line
2.20.1
Peter Maydell
AppliedQuoted 5 lines · Jerome Forissier
This patchset creates the DT property /chosen/kaslr-seed which is used by the OS for Address Space Layout Randomization. If the machine is secure, a similar property is created under /secure-chosen.
Quoted 8 lines
Changes since v1:
- Move creation of /secure-chosen tocreate_fdt()
- Useqemu_guest_getrandom()instead ofqcrypto_random_bytes()
- Create kaslr-seed for the non-secure OS tooJerome Forissier (2):
hw/arm/virt: dt: move creation of /secure-chosen tocreate_fdt()hw/arm/virt: dt: add kaslr-seed property
Applied to target-arm.next, thanks.
-- PMM