Skip to content

Commit

Permalink
init: call time_init() before rand_initialize()
Browse files Browse the repository at this point in the history
commit fe222a6 upstream.

Currently time_init() is called after rand_initialize(), but
rand_initialize() makes use of the timer on various platforms, and
sometimes this timer needs to be initialized by time_init() first. In
order for random_get_entropy() to not return zero during early boot when
it's potentially used as an entropy source, reverse the order of these
two calls. The block doing random initialization was right before
time_init() before, so changing the order shouldn't have any complicated
effects.

Cc: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Stafford Horne <shorne@gmail.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
zx2c4 authored and gregkh committed May 30, 2022
1 parent ec25e38 commit 7d9eab7
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion init/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -952,11 +952,13 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
hrtimers_init();
softirq_init();
timekeeping_init();
time_init();

/*
* For best initial stack canary entropy, prepare it after:
* - setup_arch() for any UEFI RNG entropy and boot cmdline access
* - timekeeping_init() for ktime entropy used in rand_initialize()
* - time_init() for making random_get_entropy() work on some platforms
* - rand_initialize() to get any arch-specific entropy like RDRAND
* - add_latent_entropy() to get any latent entropy
* - adding command line entropy
Expand All @@ -966,7 +968,6 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
add_device_randomness(command_line, strlen(command_line));
boot_init_stack_canary();

time_init();
perf_event_init();
profile_init();
call_function_init();
Expand Down

0 comments on commit 7d9eab7

Please sign in to comment.