On 25/10/22 02:43, Jason A. Donenfeld wrote:
When the system reboots, the rng-seed that the FDT has should be
re-randomized, so that the new boot gets a new seed. Several
architectures require this functionality, so export a function for
injecting a new seed into the given FDT.
Cc: Alistair Francis <alistair.fran...@wdc.com>
Cc: David Gibson <da...@gibson.dropbear.id.au>
Signed-off-by: Jason A. Donenfeld <ja...@zx2c4.com>
---
include/sysemu/device_tree.h | 9 +++++++++
softmmu/device_tree.c | 21 +++++++++++++++++++++
2 files changed, 30 insertions(+)
+void qemu_fdt_randomize_seeds(void *fdt)
+{
+ int noffset, poffset, len;
+ const char *name;
+ uint8_t *data;
+
+ for (noffset = fdt_next_node(fdt, 0, NULL);
+ noffset >= 0;
+ noffset = fdt_next_node(fdt, noffset, NULL)) {
+ for (poffset = fdt_first_property_offset(fdt, noffset);
+ poffset >= 0;
+ poffset = fdt_next_property_offset(fdt, poffset)) {
+ data = (uint8_t *)fdt_getprop_by_offset(fdt, poffset, &name, &len);
Is this non-const cast is safe?
+ if (!data || strcmp(name, "rng-seed"))
+ continue;
+ qemu_guest_getrandom_nofail(data, len);
Shouldn't we read to the stack and fill with fdt_setprop_inplace()?
+ }
+ }
+}