[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v7 18/24] hw/misc/bcm2835_rng: Use qemu_guest_getran
From: |
Richard Henderson |
Subject: |
[Qemu-devel] [PATCH v7 18/24] hw/misc/bcm2835_rng: Use qemu_guest_getrandom_nofail |
Date: |
Tue, 14 May 2019 12:16:47 -0700 |
The random number is intended for use by the guest. As such, we should
honor the -seed argument for reproducibility. Use the *_nofail routine
instead of rolling our own error handling locally.
Reviewed-by: Laurent Vivier <address@hidden>
Reviewed-by: Philippe Mathieu-Daudé <address@hidden>
Signed-off-by: Richard Henderson <address@hidden>
---
hw/misc/bcm2835_rng.c | 32 ++++++++++++++------------------
1 file changed, 14 insertions(+), 18 deletions(-)
diff --git a/hw/misc/bcm2835_rng.c b/hw/misc/bcm2835_rng.c
index 4d62143b24..fe59c868f5 100644
--- a/hw/misc/bcm2835_rng.c
+++ b/hw/misc/bcm2835_rng.c
@@ -9,30 +9,26 @@
#include "qemu/osdep.h"
#include "qemu/log.h"
-#include "qapi/error.h"
-#include "crypto/random.h"
+#include "qemu/guest-random.h"
#include "hw/misc/bcm2835_rng.h"
static uint32_t get_random_bytes(void)
{
uint32_t res;
- Error *err = NULL;
- if (qcrypto_random_bytes((uint8_t *)&res, sizeof(res), &err) < 0) {
- /* On failure we don't want to return the guest a non-random
- * value in case they're really using it for cryptographic
- * purposes, so the best we can do is die here.
- * This shouldn't happen unless something's broken.
- * In theory we could implement this device's full FIFO
- * and interrupt semantics and then just stop filling the
- * FIFO. That's a lot of work, though, so we assume any
- * errors are systematic problems and trust that if we didn't
- * fail as the guest inited then we won't fail later on
- * mid-run.
- */
- error_report_err(err);
- exit(1);
- }
+ /*
+ * On failure we don't want to return the guest a non-random
+ * value in case they're really using it for cryptographic
+ * purposes, so the best we can do is die here.
+ * This shouldn't happen unless something's broken.
+ * In theory we could implement this device's full FIFO
+ * and interrupt semantics and then just stop filling the
+ * FIFO. That's a lot of work, though, so we assume any
+ * errors are systematic problems and trust that if we didn't
+ * fail as the guest inited then we won't fail later on
+ * mid-run.
+ */
+ qemu_guest_getrandom_nofail(&res, sizeof(res));
return res;
}
--
2.17.1
- [Qemu-devel] [PATCH v7 09/24] util: Add qemu_guest_getrandom and associated routines, (continued)
- [Qemu-devel] [PATCH v7 09/24] util: Add qemu_guest_getrandom and associated routines, Richard Henderson, 2019/05/14
- [Qemu-devel] [PATCH v7 08/24] ui/vnc: Use gcrypto_random_bytes for start_auth_vnc, Richard Henderson, 2019/05/14
- [Qemu-devel] [PATCH v7 12/24] linux-user: Call qcrypto_random_init if not using -seed, Richard Henderson, 2019/05/14
- [Qemu-devel] [PATCH v7 10/24] cpus: Initialize pseudo-random seeds for all guest cpus, Richard Henderson, 2019/05/14
- [Qemu-devel] [PATCH v7 13/24] linux-user: Use qemu_guest_getrandom_nofail for AT_RANDOM, Richard Henderson, 2019/05/14
- [Qemu-devel] [PATCH v7 11/24] linux-user: Initialize pseudo-random seeds for all guest cpus, Richard Henderson, 2019/05/14
- [Qemu-devel] [PATCH v7 15/24] linux-user: Remove srand call, Richard Henderson, 2019/05/14
- [Qemu-devel] [PATCH v7 14/24] linux-user/aarch64: Use qemu_guest_getrandom for PAUTH keys, Richard Henderson, 2019/05/14
- [Qemu-devel] [PATCH v7 17/24] hw/misc/nrf51_rng: Use qemu_guest_getrandom_nofail, Richard Henderson, 2019/05/14
- [Qemu-devel] [PATCH v7 16/24] aspeed/scu: Use qemu_guest_getrandom_nofail, Richard Henderson, 2019/05/14
- [Qemu-devel] [PATCH v7 18/24] hw/misc/bcm2835_rng: Use qemu_guest_getrandom_nofail,
Richard Henderson <=
- [Qemu-devel] [PATCH v7 19/24] hw/misc/exynos4210_rng: Use qemu_guest_getrandom, Richard Henderson, 2019/05/14
- [Qemu-devel] [PATCH v7 20/24] target/arm: Put all PAC keys into a structure, Richard Henderson, 2019/05/14
- [Qemu-devel] [PATCH v7 21/24] target/arm: Implement ARMv8.5-RNG, Richard Henderson, 2019/05/14
- [Qemu-devel] [PATCH v7 23/24] target/ppc: Use gen_io_start/end around DARN, Richard Henderson, 2019/05/14
- [Qemu-devel] [PATCH v7 22/24] target/ppc: Use qemu_guest_getrandom for DARN, Richard Henderson, 2019/05/14
- [Qemu-devel] [PATCH v7 24/24] target/i386: Implement CPUID_EXT_RDRAND, Richard Henderson, 2019/05/14
- Re: [Qemu-devel] [PATCH v7 00/24] Add qemu_getrandom and ARMv8.5-RNG etc, Markus Armbruster, 2019/05/15