Re: early x86 unseeded randomness

From: Borislav Petkov
Date: Tue Aug 15 2017 - 09:45:26 EST


On Tue, Aug 15, 2017 at 12:47:36PM +0200, Thomas Gleixner wrote:
> 8<-------------------
>
> --- a/arch/x86/kernel/tsc.c
> +++ b/arch/x86/kernel/tsc.c
> @@ -1360,3 +1360,19 @@ unsigned long calibrate_delay_is_known(v
> return 0;
> }
> #endif
> +
> +u64 __init tsc_early_random(void)
> +{
> + u64 uninitialized_var(res);
> + int i;
> +
> + if (!boot_cpu_has(X86_FEATURE_TSC))
> + return res;
> +
> + res ^= rdtsc();
> + for (i = 0; i < BITS_PER_LONG; i++) {
> + res ^= ((rdtsc() & 0x04) >> 2) << i;
> + udelay(2);
> + }
> + return res;
> +}

Something like this is exactly what I was aiming at with my dumb patch.
We could use this for early boot randomness on x86.

Should I turn it into proper patches or you want to?

--
Regards/Gruss,
Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.