Skip to content

Commit

Permalink
random: initialize the last_time field in struct timer_rand_state
Browse files Browse the repository at this point in the history
Since we initialize jiffies to wrap five minutes before boot (see
INITIAL_JIFFIES defined in include/linux/jiffies.h) it's important to
make sure the last_time field is initialized to INITIAL_JIFFIES.
Otherwise, the entropy estimator will overestimate the amount of
entropy resulting from the first call to add_timer_randomness(),
generally by about 8 bits.

Signed-off-by: "Theodore Ts'o" <[email protected]>
  • Loading branch information
tytso committed Nov 3, 2013
1 parent ae9ecd9 commit 644008d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions drivers/char/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,8 @@ struct timer_rand_state {
unsigned dont_count_entropy:1;
};

#define INIT_TIMER_RAND_STATE { INITIAL_JIFFIES, };

/*
* Add device- or boot-specific data to the input and nonblocking
* pools to help initialize them to unique values.
Expand All @@ -750,7 +752,7 @@ void add_device_randomness(const void *buf, unsigned int size)
}
EXPORT_SYMBOL(add_device_randomness);

static struct timer_rand_state input_timer_state;
static struct timer_rand_state input_timer_state = INIT_TIMER_RAND_STATE;

/*
* This function adds entropy to the entropy "pool" by using timing
Expand Down Expand Up @@ -1267,8 +1269,10 @@ void rand_initialize_disk(struct gendisk *disk)
* source.
*/
state = kzalloc(sizeof(struct timer_rand_state), GFP_KERNEL);
if (state)
if (state) {
state->last_time = INITIAL_JIFFIES;
disk->random = state;
}
}
#endif

Expand Down

0 comments on commit 644008d

Please sign in to comment.