From 5506feb24282db0a9db5b0e151093e6eb74dd101 Mon Sep 17 00:00:00 2001 From: Sean Christopherson Date: Fri, 26 Jun 2026 14:35:18 -0700 Subject: [PATCH] KVM: selftests: Seed libc's RNG before using it to generate a seed for KVM's pRNG Seed the RNG used by random() using the de facto standard method of srand(time(0)), so that a different seed is actually used in each test run. E.g. without seeding the RNG, literally every test on x86 will use 0x6b8b4567 to seed the KVM RNG. Link: https://patch.msgid.link/20260626213534.3866178-6-seanjc@google.com Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/lib/kvm_util.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index 1016865d3f7a..277166ab1aa9 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -2284,6 +2285,7 @@ void __attribute((constructor)) kvm_selftest_init(void) sigaction(SIGILL, &sig_sa, NULL); sigaction(SIGFPE, &sig_sa, NULL); + srandom(time(0)); kvm_seed_rng(random()); kvm_selftest_arch_init();