Re: [PATCH] random: defer use of bootloader randomness to random_init()

From: Jason A. Donenfeld
Date: Tue Jun 07 2022 - 10:48:39 EST


Hi Ard,

On Tue, Jun 07, 2022 at 04:19:26PM +0200, Ard Biesheuvel wrote:
> #include <stdio.h>
> #include <stdlib.h>
> #include <sys/random.h>
>
> static unsigned char buf[16];
>
> int main(void)
> {
> for (int i = 0; i < 1000000; i++) {
> if (getrandom(buf, sizeof(buf),
> GRND_RANDOM | GRND_NONBLOCK) < sizeof(buf)) {
> fprintf(stderr, "getrandom() error!\n");
> exit(-1);
> }
> }
> return 0;
> }

I'm actually more worried about the random input flow than the random
output flow and branch misprediction. But more generally, I'd just like
to keep that code as cold as possible after crng init. It's code that's
only used in that one phase and then never again. It can be entirely
disabled.

Anyway, we've got a few solutions now to pick from on the random.c side
of things. I'm going to investigate the arm32 situation next. And then
we'll see what it all looks like.

Jason