Re: [PATCH] random: Initialize vsprintf's pointer hash once the random core is ready.
From: Jason A. Donenfeld
Date: Fri Jul 29 2022 - 06:12:21 EST
Hi Sebastian,
On Fri, Jul 29, 2022 at 10:52:58AM +0200, Sebastian Andrzej Siewior wrote:
> --- a/drivers/char/random.c
> +++ b/drivers/char/random.c
> @@ -202,6 +202,7 @@ static void extract_entropy(void *buf, size_t len);
> /* This extracts a new crng key from the input pool. */
> static void crng_reseed(void)
> {
> + bool init_hash_pointer = false;
> unsigned long flags;
> unsigned long next_gen;
> u8 key[CHACHA_KEY_SIZE];
> @@ -221,10 +222,15 @@ static void crng_reseed(void)
> ++next_gen;
> WRITE_ONCE(base_crng.generation, next_gen);
> WRITE_ONCE(base_crng.birth, jiffies);
> - if (!static_branch_likely(&crng_is_ready))
> + if (!static_branch_likely(&crng_is_ready)) {
> crng_init = CRNG_READY;
> + init_hash_pointer = true;
> + }
> spin_unlock_irqrestore(&base_crng.lock, flags);
> memzero_explicit(key, sizeof(key));
> +
> + if (init_hash_pointer)
> + vsprintf_init_hash_pointer();
> }
Gumming up random.c with these sorts of things isn't alright. vsprintf
isn't special in any regard here.
If you can't do this from ordinary context inside of vsprintf, just
launch a workqueue to do it. This is already needed for changing
vsprintf's static branch, so just move the get_random_bytes() call into
there on RT (leaving it alone on non-RT, I guess).
Jason