All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: qemu-devel@nongnu.org, peter.maydell@linaro.org
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>,
	Alistair Francis <alistair.francis@wdc.com>,
	David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH 1/6] device-tree: add re-randomization helper function
Date: Fri, 30 Sep 2022 01:23:34 +0200	[thread overview]
Message-ID: <20220929232339.372813-1-Jason@zx2c4.com> (raw)

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.francis@wdc.com>
Cc: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 include/sysemu/device_tree.h |  9 +++++++++
 softmmu/device_tree.c        | 21 +++++++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/include/sysemu/device_tree.h b/include/sysemu/device_tree.h
index ef060a9759..d552f324b6 100644
--- a/include/sysemu/device_tree.h
+++ b/include/sysemu/device_tree.h
@@ -196,6 +196,15 @@ int qemu_fdt_setprop_sized_cells_from_array(void *fdt,
                                                 qdt_tmp);                 \
     })
 
+
+/**
+ * qemu_fdt_randomize_seeds:
+ * @fdt: device tree blob
+ *
+ * Re-randomize all "rng-seed" properties with new seeds.
+ */
+void qemu_fdt_randomize_seeds(void *fdt);
+
 #define FDT_PCI_RANGE_RELOCATABLE          0x80000000
 #define FDT_PCI_RANGE_PREFETCHABLE         0x40000000
 #define FDT_PCI_RANGE_ALIASED              0x20000000
diff --git a/softmmu/device_tree.c b/softmmu/device_tree.c
index 6ca3fad285..d986c7b7b3 100644
--- a/softmmu/device_tree.c
+++ b/softmmu/device_tree.c
@@ -22,6 +22,7 @@
 #include "qemu/option.h"
 #include "qemu/bswap.h"
 #include "qemu/cutils.h"
+#include "qemu/guest-random.h"
 #include "sysemu/device_tree.h"
 #include "hw/loader.h"
 #include "hw/boards.h"
@@ -643,3 +644,23 @@ out:
     g_free(propcells);
     return ret;
 }
+
+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);
+            if (!data || strcmp(name, "rng-seed"))
+                continue;
+            qemu_guest_getrandom_nofail(data, len);
+        }
+    }
+}
-- 
2.37.3



             reply	other threads:[~2022-09-29 23:25 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-29 23:23 Jason A. Donenfeld [this message]
2022-09-29 23:23 ` [PATCH 2/6] arm: re-randomize rng-seed on reboot Jason A. Donenfeld
2022-09-30  9:11   ` Bin Meng
2022-09-29 23:23 ` [PATCH 3/6] riscv: " Jason A. Donenfeld
2022-09-30  9:11   ` Bin Meng
2022-10-10  2:56   ` Alistair Francis
2022-09-29 23:23 ` [PATCH 4/6] openrisc: " Jason A. Donenfeld
2022-09-30  9:11   ` Bin Meng
2022-09-29 23:23 ` [PATCH 5/6] rx: " Jason A. Donenfeld
2022-09-30  9:11   ` Bin Meng
2022-10-01 13:13   ` Yoshinori Sato
2022-09-29 23:23 ` [PATCH 6/6] mips: " Jason A. Donenfeld
2022-09-30  9:11   ` Bin Meng
2022-09-30  8:44 ` [PATCH 1/6] device-tree: add re-randomization helper function Bin Meng
2022-10-06 13:16 ` Peter Maydell
2022-10-06 13:17   ` Jason A. Donenfeld
2022-10-10 10:54   ` Peter Maydell
2022-10-10 10:58     ` Peter Maydell
2022-10-10 15:20     ` Jason A. Donenfeld
2022-10-10 15:32       ` Peter Maydell
2022-10-10 15:50         ` Jason A. Donenfeld
2022-10-11  6:46         ` Pavel Dovgalyuk
2022-10-11 20:06           ` Jason A. Donenfeld
2022-10-11 20:40             ` Jason A. Donenfeld

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220929232339.372813-1-Jason@zx2c4.com \
    --to=jason@zx2c4.com \
    --cc=alistair.francis@wdc.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.