diff options
author | Kees Cook <keescook@chromium.org> | 2019-04-19 23:27:05 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2019-04-19 23:27:05 -0400 |
commit | d55535232c3dbde9a523a9d10d68670f5fe5dec3 (patch) | |
tree | 43265cdcfde71ed2fdbd562c17f034c28aab15bc /init | |
parent | eb9d1bf079bb438d1a066d72337092935fc770f6 (diff) |
random: move rand_initialize() earlier
Right now rand_initialize() is run as an early_initcall(), but it only
depends on timekeeping_init() (for mixing ktime_get_real() into the
pools). However, the call to boot_init_stack_canary() for stack canary
initialization runs earlier, which triggers a warning at boot:
random: get_random_bytes called from start_kernel+0x357/0x548 with crng_init=0
Instead, this moves rand_initialize() to after timekeeping_init(), and moves
canary initialization here as well.
Note that this warning may still remain for machines that do not have
UEFI RNG support (which initializes the RNG pools during setup_arch()),
or for x86 machines without RDRAND (or booting without "random.trust=on"
or CONFIG_RANDOM_TRUST_CPU=y).
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'init')
-rw-r--r-- | init/main.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/init/main.c b/init/main.c index 598e278b46f7..55243bc0a067 100644 --- a/init/main.c +++ b/init/main.c | |||
@@ -564,13 +564,6 @@ asmlinkage __visible void __init start_kernel(void) | |||
564 | page_address_init(); | 564 | page_address_init(); |
565 | pr_notice("%s", linux_banner); | 565 | pr_notice("%s", linux_banner); |
566 | setup_arch(&command_line); | 566 | setup_arch(&command_line); |
567 | /* | ||
568 | * Set up the the initial canary and entropy after arch | ||
569 | * and after adding latent and command line entropy. | ||
570 | */ | ||
571 | add_latent_entropy(); | ||
572 | add_device_randomness(command_line, strlen(command_line)); | ||
573 | boot_init_stack_canary(); | ||
574 | mm_init_cpumask(&init_mm); | 567 | mm_init_cpumask(&init_mm); |
575 | setup_command_line(command_line); | 568 | setup_command_line(command_line); |
576 | setup_nr_cpu_ids(); | 569 | setup_nr_cpu_ids(); |
@@ -655,6 +648,20 @@ asmlinkage __visible void __init start_kernel(void) | |||
655 | hrtimers_init(); | 648 | hrtimers_init(); |
656 | softirq_init(); | 649 | softirq_init(); |
657 | timekeeping_init(); | 650 | timekeeping_init(); |
651 | |||
652 | /* | ||
653 | * For best initial stack canary entropy, prepare it after: | ||
654 | * - setup_arch() for any UEFI RNG entropy and boot cmdline access | ||
655 | * - timekeeping_init() for ktime entropy used in rand_initialize() | ||
656 | * - rand_initialize() to get any arch-specific entropy like RDRAND | ||
657 | * - add_latent_entropy() to get any latent entropy | ||
658 | * - adding command line entropy | ||
659 | */ | ||
660 | rand_initialize(); | ||
661 | add_latent_entropy(); | ||
662 | add_device_randomness(command_line, strlen(command_line)); | ||
663 | boot_init_stack_canary(); | ||
664 | |||
658 | time_init(); | 665 | time_init(); |
659 | printk_safe_init(); | 666 | printk_safe_init(); |
660 | perf_event_init(); | 667 | perf_event_init(); |