Skip to content

Commit fe6f1a6

Browse files
nuxitytso
authored andcommitted
random: fix CRNG initialization when random.trust_cpu=1
When the system boots with random.trust_cpu=1 it doesn't initialize the per-NUMA CRNGs because it skips the rest of the CRNG startup code. This means that the code from 1e7f583 ("random: make /dev/urandom scalable for silly userspace programs") is not used when random.trust_cpu=1. crash> dmesg | grep random: [ 0.000000] random: get_random_bytes called from start_kernel+0x94/0x530 with crng_init=0 [ 0.314029] random: crng done (trusting CPU's manufacturer) crash> print crng_node_pool $6 = (struct crng_state **) 0x0 After adding the missing call to numa_crng_init() the per-NUMA CRNGs are initialized again: crash> dmesg | grep random: [ 0.000000] random: get_random_bytes called from start_kernel+0x94/0x530 with crng_init=0 [ 0.314031] random: crng done (trusting CPU's manufacturer) crash> print crng_node_pool $1 = (struct crng_state **) 0xffff9a915f4014a0 The call to invalidate_batched_entropy() was also missing. This is important for architectures like PPC and S390 which only have the arch_get_random_seed_* functions. Fixes: 39a8883 ("random: add a config option to trust the CPU's hwrng") Signed-off-by: Jon DeVree <[email protected]> Signed-off-by: Theodore Ts'o <[email protected]>
1 parent d555352 commit fe6f1a6

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

drivers/char/random.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,7 @@ static struct crng_state **crng_node_pool __read_mostly;
772772
#endif
773773

774774
static void invalidate_batched_entropy(void);
775+
static void numa_crng_init(void);
775776

776777
static bool trust_cpu __ro_after_init = IS_ENABLED(CONFIG_RANDOM_TRUST_CPU);
777778
static int __init parse_trust_cpu(char *arg)
@@ -800,7 +801,9 @@ static void crng_initialize(struct crng_state *crng)
800801
}
801802
crng->state[i] ^= rv;
802803
}
803-
if (trust_cpu && arch_init) {
804+
if (trust_cpu && arch_init && crng == &primary_crng) {
805+
invalidate_batched_entropy();
806+
numa_crng_init();
804807
crng_init = 2;
805808
pr_notice("random: crng done (trusting CPU's manufacturer)\n");
806809
}

0 commit comments

Comments
 (0)