Skip to content

Commit 1754abb

Browse files
committed
random: mix build-time latent entropy into pool at init
Prior, the "input_pool_data" array needed no real initialization, and so it was easy to mark it with __latent_entropy to populate it during compile-time. In switching to using a hash function, this required us to specifically initialize it to some specific state, which means we dropped the __latent_entropy attribute. An unfortunate side effect was this meant the pool was no longer seeded using compile-time random data. In order to bring this back, we declare an array in rand_initialize() with __latent_entropy and call mix_pool_bytes() on that at init, which accomplishes the same thing as before. We make this __initconst, so that it doesn't take up space at runtime after init. Fixes: 6e8ec25 ("random: use computational hash for entropy extraction") Reviewed-by: Dominik Brodowski <linux@dominikbrodowski.net> Reviewed-by: Theodore Ts'o <tytso@mit.edu> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
1 parent 0396e46 commit 1754abb

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

drivers/char/random.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,11 @@ int __init rand_initialize(void)
975975
bool arch_init = true;
976976
unsigned long rv;
977977

978+
#if defined(LATENT_ENTROPY_PLUGIN)
979+
static const u8 compiletime_seed[BLAKE2S_BLOCK_SIZE] __initconst __latent_entropy;
980+
_mix_pool_bytes(compiletime_seed, sizeof(compiletime_seed));
981+
#endif
982+
978983
for (i = 0; i < BLAKE2S_BLOCK_SIZE; i += sizeof(rv)) {
979984
if (!arch_get_random_seed_long_early(&rv) &&
980985
!arch_get_random_long_early(&rv)) {

0 commit comments

Comments
 (0)