All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: f4bug@amsat.org, aurelien@aurel32.net, qemu-devel@nongnu.org,
	tsbogend@alpha.franken.de
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>
Subject: [PATCH qemu] mips/malta: pass RNG seed to to kernel via env var
Date: Fri, 30 Sep 2022 16:05:20 +0200	[thread overview]
Message-ID: <20220930140520.576374-1-Jason@zx2c4.com> (raw)

With the kernel patch linked below, Linux ingests a RNG seed
passed from the hypervisor. So, pass this for the Malta platform, and
reinitialize it on reboot too, so that it's always fresh.

Link: https://lore.kernel.org/linux-mips/20220930140138.575751-1-Jason@zx2c4.com/
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 hw/mips/malta.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/hw/mips/malta.c b/hw/mips/malta.c
index 0e932988e0..9d793b3c17 100644
--- a/hw/mips/malta.c
+++ b/hw/mips/malta.c
@@ -26,6 +26,7 @@
 #include "qemu/units.h"
 #include "qemu/bitops.h"
 #include "qemu/datadir.h"
+#include "qemu/guest-random.h"
 #include "hw/clock.h"
 #include "hw/southbridge/piix.h"
 #include "hw/isa/superio.h"
@@ -1017,6 +1018,17 @@ static void G_GNUC_PRINTF(3, 4) prom_set(uint32_t *prom_buf, int index,
     va_end(ap);
 }
 
+static void reinitialize_rng_seed(void *opaque)
+{
+    char *rng_seed_hex = opaque;
+    uint8_t rng_seed[32];
+
+    qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed));
+    for (size_t i = 0; i < sizeof(rng_seed); ++i) {
+        sprintf(rng_seed_hex + i * 2, "%02x", rng_seed[i]);
+    }
+}
+
 /* Kernel */
 static uint64_t load_kernel(void)
 {
@@ -1028,6 +1040,8 @@ static uint64_t load_kernel(void)
     long prom_size;
     int prom_index = 0;
     uint64_t (*xlate_to_kseg0) (void *opaque, uint64_t addr);
+    uint8_t rng_seed[32];
+    char rng_seed_hex[sizeof(rng_seed) * 2 + 1];
 
 #if TARGET_BIG_ENDIAN
     big_endian = 1;
@@ -1115,9 +1129,20 @@ static uint64_t load_kernel(void)
 
     prom_set(prom_buf, prom_index++, "modetty0");
     prom_set(prom_buf, prom_index++, "38400n8r");
+
+    qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed));
+    for (size_t i = 0; i < sizeof(rng_seed); ++i) {
+        sprintf(rng_seed_hex + i * 2, "%02x", rng_seed[i]);
+    }
+    prom_set(prom_buf, prom_index++, "rngseed");
+    prom_set(prom_buf, prom_index++, "%s", rng_seed_hex);
+
     prom_set(prom_buf, prom_index++, NULL);
 
     rom_add_blob_fixed("prom", prom_buf, prom_size, ENVP_PADDR);
+    qemu_register_reset(reinitialize_rng_seed,
+                        memmem(rom_ptr(ENVP_PADDR, prom_size), prom_size,
+                               rng_seed_hex, sizeof(rng_seed_hex)));
 
     g_free(prom_buf);
     return kernel_entry;
-- 
2.37.3



             reply	other threads:[~2022-09-30 14:19 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-30 14:05 Jason A. Donenfeld [this message]
2022-09-30 15:05 ` [PATCH qemu] mips/malta: pass RNG seed to to kernel via env var Daniel P. Berrangé
2022-09-30 15:06   ` Jason A. Donenfeld
2022-10-01 19:06 ` Jason A. Donenfeld
2022-10-01 19:32   ` Bernhard Reutner-Fischer
2022-10-01 21:33     ` Jason A. Donenfeld
2022-10-03 10:36   ` [PATCH v2] " Jason A. Donenfeld
2022-10-03 18:23     ` Jason A. Donenfeld
2022-10-03 22:36     ` Philippe Mathieu-Daudé
2022-10-03 22:36       ` Philippe Mathieu-Daudé via
2022-10-03 23:07       ` Jason A. Donenfeld
2022-10-04 10:37         ` Jason A. Donenfeld
2022-10-04 10:53           ` Peter Maydell
2022-10-04 10:56             ` Jason A. Donenfeld
2022-10-04 11:00               ` Jason A. Donenfeld
2022-10-04 11:03               ` Peter Maydell
2022-10-04 11:10                 ` Jason A. Donenfeld
2022-10-04 11:39                   ` BALATON Zoltan
2022-10-04 12:08                     ` Jason A. Donenfeld
2022-10-04  8:05       ` Daniel P. Berrangé

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=20220930140520.576374-1-Jason@zx2c4.com \
    --to=jason@zx2c4.com \
    --cc=aurelien@aurel32.net \
    --cc=f4bug@amsat.org \
    --cc=qemu-devel@nongnu.org \
    --cc=tsbogend@alpha.franken.de \
    /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.