summaryrefslogtreecommitdiffstats
path: root/linux-user/aarch64/cpu_loop.c
diff options
context:
space:
mode:
authorRichard Henderson2019-03-13 03:22:20 +0100
committerRichard Henderson2019-05-22 18:38:54 +0200
commit51977e25f77faae6949c7eb51c86f0319b82a77d (patch)
tree605108fe227d449c4367a6ec8c56f524102a64f4 /linux-user/aarch64/cpu_loop.c
parentlinux-user: Use qemu_guest_getrandom_nofail for AT_RANDOM (diff)
downloadqemu-51977e25f77faae6949c7eb51c86f0319b82a77d.tar.gz
qemu-51977e25f77faae6949c7eb51c86f0319b82a77d.tar.xz
qemu-51977e25f77faae6949c7eb51c86f0319b82a77d.zip
linux-user/aarch64: Use qemu_guest_getrandom for PAUTH keys
Use a better interface for random numbers than rand() * 3. Reviewed-by: Laurent Vivier <lvivier@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'linux-user/aarch64/cpu_loop.c')
-rw-r--r--linux-user/aarch64/cpu_loop.c29
1 files changed, 6 insertions, 23 deletions
diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c
index d75fd9d3e2..cedad39ca0 100644
--- a/linux-user/aarch64/cpu_loop.c
+++ b/linux-user/aarch64/cpu_loop.c
@@ -20,6 +20,7 @@
#include "qemu/osdep.h"
#include "qemu.h"
#include "cpu_loop-common.h"
+#include "qemu/guest-random.h"
#define get_user_code_u32(x, gaddr, env) \
({ abi_long __r = get_user_u32((x), (gaddr)); \
@@ -147,24 +148,6 @@ void cpu_loop(CPUARMState *env)
}
}
-static uint64_t arm_rand64(void)
-{
- int shift = 64 - clz64(RAND_MAX);
- int i, n = 64 / shift + (64 % shift != 0);
- uint64_t ret = 0;
-
- for (i = 0; i < n; i++) {
- ret = (ret << shift) | rand();
- }
- return ret;
-}
-
-void arm_init_pauth_key(ARMPACKey *key)
-{
- key->lo = arm_rand64();
- key->hi = arm_rand64();
-}
-
void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs)
{
ARMCPU *cpu = arm_env_get_cpu(env);
@@ -192,11 +175,11 @@ void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs)
#endif
if (cpu_isar_feature(aa64_pauth, cpu)) {
- arm_init_pauth_key(&env->apia_key);
- arm_init_pauth_key(&env->apib_key);
- arm_init_pauth_key(&env->apda_key);
- arm_init_pauth_key(&env->apdb_key);
- arm_init_pauth_key(&env->apga_key);
+ qemu_guest_getrandom_nofail(&env->apia_key, sizeof(ARMPACKey));
+ qemu_guest_getrandom_nofail(&env->apib_key, sizeof(ARMPACKey));
+ qemu_guest_getrandom_nofail(&env->apda_key, sizeof(ARMPACKey));
+ qemu_guest_getrandom_nofail(&env->apdb_key, sizeof(ARMPACKey));
+ qemu_guest_getrandom_nofail(&env->apga_key, sizeof(ARMPACKey));
}
ts->stack_base = info->start_stack;