Skip to content

Commit

Permalink
random: do not ignore early device randomness
Browse files Browse the repository at this point in the history
The add_device_randomness() function would ignore incoming bytes if the
crng wasn't ready.  This additionally makes sure to make an early enough
call to add_latent_entropy() to influence the initial stack canary,
which is especially important on non-x86 systems where it stays the same
through the life of the boot.

Link: http://lkml.kernel.org/r/20170626233038.GA48751@beast
Signed-off-by: Kees Cook <[email protected]>
Cc: "Theodore Ts'o" <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Jessica Yu <[email protected]>
Cc: Steven Rostedt (VMware) <[email protected]>
Cc: Viresh Kumar <[email protected]>
Cc: Tejun Heo <[email protected]>
Cc: Prarit Bhargava <[email protected]>
Cc: Lokesh Vutla <[email protected]>
Cc: Nicholas Piggin <[email protected]>
Cc: AKASHI Takahiro <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
kees authored and torvalds committed Jul 12, 2017
1 parent 9380fa6 commit ee7998c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions drivers/char/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,11 @@ void add_device_randomness(const void *buf, unsigned int size)
unsigned long time = random_get_entropy() ^ jiffies;
unsigned long flags;

if (!crng_ready()) {
crng_fast_load(buf, size);
return;
}

trace_add_device_randomness(size, _RET_IP_);
spin_lock_irqsave(&input_pool.lock, flags);
_mix_pool_bytes(&input_pool, buf, size);
Expand Down
1 change: 1 addition & 0 deletions init/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ asmlinkage __visible void __init start_kernel(void)
/*
* Set up the initial canary ASAP:
*/
add_latent_entropy();
boot_init_stack_canary();

cgroup_init_early();
Expand Down

0 comments on commit ee7998c

Please sign in to comment.