Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F140237005
D32021.id95373.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D32021.id95373.diff
View Options
diff --git a/sys/dev/random/fortuna.c b/sys/dev/random/fortuna.c
--- a/sys/dev/random/fortuna.c
+++ b/sys/dev/random/fortuna.c
@@ -73,6 +73,15 @@
#include <dev/random/uint128.h>
#include <dev/random/fortuna.h>
+/*
+ * FS&K discusses reseeding no more frequently than once every 100ms, but does
+ * not seem to discuss how infrequent is too much. The below places an
+ * arbitrary cap on it to make sure we're deliberately raising the roof.
+ */
+#define FORTUNA_RESEED_INTERVAL SBT_1S
+CTASSERT(FORTUNA_RESEED_INTERVAL >= SBT_1S / 10);
+CTASSERT(FORTUNA_RESEED_INTERVAL <= SBT_1S);
+
/* Defined in FS&K */
#define RANDOM_FORTUNA_NPOOLS 32 /* The number of accumulation pools */
#define RANDOM_FORTUNA_DEFPOOLSIZE 64 /* The default pool size/length for a (re)seed */
@@ -470,7 +479,7 @@
* not block initial seeding (fs_lasttime == 0).
*/
|| (__predict_true(fortuna_state.fs_lasttime != 0) &&
- now - fortuna_state.fs_lasttime <= SBT_1S/10)
+ now - fortuna_state.fs_lasttime <= FORTUNA_RESEED_INTERVAL)
#endif
) {
RANDOM_RESEED_UNLOCK();
diff --git a/sys/dev/random/random_harvestq.h b/sys/dev/random/random_harvestq.h
--- a/sys/dev/random/random_harvestq.h
+++ b/sys/dev/random/random_harvestq.h
@@ -42,8 +42,6 @@
uint8_t he_source; /* origin of the entropy */
};
-void read_rate_increment(u_int);
-
#define RANDOM_HARVEST_INIT_LOCK(x) mtx_init(&harvest_context.hc_mtx, "entropy harvest mutex", NULL, MTX_SPIN)
#define RANDOM_HARVEST_LOCK(x) mtx_lock_spin(&harvest_context.hc_mtx)
#define RANDOM_HARVEST_UNLOCK(x) mtx_unlock_spin(&harvest_context.hc_mtx)
diff --git a/sys/dev/random/random_harvestq.c b/sys/dev/random/random_harvestq.c
--- a/sys/dev/random/random_harvestq.c
+++ b/sys/dev/random/random_harvestq.c
@@ -72,11 +72,20 @@
#define _RANDOM_HARVEST_UMA_OFF (1u << RANDOM_UMA)
#endif
+/*
+ * How much entropy to deliver at 10Hz. We want to end up with at least 256
+ * bits per second per pool. We'll end up collecting 32 bits per feed /
+ * 320 bits per second because it's non-trivial to inject partial bytes at the
+ * moment.
+ */
+#define ENTROPY_PER_POOL roundup2((256 / 10) + 1, 32)
+#define ENTROPY_PER_POOL_WORDS (ENTROPY_PER_POOL / (NBBY * sizeof(uint32_t)))
+_Static_assert(ENTROPY_PER_POOL_WORDS <= HARVESTSIZE,
+ "Collecting too much entropy per pool.");
+
static void random_kthread(void);
static void random_sources_feed(void);
-static u_int read_rate;
-
/*
* Random must initialize much earlier than epoch, but we can initialize the
* epoch code before SMP starts. Prior to SMP, we can safely bypass
@@ -228,10 +237,10 @@
static void
random_sources_feed(void)
{
- uint32_t entropy[HARVESTSIZE];
+ uint32_t entropy[ENTROPY_PER_POOL_WORDS];
struct epoch_tracker et;
struct random_sources *rrs;
- u_int i, n, local_read_rate;
+ u_int i, n;
bool rse_warm;
rse_warm = epoch_inited;
@@ -240,15 +249,10 @@
* Step over all of live entropy sources, and feed their output
* to the system-wide RNG.
*/
- local_read_rate = atomic_readandclear_32(&read_rate);
- /* Perform at least one read per round */
- local_read_rate = MAX(local_read_rate, 1);
- /* But not exceeding RANDOM_KEYSIZE_WORDS */
- local_read_rate = MIN(local_read_rate, RANDOM_KEYSIZE_WORDS);
if (rse_warm)
epoch_enter_preempt(rs_epoch, &et);
CK_LIST_FOREACH(rrs, &source_list, rrs_entries) {
- for (i = 0; i < p_random_alg_context->ra_poolcount*local_read_rate; i++) {
+ for (i = 0; i < p_random_alg_context->ra_poolcount; i++) {
n = rrs->rrs_source->rs_read(entropy, sizeof(entropy));
KASSERT((n <= sizeof(entropy)), ("%s: rs_read returned too much data (%u > %zu)", __func__, n, sizeof(entropy)));
/*
@@ -272,13 +276,6 @@
explicit_bzero(entropy, sizeof(entropy));
}
-void
-read_rate_increment(u_int chunk)
-{
-
- atomic_add_32(&read_rate, chunk);
-}
-
/* ARGSUSED */
static int
random_check_uint_harvestmask(SYSCTL_HANDLER_ARGS)
diff --git a/sys/dev/random/randomdev.c b/sys/dev/random/randomdev.c
--- a/sys/dev/random/randomdev.c
+++ b/sys/dev/random/randomdev.c
@@ -187,7 +187,6 @@
if (error != 0)
return (error);
- read_rate_increment(howmany(uio->uio_resid + 1, sizeof(uint32_t)));
total_read = 0;
/* Easy to deal with the trivial 0 byte case. */
@@ -286,7 +285,6 @@
(void)randomdev_wait_until_seeded(SEEDWAIT_UNINTERRUPTIBLE);
}
- read_rate_increment(roundup2(len, sizeof(uint32_t)));
p_random_alg_context->ra_read(random_buf, len);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 22, 6:00 PM (1 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
27158177
Default Alt Text
D32021.id95373.diff (4 KB)
Attached To
Mode
D32021: kern: random: reduce the rate at which we collect from fast entropy sources
Attached
Detach File
Event Timeline
Log In to Comment