Module Name: src Committed By: riastradh Date: Mon Aug 26 15:50:26 UTC 2024
Modified Files: src/lib/libc/gen: arc4random.c Log Message: arc4random.c: Fix test program. This isn't wired up anywhere, but let's reduce the bitrot. It was helpful in reminding me that kern.entropy.epoch was, for reasons I can't remember, restricted to privileged access. PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM fork To generate a diff of this commit: cvs rdiff -u -r1.35 -r1.36 src/lib/libc/gen/arc4random.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libc/gen/arc4random.c diff -u src/lib/libc/gen/arc4random.c:1.35 src/lib/libc/gen/arc4random.c:1.36 --- src/lib/libc/gen/arc4random.c:1.35 Mon Aug 26 15:19:22 2024 +++ src/lib/libc/gen/arc4random.c Mon Aug 26 15:50:26 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: arc4random.c,v 1.35 2024/08/26 15:19:22 riastradh Exp $ */ +/* $NetBSD: arc4random.c,v 1.36 2024/08/26 15:50:26 riastradh Exp $ */ /*- * Copyright (c) 2014 The NetBSD Foundation, Inc. @@ -52,7 +52,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: arc4random.c,v 1.35 2024/08/26 15:19:22 riastradh Exp $"); +__RCSID("$NetBSD: arc4random.c,v 1.36 2024/08/26 15:50:26 riastradh Exp $"); #include "namespace.h" #include "reentrant.h" @@ -810,8 +810,18 @@ main(int argc __unused, char **argv __un switch (pid) { case -1: err(1, "fork"); - case 0: - _exit(arc4random_prng_get()->arc4_seeded); + case 0: { + /* + * Verify the epoch has been set to zero by fork. + */ + struct arc4random_prng *prng = NULL; +#ifdef _REENTRANT + prng = thr_getspecific(arc4random_global.thread_key); +#endif + if (prng == NULL) + prng = &arc4random_global.prng; + _exit(prng->arc4_epoch != 0); + } default: rpid = waitpid(pid, &status, 0); if (rpid == -1)