Commit 4af712e8 authored by Hannes Frederic Sowa's avatar Hannes Frederic Sowa Committed by David S. Miller
Browse files

random32: add prandom_reseed_late() and call when nonblocking pool becomes initialized

The Tausworthe PRNG is initialized at late_initcall time. At that time the
entropy pool serving get_random_bytes is not filled sufficiently. This
patch adds an additional reseeding step as soon as the nonblocking pool
gets marked as initialized.

On some machines it might be possible that late_initcall gets called after
the pool has been initialized. In this situation we won't reseed again.

(A call to prandom_seed_late blocks later invocations of early reseed

Joint work with Daniel Borkmann.

Cc: Eric Dumazet <>
Cc: Theodore Ts'o <>
Signed-off-by: default avatarHannes Frederic Sowa <>
Signed-off-by: default avatarDaniel Borkmann <>
Acked-by: default avatar"Theodore Ts'o" <>
Signed-off-by: default avatarDavid S. Miller <>
parent 6d319202
......@@ -603,8 +603,11 @@ static void credit_entropy_bits(struct entropy_store *r, int nbits)
if (!r->initialized && nbits > 0) {
r->entropy_total += nbits;
if (r->entropy_total > 128)
if (r->entropy_total > 128) {
r->initialized = 1;
if (r == &nonblocking_pool)
trace_credit_entropy_bits(r->name, nbits, entropy_count,
......@@ -29,6 +29,7 @@ unsigned long randomize_range(unsigned long start, unsigned long end, unsigned l
u32 prandom_u32(void);
void prandom_bytes(void *buf, int nbytes);
void prandom_seed(u32 seed);
void prandom_reseed_late(void);
u32 prandom_u32_state(struct rnd_state *);
void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
......@@ -200,9 +200,18 @@ static void prandom_start_seed_timer(void)
* Generate better values after random number generator
* is fully initialized.
static int __init prandom_reseed(void)
static void __prandom_reseed(bool late)
int i;
unsigned long flags;
static bool latch = false;
static DEFINE_SPINLOCK(lock);
/* only allow initial seeding (late == false) once */
spin_lock_irqsave(&lock, flags);
if (latch && !late)
goto out;
latch = true;
for_each_possible_cpu(i) {
struct rnd_state *state = &per_cpu(net_rand_state,i);
......@@ -216,6 +225,18 @@ static int __init prandom_reseed(void)
/* mix it in */
spin_unlock_irqrestore(&lock, flags);
void prandom_reseed_late(void)
static int __init prandom_reseed(void)
return 0;
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