random(4): Reorder configuration of random source modules
Move fast entropy source registration to the earlier SI_SUB_RANDOM:SI_ORDER_FOURTH and move random_harvestq_prime after that. Relocate the registration routines out of the much later randomdev module and into random_harvestq. This is necessary for the fast random sources to actually register before we perform random_harvestq_prime() early in the kernel boot. No functional change. Reviewed by: delphij, markjm Approved by: secteam(delphij) Differential Revision: https://reviews.freebsd.org/D21308
This commit is contained in:
parent
3a91d1062a
commit
7384206a94
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=351191
@ -137,6 +137,12 @@ darn_modevent(module_t mod, int type, void *unused)
|
||||
return (error);
|
||||
}
|
||||
|
||||
DEV_MODULE(darn, darn_modevent, NULL);
|
||||
static moduledata_t darn_mod = {
|
||||
"darn",
|
||||
darn_modevent,
|
||||
0
|
||||
};
|
||||
|
||||
DECLARE_MODULE(darn, darn_mod, SI_SUB_RANDOM, SI_ORDER_FOURTH);
|
||||
MODULE_VERSION(darn, 1);
|
||||
MODULE_DEPEND(darn, random_device, 1, 1, 1);
|
||||
MODULE_DEPEND(darn, random_harvestq, 1, 1, 1);
|
||||
|
@ -164,6 +164,12 @@ rdrand_modevent(module_t mod, int type, void *unused)
|
||||
return (error);
|
||||
}
|
||||
|
||||
DEV_MODULE(rdrand, rdrand_modevent, NULL);
|
||||
static moduledata_t rdrand_mod = {
|
||||
"rdrand",
|
||||
rdrand_modevent,
|
||||
0
|
||||
};
|
||||
|
||||
DECLARE_MODULE(rdrand, rdrand_mod, SI_SUB_RANDOM, SI_ORDER_FOURTH);
|
||||
MODULE_VERSION(rdrand, 1);
|
||||
MODULE_DEPEND(rdrand, random_device, 1, 1, 1);
|
||||
MODULE_DEPEND(rdrand, random_harvestq, 1, 1, 1);
|
||||
|
@ -146,6 +146,12 @@ nehemiah_modevent(module_t mod, int type, void *unused)
|
||||
return (error);
|
||||
}
|
||||
|
||||
DEV_MODULE(nehemiah, nehemiah_modevent, NULL);
|
||||
static moduledata_t nehemiah_mod = {
|
||||
"nehemiah",
|
||||
nehemiah_modevent,
|
||||
0
|
||||
};
|
||||
|
||||
DECLARE_MODULE(nehemiah, nehemiah_mod, SI_SUB_RANDOM, SI_ORDER_FOURTH);
|
||||
MODULE_VERSION(nehemiah, 1);
|
||||
MODULE_DEPEND(nehemiah, random_device, 1, 1, 1);
|
||||
MODULE_DEPEND(nehemiah, random_harvestq, 1, 1, 1);
|
||||
|
@ -447,7 +447,7 @@ random_harvestq_prime(void *unused __unused)
|
||||
printf("random: no preloaded entropy cache\n");
|
||||
}
|
||||
}
|
||||
SYSINIT(random_device_prime, SI_SUB_RANDOM, SI_ORDER_FOURTH, random_harvestq_prime, NULL);
|
||||
SYSINIT(random_device_prime, SI_SUB_RANDOM, SI_ORDER_MIDDLE, random_harvestq_prime, NULL);
|
||||
|
||||
/* ARGSUSED */
|
||||
static void
|
||||
@ -556,4 +556,60 @@ random_harvest_deregister_source(enum random_entropy_source source)
|
||||
hc_source_mask &= ~(1 << source);
|
||||
}
|
||||
|
||||
void
|
||||
random_source_register(struct random_source *rsource)
|
||||
{
|
||||
struct random_sources *rrs;
|
||||
|
||||
KASSERT(rsource != NULL, ("invalid input to %s", __func__));
|
||||
|
||||
rrs = malloc(sizeof(*rrs), M_ENTROPY, M_WAITOK);
|
||||
rrs->rrs_source = rsource;
|
||||
|
||||
random_harvest_register_source(rsource->rs_source);
|
||||
|
||||
printf("random: registering fast source %s\n", rsource->rs_ident);
|
||||
LIST_INSERT_HEAD(&source_list, rrs, rrs_entries);
|
||||
}
|
||||
|
||||
void
|
||||
random_source_deregister(struct random_source *rsource)
|
||||
{
|
||||
struct random_sources *rrs = NULL;
|
||||
|
||||
KASSERT(rsource != NULL, ("invalid input to %s", __func__));
|
||||
|
||||
random_harvest_deregister_source(rsource->rs_source);
|
||||
|
||||
LIST_FOREACH(rrs, &source_list, rrs_entries)
|
||||
if (rrs->rrs_source == rsource) {
|
||||
LIST_REMOVE(rrs, rrs_entries);
|
||||
break;
|
||||
}
|
||||
if (rrs != NULL)
|
||||
free(rrs, M_ENTROPY);
|
||||
}
|
||||
|
||||
static int
|
||||
random_source_handler(SYSCTL_HANDLER_ARGS)
|
||||
{
|
||||
struct random_sources *rrs;
|
||||
struct sbuf sbuf;
|
||||
int error, count;
|
||||
|
||||
sbuf_new_for_sysctl(&sbuf, NULL, 64, req);
|
||||
count = 0;
|
||||
LIST_FOREACH(rrs, &source_list, rrs_entries) {
|
||||
sbuf_cat(&sbuf, (count++ ? ",'" : "'"));
|
||||
sbuf_cat(&sbuf, rrs->rrs_source->rs_ident);
|
||||
sbuf_cat(&sbuf, "'");
|
||||
}
|
||||
error = sbuf_finish(&sbuf);
|
||||
sbuf_delete(&sbuf);
|
||||
return (error);
|
||||
}
|
||||
SYSCTL_PROC(_kern_random, OID_AUTO, random_sources, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
|
||||
NULL, 0, random_source_handler, "A",
|
||||
"List of active fast entropy sources.");
|
||||
|
||||
MODULE_VERSION(random_harvestq, 1);
|
||||
|
@ -410,62 +410,6 @@ randomdev_ioctl(struct cdev *dev __unused, u_long cmd, caddr_t addr __unused,
|
||||
return (error);
|
||||
}
|
||||
|
||||
void
|
||||
random_source_register(struct random_source *rsource)
|
||||
{
|
||||
struct random_sources *rrs;
|
||||
|
||||
KASSERT(rsource != NULL, ("invalid input to %s", __func__));
|
||||
|
||||
rrs = malloc(sizeof(*rrs), M_ENTROPY, M_WAITOK);
|
||||
rrs->rrs_source = rsource;
|
||||
|
||||
random_harvest_register_source(rsource->rs_source);
|
||||
|
||||
printf("random: registering fast source %s\n", rsource->rs_ident);
|
||||
LIST_INSERT_HEAD(&source_list, rrs, rrs_entries);
|
||||
}
|
||||
|
||||
void
|
||||
random_source_deregister(struct random_source *rsource)
|
||||
{
|
||||
struct random_sources *rrs = NULL;
|
||||
|
||||
KASSERT(rsource != NULL, ("invalid input to %s", __func__));
|
||||
|
||||
random_harvest_deregister_source(rsource->rs_source);
|
||||
|
||||
LIST_FOREACH(rrs, &source_list, rrs_entries)
|
||||
if (rrs->rrs_source == rsource) {
|
||||
LIST_REMOVE(rrs, rrs_entries);
|
||||
break;
|
||||
}
|
||||
if (rrs != NULL)
|
||||
free(rrs, M_ENTROPY);
|
||||
}
|
||||
|
||||
static int
|
||||
random_source_handler(SYSCTL_HANDLER_ARGS)
|
||||
{
|
||||
struct random_sources *rrs;
|
||||
struct sbuf sbuf;
|
||||
int error, count;
|
||||
|
||||
sbuf_new_for_sysctl(&sbuf, NULL, 64, req);
|
||||
count = 0;
|
||||
LIST_FOREACH(rrs, &source_list, rrs_entries) {
|
||||
sbuf_cat(&sbuf, (count++ ? ",'" : "'"));
|
||||
sbuf_cat(&sbuf, rrs->rrs_source->rs_ident);
|
||||
sbuf_cat(&sbuf, "'");
|
||||
}
|
||||
error = sbuf_finish(&sbuf);
|
||||
sbuf_delete(&sbuf);
|
||||
return (error);
|
||||
}
|
||||
SYSCTL_PROC(_kern_random, OID_AUTO, random_sources, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
|
||||
NULL, 0, random_source_handler, "A",
|
||||
"List of active fast entropy sources.");
|
||||
|
||||
/* ARGSUSED */
|
||||
static int
|
||||
randomdev_modevent(module_t mod __unused, int type, void *data __unused)
|
||||
|
Loading…
Reference in New Issue
Block a user