diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2022-02-22 16:04:10 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2022-03-03 00:10:28 +0100 |
commit | ffb8cd62334ebc1880108f552bc07b9ac0a2ed33 (patch) | |
tree | a3dcb820fded1a2a0ff98969d24edde2b6606b5f | |
parent | 4eff63d292f714a67834bfbd7cbc4c0fa0b1dd52 (diff) | |
download | wireguard-linux-compat-ffb8cd62334ebc1880108f552bc07b9ac0a2ed33.tar.gz |
qemu: simplify RNG seeding
We don't actualy need to write anything in the pool. Instead, we just
force the total over 128, and we should be good to go for all old
kernels. We also only need this on getrandom() kernels, which simplifies
things too.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r-- | src/tests/qemu/init.c | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/src/tests/qemu/init.c b/src/tests/qemu/init.c index 3e2a237..263c659 100644 --- a/src/tests/qemu/init.c +++ b/src/tests/qemu/init.c @@ -58,27 +58,17 @@ static void print_banner(void) static void seed_rng(void) { - int fd; - struct { - int entropy_count; - int buffer_size; - unsigned char buffer[256]; - } entropy = { - .entropy_count = sizeof(entropy.buffer) * 8, - .buffer_size = sizeof(entropy.buffer), - .buffer = "Adding real entropy is not actually important for these tests. Don't try this at home, kids!" - }; + int bits = 4096, fd; - if (mknod("/dev/urandom", S_IFCHR | 0644, makedev(1, 9))) - panic("mknod(/dev/urandom)"); - fd = open("/dev/urandom", O_WRONLY); + pretty_message("[+] Fake seeding RNG..."); + fd = open("/dev/random", O_WRONLY); if (fd < 0) - panic("open(urandom)"); + panic("open(random)"); for (;;) { - if (getrandom(entropy.buffer, sizeof(entropy.buffer), GRND_NONBLOCK) != -1 || errno != EAGAIN) + if (!getrandom(NULL, 0, GRND_NONBLOCK) || errno == ENOSYS) break; - if (ioctl(fd, RNDADDENTROPY, &entropy) < 0) - panic("ioctl(urandom)"); + if (ioctl(fd, RNDADDTOENTCNT, &bits) < 0) + panic("ioctl(RNDADDTOENTCNT)"); } close(fd); } @@ -274,10 +264,10 @@ static void check_leaks(void) int main(int argc, char *argv[]) { - seed_rng(); ensure_console(); print_banner(); mount_filesystems(); + seed_rng(); kmod_selftests(); enable_logging(); clear_leaks(); |