Commit cbe89e5a authored by Jason A. Donenfeld's avatar Jason A. Donenfeld

random: do not use batches when !crng_ready()

It's too hard to keep the batches synchronized, and pointless anyway,
since in !crng_ready(), we're updating the base_crng key really often,
where batching only hurts. So instead, if the crng isn't ready, just
call into get_random_bytes(). At this stage nothing is performance
critical anyhow.

Cc: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: default avatarDominik Brodowski <linux@dominikbrodowski.net>
Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
parent b7b67d13
...@@ -466,10 +466,8 @@ static void crng_pre_init_inject(const void *input, size_t len, bool account) ...@@ -466,10 +466,8 @@ static void crng_pre_init_inject(const void *input, size_t len, bool account)
if (account) { if (account) {
crng_init_cnt += min_t(size_t, len, CRNG_INIT_CNT_THRESH - crng_init_cnt); crng_init_cnt += min_t(size_t, len, CRNG_INIT_CNT_THRESH - crng_init_cnt);
if (crng_init_cnt >= CRNG_INIT_CNT_THRESH) { if (crng_init_cnt >= CRNG_INIT_CNT_THRESH)
++base_crng.generation;
crng_init = 1; crng_init = 1;
}
} }
spin_unlock_irqrestore(&base_crng.lock, flags); spin_unlock_irqrestore(&base_crng.lock, flags);
...@@ -625,6 +623,11 @@ u64 get_random_u64(void) ...@@ -625,6 +623,11 @@ u64 get_random_u64(void)
warn_unseeded_randomness(&previous); warn_unseeded_randomness(&previous);
if (!crng_ready()) {
_get_random_bytes(&ret, sizeof(ret));
return ret;
}
local_lock_irqsave(&batched_entropy_u64.lock, flags); local_lock_irqsave(&batched_entropy_u64.lock, flags);
batch = raw_cpu_ptr(&batched_entropy_u64); batch = raw_cpu_ptr(&batched_entropy_u64);
...@@ -659,6 +662,11 @@ u32 get_random_u32(void) ...@@ -659,6 +662,11 @@ u32 get_random_u32(void)
warn_unseeded_randomness(&previous); warn_unseeded_randomness(&previous);
if (!crng_ready()) {
_get_random_bytes(&ret, sizeof(ret));
return ret;
}
local_lock_irqsave(&batched_entropy_u32.lock, flags); local_lock_irqsave(&batched_entropy_u32.lock, flags);
batch = raw_cpu_ptr(&batched_entropy_u32); batch = raw_cpu_ptr(&batched_entropy_u32);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment