linux-user: Use qemu_guest_getrandom_nofail for AT_RANDOM

Use a better interface for random numbers than rand * 16.

Reviewed-by: Laurent Vivier <lvivier@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
Richard Henderson 2019-03-12 19:17:53 -07:00
parent a573e9bac6
commit c6a2377fb2

View file

@ -7,6 +7,7 @@
#include "qemu.h" #include "qemu.h"
#include "disas/disas.h" #include "disas/disas.h"
#include "qemu/path.h" #include "qemu/path.h"
#include "qemu/guest-random.h"
#ifdef _ARCH_PPC64 #ifdef _ARCH_PPC64
#undef ARCH_DLINFO #undef ARCH_DLINFO
@ -1883,12 +1884,9 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
} }
/* /*
* Generate 16 random bytes for userspace PRNG seeding (not * Generate 16 random bytes for userspace PRNG seeding.
* cryptically secure but it's not the aim of QEMU).
*/ */
for (i = 0; i < 16; i++) { qemu_guest_getrandom_nofail(k_rand_bytes, sizeof(k_rand_bytes));
k_rand_bytes[i] = rand();
}
if (STACK_GROWS_DOWN) { if (STACK_GROWS_DOWN) {
sp -= 16; sp -= 16;
u_rand_bytes = sp; u_rand_bytes = sp;