Skip to content

Commit 40db23e

Browse files
committed
random: make add_timer_randomness() fill the nonblocking pool first
Change add_timer_randomness() so that it directs incoming entropy to the nonblocking pool first if it hasn't been fully initialized yet. This matches the strategy we use in add_interrupt_randomness(), which allows us to push the randomness where we need it the most during when the system is first booting up, so that get_random_bytes() and /dev/urandom become safe to use as soon as possible. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
1 parent f80bbd8 commit 40db23e

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

‎drivers/char/random.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,7 @@ static struct timer_rand_state input_timer_state;
761761
*/
762762
static void add_timer_randomness(struct timer_rand_state *state, unsigned num)
763763
{
764+
struct entropy_store *r;
764765
struct {
765766
long jiffies;
766767
unsigned cycles;
@@ -773,7 +774,8 @@ static void add_timer_randomness(struct timer_rand_state *state, unsigned num)
773774
sample.jiffies = jiffies;
774775
sample.cycles = random_get_entropy();
775776
sample.num = num;
776-
mix_pool_bytes(&input_pool, &sample, sizeof(sample), NULL);
777+
r = nonblocking_pool.initialized ? &input_pool : &nonblocking_pool;
778+
mix_pool_bytes(r, &sample, sizeof(sample), NULL);
777779

778780
/*
779781
* Calculate number of bits of randomness we probably added.
@@ -807,8 +809,7 @@ static void add_timer_randomness(struct timer_rand_state *state, unsigned num)
807809
* Round down by 1 bit on general principles,
808810
* and limit entropy entimate to 12 bits.
809811
*/
810-
credit_entropy_bits(&input_pool,
811-
min_t(int, fls(delta>>1), 11));
812+
credit_entropy_bits(r, min_t(int, fls(delta>>1), 11));
812813
}
813814
preempt_enable();
814815
}

0 commit comments

Comments
 (0)