Re: [PATCH 1/2] x86/random: Retry on RDSEED failure

Jason A. Donenfeld
2024-02-09T19:53:24Z

Hi Kirill,

On Sat, Feb 3, 2024 at 11:12 AM Jason A. Donenfeld <Jason@zx2c4.com> wrote:
> Yea, actually, I had a pretty similar idea for something like that
> that's very non-invasive, where none of this even touches the RDRAND
> core code, much less random.c. Specifically, we consider "adding some
> extra RDRAND to the pool" like any other driver that wants to add some
> of its own seeds to the pool, with add_device_randomness(), a call that
> lives in various driver code, doesn't influence any entropy readiness
> aspects of random.c, and can safely be sprinkled in any device or
> platform driver.
>
> Specifically what I'm thinking about is something like:
>
> void coco_main_boottime_init_function_somewhere_deep_in_arch_code(void)
> {
> // [...]
> // bring up primary CoCo nuts
> // [...]
>
> /* CoCo requires an explicit RDRAND seed, because the host can make the
> * rest of the system deterministic.
> */
> unsigned long seed[32 / sizeof(long)];
> size_t i, longs;
> for (i = 0; i < ARRAY_SIZE(seed); i += longs) {
> longs = arch_get_random_longs(&seed[i], ARRAY_SIZE(seed) - i);
> /* If RDRAND is being DoS'd, panic, because we can't ensure
> * confidentiality.
> */
> BUG_ON(!longs);
> }
> add_device_randomness(seed, sizeof(seed));
> memzero_explicit(seed, sizeof(seed));
>
> // [...]
> // do other CoCo things
> // [...]
> }
>
> I would have no objection to the CoCo people adding something like this
> and would give it my Ack, but more importantly, my Ack for that doesn't
> even matter, because add_device_randomness() is pretty innocuous.
>
> So Kirill, if nobody else here objects to that approach, and you want to
> implement it in some super minimal way like that, that would be fine
> with me. Or maybe we want to wait for that internal inquiry at Intel to
> return some answers first. But either way, this might be an easy
> approach that doesn't add too much complexity.

I went ahead and implemented this just to have something concrete out there:
https://lore.kernel.org/all/20240209164946.4164052-1-Jason@zx2c4.com/

I probably screwed up some x86 platform conventions/details, but
that's the general idea I had in mind.

Jason