Re: [PATCH 2/2 v2] lib/vsprintf: Initialize vsprintf's pointer hash once the random core is ready.

From: Jason A. Donenfeld
Date: Fri Jul 29 2022 - 19:29:24 EST


On Fri, Jul 29, 2022 at 05:47:16PM +0200, Sebastian Andrzej Siewior wrote:
> +static void fill_ptr_key_workfn(struct work_struct *work)
> +{
> + int ret;
> +
> + ret = get_random_bytes_wait(&ptr_key, sizeof(ptr_key));

> +static int vsprintf_init_hashval(void)
> +{
> + static DECLARE_WORK(fill_ptr_key_work, fill_ptr_key_workfn);
> +
> + queue_work(system_unbound_wq, &fill_ptr_key_work);
> + return 0;
> +}
> +subsys_initcall(vsprintf_init_hashval)

I'm unsure how good of an idea this is; it'll wind up setting off the
jitter entropy thing very early in init. It's probably a better idea to
just schedule the worker the first time that the RNG is already
initialized by some other means. Check `in_hardirq()` or something if
you're worried about missing the first message.

Jason