svn commit: r256399 - projects/random_number_generator/sys/dev/random
Mark Murray
markm at FreeBSD.org
Sat Oct 12 23:15:07 UTC 2013
Author: markm
Date: Sat Oct 12 23:15:06 2013
New Revision: 256399
URL: http://svnweb.freebsd.org/changeset/base/256399
Log:
Fix a problem where the priority order of yarrow,dummy can get reversed
to dummy,yarrow and break the usability of /dev/random.
Fix the name of the tunable to something logical that 'sysctl kern.random'
emits.
Submitted by: des@ (the idea, code by me)
Modified:
projects/random_number_generator/sys/dev/random/dummy_rng.c
projects/random_number_generator/sys/dev/random/random_adaptors.c
projects/random_number_generator/sys/dev/random/randomdev.h
projects/random_number_generator/sys/dev/random/randomdev_soft.c
Modified: projects/random_number_generator/sys/dev/random/dummy_rng.c
==============================================================================
--- projects/random_number_generator/sys/dev/random/dummy_rng.c Sat Oct 12 22:42:18 2013 (r256398)
+++ projects/random_number_generator/sys/dev/random/dummy_rng.c Sat Oct 12 23:15:06 2013 (r256399)
@@ -102,6 +102,7 @@ struct random_adaptor dummy_random = {
.read = (random_read_func_t *)random_null_func,
.reseed = (random_reseed_func_t *)random_null_func,
.seeded = 0, /* This device can never be seeded */
+ .priority = 1, /* Bottom priority, so goes to last position */
};
static int
Modified: projects/random_number_generator/sys/dev/random/random_adaptors.c
==============================================================================
--- projects/random_number_generator/sys/dev/random/random_adaptors.c Sat Oct 12 22:42:18 2013 (r256398)
+++ projects/random_number_generator/sys/dev/random/random_adaptors.c Sat Oct 12 23:15:06 2013 (r256399)
@@ -104,12 +104,13 @@ void
random_adaptor_choose(struct random_adaptor **adaptor)
{
char rngs[128], *token, *cp;
- struct random_adaptors *rpp;
+ struct random_adaptors *rppi, *ramax;
+ unsigned primax;
KASSERT(adaptor != NULL, ("pre-conditions failed"));
*adaptor = NULL;
- if (TUNABLE_STR_FETCH("rngs_want", rngs, sizeof(rngs))) {
+ if (TUNABLE_STR_FETCH("kern.random.active_adaptor", rngs, sizeof(rngs))) {
cp = rngs;
while ((token = strsep(&cp, ",")) != NULL)
@@ -120,16 +121,22 @@ random_adaptor_choose(struct random_adap
" skipping\n", token);
}
+ primax = 0U;
if (*adaptor == NULL) {
/*
- * Fallback to the first thing that's on the list of
- * available RNGs.
+ * Fall back to the highest priority item on the available
+ * RNG list.
*/
sx_slock(&adaptors_lock);
- rpp = LIST_FIRST(&adaptors);
- if (rpp != NULL)
- *adaptor = rpp->rsp;
+ LIST_FOREACH(rppi, &adaptors, entries) {
+ if (rppi->rsp->priority >= primax) {
+ ramax = rppi;
+ primax = rppi->rsp->priority;
+ }
+ }
+ if (ramax != NULL)
+ *adaptor = ramax->rsp;
sx_sunlock(&adaptors_lock);
Modified: projects/random_number_generator/sys/dev/random/randomdev.h
==============================================================================
--- projects/random_number_generator/sys/dev/random/randomdev.h Sat Oct 12 22:42:18 2013 (r256398)
+++ projects/random_number_generator/sys/dev/random/randomdev.h Sat Oct 12 23:15:06 2013 (r256399)
@@ -44,6 +44,7 @@ struct random_adaptor {
struct selinfo rsel;
const char *ident;
int seeded;
+ unsigned priority;
random_init_func_t *init;
random_deinit_func_t *deinit;
random_block_func_t *block;
Modified: projects/random_number_generator/sys/dev/random/randomdev_soft.c
==============================================================================
--- projects/random_number_generator/sys/dev/random/randomdev_soft.c Sat Oct 12 22:42:18 2013 (r256398)
+++ projects/random_number_generator/sys/dev/random/randomdev_soft.c Sat Oct 12 23:15:06 2013 (r256399)
@@ -84,6 +84,7 @@ static struct random_adaptor random_cont
.poll = randomdev_poll,
.reseed = randomdev_flush_reseed,
.seeded = 0, /* This will be seeded during entropy processing */
+ .priority = 90, /* High priority, so top of the list. Fortuna may still win. */
};
#define RANDOM_MODULE_NAME yarrow
#define RANDOM_CSPRNG_NAME "yarrow"
@@ -99,6 +100,7 @@ static struct random_adaptor random_cont
.poll = randomdev_poll,
.reseed = randomdev_flush_reseed,
.seeded = 0, /* This will be excplicitly seeded at startup when secured */
+ .priority = 100, /* High priority, so top of the list. Beat Yarrow. */
};
#define RANDOM_MODULE_NAME fortuna
#define RANDOM_CSPRNG_NAME "fortuna"
More information about the svn-src-projects
mailing list