Module Name: src
Committed By: riastradh
Date: Thu May 7 19:13:38 UTC 2020
Modified Files:
src/sbin/rndctl: rndctl.c
Log Message:
Trigger entropy consolidation before saving seed.
This way, whenever /etc/security runs infrequently (daily), or the
operator manually issues rndctl -S, we ensure that all samples taken
during the entire boot are hashed together in the seed for the next
boot.
This should be infrequent enough that it's unlikely to enable the
iterative-guessing attacks that we try to mitigate by not frequently
consolidating entropy.
To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/sbin/rndctl/rndctl.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sbin/rndctl/rndctl.c
diff -u src/sbin/rndctl/rndctl.c:1.35 src/sbin/rndctl/rndctl.c:1.36
--- src/sbin/rndctl/rndctl.c:1.35 Thu May 7 19:12:45 2020
+++ src/sbin/rndctl/rndctl.c Thu May 7 19:13:38 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: rndctl.c,v 1.35 2020/05/07 19:12:45 riastradh Exp $ */
+/* $NetBSD: rndctl.c,v 1.36 2020/05/07 19:13:38 riastradh Exp $ */
/*-
* Copyright (c) 1997 Michael Graff.
@@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: rndctl.c,v 1.35 2020/05/07 19:12:45 riastradh Exp $");
+__RCSID("$NetBSD: rndctl.c,v 1.36 2020/05/07 19:13:38 riastradh Exp $");
#endif
#include <sys/param.h>
@@ -40,6 +40,7 @@ __RCSID("$NetBSD: rndctl.c,v 1.35 2020/0
#include <sys/ioctl.h>
#include <sys/rndio.h>
#include <sys/sha3.h>
+#include <sys/sysctl.h>
#include <err.h>
#include <errno.h>
@@ -251,6 +252,11 @@ do_save(const char *filename)
char tmp[PATH_MAX];
int fd_seed;
+ /* Consolidate any pending samples. */
+ if (sysctlbyname("kern.entropy.consolidate", NULL, NULL,
+ (const int[]){1}, sizeof(int)) == -1)
+ warn("consolidate entropy");
+
/* Format the temporary file name. */
if (snprintf(tmp, sizeof tmp, "%s.tmp", filename) >= PATH_MAX)
errx(1, "path too long");
@@ -367,6 +373,11 @@ do_load(const char *filename)
/*
* 2. Feed the old seed into the kernel.
+ *
+ * This also has the effect of consolidating pending samples,
+ * whether or not there are enough samples from sources deemed
+ * to have full entropy, so that the updated seed will
+ * incorporate them.
*/
rd.len = MIN(sizeof(rd.data), sizeof(rs.data));
rd.entropy = rs.entropy;