Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern New sysctl kern.entropy.gather=1 to trigger entropy...
details: https://anonhg.NetBSD.org/src/rev/600a68c3b661
branches: trunk
changeset: 1009858:600a68c3b661
user: riastradh <riastradh%NetBSD.org@localhost>
date: Tue May 05 15:31:42 2020 +0000
description:
New sysctl kern.entropy.gather=1 to trigger entropy gathering.
Invokes all on-demand RNG sources. This enables HWRNG driver
developers to use a dtrace probe on rnd_add_data to examine the data
coming out of the HWRNG:
dtrace -n 'fbt::rnd_add_data:entry /args[0]->name == "amdccp0"/ {
...examine buffer args[1] length args[2]...
}'
diffstat:
sys/kern/kern_entropy.c | 38 ++++++++++++++++++++++++++++++++++++--
1 files changed, 36 insertions(+), 2 deletions(-)
diffs (73 lines):
diff -r 640e96133c9b -r 600a68c3b661 sys/kern/kern_entropy.c
--- a/sys/kern/kern_entropy.c Tue May 05 15:25:18 2020 +0000
+++ b/sys/kern/kern_entropy.c Tue May 05 15:31:42 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_entropy.c,v 1.9 2020/05/03 06:33:59 riastradh Exp $ */
+/* $NetBSD: kern_entropy.c,v 1.10 2020/05/05 15:31:42 riastradh Exp $ */
/*-
* Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -77,7 +77,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_entropy.c,v 1.9 2020/05/03 06:33:59 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_entropy.c,v 1.10 2020/05/05 15:31:42 riastradh Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -245,6 +245,7 @@
static void entropy_gather_xc(void *, void *);
static void entropy_notify(void);
static int sysctl_entropy_consolidate(SYSCTLFN_ARGS);
+static int sysctl_entropy_gather(SYSCTLFN_ARGS);
static void filt_entropy_read_detach(struct knote *);
static int filt_entropy_read_event(struct knote *, long);
static void entropy_request(size_t);
@@ -362,6 +363,10 @@
CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT, "consolidate",
SYSCTL_DESCR("Trigger entropy consolidation now"),
sysctl_entropy_consolidate, 0, NULL, 0, CTL_CREATE, CTL_EOL);
+ sysctl_createv(&entropy_sysctllog, 0, &entropy_sysctlroot, NULL,
+ CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT, "gather",
+ SYSCTL_DESCR("Trigger entropy gathering from sources now"),
+ sysctl_entropy_gather, 0, NULL, 0, CTL_CREATE, CTL_EOL);
/* XXX These should maybe not be readable at securelevel>0. */
sysctl_createv(&entropy_sysctllog, 0, &entropy_sysctlroot, NULL,
CTLFLAG_PERMANENT|CTLFLAG_READONLY|CTLFLAG_PRIVATE, CTLTYPE_INT,
@@ -1171,6 +1176,35 @@
}
/*
+ * sysctl -w kern.entropy.gather=1
+ *
+ * Trigger gathering entropy from all on-demand sources, and wait
+ * for synchronous sources (but not asynchronous sources) to
+ * complete. Writable only by superuser.
+ */
+static int
+sysctl_entropy_gather(SYSCTLFN_ARGS)
+{
+ struct sysctlnode node = *rnode;
+ int arg;
+ int error;
+
+ KASSERT(E->stage == ENTROPY_HOT);
+
+ node.sysctl_data = &arg;
+ error = sysctl_lookup(SYSCTLFN_CALL(&node));
+ if (error || newp == NULL)
+ return error;
+ if (arg) {
+ mutex_enter(&E->lock);
+ entropy_request(ENTROPY_CAPACITY);
+ mutex_exit(&E->lock);
+ }
+
+ return 0;
+}
+
+/*
* entropy_extract(buf, len, flags)
*
* Extract len bytes from the global entropy pool into buf.
Home |
Main Index |
Thread Index |
Old Index