Re: [PATCH v2] x86, random: Fix get_random_bytes() warning in x86 start_kernel

From: Prarit Bhargava
Date: Sun Feb 03 2019 - 08:09:47 EST




On 2/1/19 10:02 PM, Theodore Y. Ts'o wrote:
> On Fri, Feb 01, 2019 at 01:08:31PM -0500, Prarit Bhargava wrote:
>> After 43838a23a05f ("random: fix crng_ready() test") early boot calls to
>> get_random_bytes() will warn on x86 because the crng is not initialized.
>> For example,
>>
>> random: get_random_bytes called from start_kernel+0x8e/0x587 with crng_init=0
>>
>> x86 only uses get_random_bytes() for better randomization of the stack
>> canary value so the warning is of no consequence.
>>
>> Test if the crng is initialized before calling get_random_bytes(). If it
>> is not available then attempt to read from the hardware random generator,
>> before finally using the TSC.
>
> If you want to trust the CPU's hardware number generator, there is a
> way to do this already. Simply enable CONFIG_RANDOM_TRUST_CPU, or set
> the boot command line option "random.trust_cpu=on".
>
Ted, the bug I'm trying to fix is the warning:

random: get_random_bytes called from start_kernel+0x8e/0x587 with crng_init=0

during early boot. Even with the kernel parameter the warning appears.


> Also, relying on the TSC for entropy is not something we should be
> recommending.

The current code uses the TSC. It is not something new I'm introducing.

P.

>
> So, NAK.
>
> - Ted
>