mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-06 02:50:49 +09:00
random: set up the NUMA crng instances after the CRNG is fully initialized
commit8ef35c866fupstream. Until the primary_crng is fully initialized, don't initialize the NUMA crng nodes. Otherwise users of /dev/urandom on NUMA systems before the CRNG is fully initialized can get very bad quality randomness. Of course everyone should move to getrandom(2) where this won't be an issue, but there's a lot of legacy code out there. This related to CVE-2018-1108. Reported-by: Jann Horn <jannh@google.com> Fixes:1e7f583af6("random: make /dev/urandom scalable for silly...") Cc: stable@kernel.org # 4.8+ Signed-off-by: Theodore Ts'o <tytso@mit.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
0467c15b09
commit
13eec12cfa
@@ -799,6 +799,32 @@ static void crng_initialize(struct crng_state *crng)
|
||||
crng->init_time = jiffies - CRNG_RESEED_INTERVAL - 1;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_NUMA
|
||||
static void numa_crng_init(void)
|
||||
{
|
||||
int i;
|
||||
struct crng_state *crng;
|
||||
struct crng_state **pool;
|
||||
|
||||
pool = kcalloc(nr_node_ids, sizeof(*pool), GFP_KERNEL|__GFP_NOFAIL);
|
||||
for_each_online_node(i) {
|
||||
crng = kmalloc_node(sizeof(struct crng_state),
|
||||
GFP_KERNEL | __GFP_NOFAIL, i);
|
||||
spin_lock_init(&crng->lock);
|
||||
crng_initialize(crng);
|
||||
pool[i] = crng;
|
||||
}
|
||||
mb();
|
||||
if (cmpxchg(&crng_node_pool, NULL, pool)) {
|
||||
for_each_node(i)
|
||||
kfree(pool[i]);
|
||||
kfree(pool);
|
||||
}
|
||||
}
|
||||
#else
|
||||
static void numa_crng_init(void) {}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* crng_fast_load() can be called by code in the interrupt service
|
||||
* path. So we can't afford to dilly-dally.
|
||||
@@ -957,6 +983,7 @@ static void crng_reseed(struct crng_state *crng, struct entropy_store *r)
|
||||
if (crng == &primary_crng && crng_init < 2) {
|
||||
numa_crng_init();
|
||||
invalidate_batched_entropy();
|
||||
numa_crng_init();
|
||||
crng_init = 2;
|
||||
process_random_ready_list();
|
||||
wake_up_interruptible(&crng_init_wait);
|
||||
|
||||
Reference in New Issue
Block a user