Skip to content

Commit 478f74a

Browse files
committed
Merge tag 'random-5.18-rc1-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/crng/random
Pull random number generator fixes from Jason Donenfeld: - If a hardware random number generator passes a sufficiently large chunk of entropy to random.c during early boot, we now skip the "fast_init" business and let it initialize the RNG. This makes CONFIG_RANDOM_TRUST_BOOTLOADER=y actually useful. - We already have the command line `random.trust_cpu=0/1` option for RDRAND, which let distros enable CONFIG_RANDOM_TRUST_CPU=y while placating concerns of more paranoid users. Now we add `random.trust_bootloader=0/1` so that distros can similarly enable CONFIG_RANDOM_TRUST_BOOTLOADER=y. - Re-add a comment that got removed by accident in the recent revert. - Add the spec-compliant ACPI CID for vmgenid, which Microsoft added to the vmgenid spec at Ard's request during earlier review. - Restore build-time randomness via the latent entropy plugin, which was lost when we transitioned to using a hash function. * tag 'random-5.18-rc1-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/crng/random: random: mix build-time latent entropy into pool at init virt: vmgenid: recognize new CID added by Hyper-V random: re-add removed comment about get_random_{u32,u64} reseeding random: treat bootloader trust toggle the same way as cpu trust toggle random: skip fast_init if hwrng provides large chunk of entropy
2 parents 354b8bf + 1754abb commit 478f74a

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4427,6 +4427,12 @@
44274427
fully seed the kernel's CRNG. Default is controlled
44284428
by CONFIG_RANDOM_TRUST_CPU.
44294429

4430+
random.trust_bootloader={on,off}
4431+
[KNL] Enable or disable trusting the use of a
4432+
seed passed by the bootloader (if available) to
4433+
fully seed the kernel's CRNG. Default is controlled
4434+
by CONFIG_RANDOM_TRUST_BOOTLOADER.
4435+
44304436
randomize_kstack_offset=
44314437
[KNL] Enable or disable kernel stack offset
44324438
randomization, which provides roughly 5 bits of

drivers/char/Kconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ config RANDOM_TRUST_BOOTLOADER
449449
device randomness. Say Y here to assume the entropy provided by the
450450
booloader is trustworthy so it will be added to the kernel's entropy
451451
pool. Otherwise, say N here so it will be regarded as device input that
452-
only mixes the entropy pool.
452+
only mixes the entropy pool. This can also be configured at boot with
453+
"random.trust_bootloader=on/off".
453454

454455
endmenu

drivers/char/random.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,10 @@ static void _warn_unseeded_randomness(const char *func_name, void *caller, void
224224
*
225225
* These interfaces will return the requested number of random bytes
226226
* into the given buffer or as a return value. This is equivalent to
227-
* a read from /dev/urandom. The integer family of functions may be
228-
* higher performance for one-off random integers, because they do a
229-
* bit of buffering.
227+
* a read from /dev/urandom. The u32, u64, int, and long family of
228+
* functions may be higher performance for one-off random integers,
229+
* because they do a bit of buffering and do not invoke reseeding
230+
* until the buffer is emptied.
230231
*
231232
*********************************************************************/
232233

@@ -948,11 +949,17 @@ static bool drain_entropy(void *buf, size_t nbytes, bool force)
948949
**********************************************************************/
949950

950951
static bool trust_cpu __ro_after_init = IS_ENABLED(CONFIG_RANDOM_TRUST_CPU);
952+
static bool trust_bootloader __ro_after_init = IS_ENABLED(CONFIG_RANDOM_TRUST_BOOTLOADER);
951953
static int __init parse_trust_cpu(char *arg)
952954
{
953955
return kstrtobool(arg, &trust_cpu);
954956
}
957+
static int __init parse_trust_bootloader(char *arg)
958+
{
959+
return kstrtobool(arg, &trust_bootloader);
960+
}
955961
early_param("random.trust_cpu", parse_trust_cpu);
962+
early_param("random.trust_bootloader", parse_trust_bootloader);
956963

957964
/*
958965
* The first collection of entropy occurs at system boot while interrupts
@@ -968,6 +975,11 @@ int __init rand_initialize(void)
968975
bool arch_init = true;
969976
unsigned long rv;
970977

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+
971983
for (i = 0; i < BLAKE2S_BLOCK_SIZE; i += sizeof(rv)) {
972984
if (!arch_get_random_seed_long_early(&rv) &&
973985
!arch_get_random_long_early(&rv)) {
@@ -1128,7 +1140,7 @@ void rand_initialize_disk(struct gendisk *disk)
11281140
void add_hwgenerator_randomness(const void *buffer, size_t count,
11291141
size_t entropy)
11301142
{
1131-
if (unlikely(crng_init == 0)) {
1143+
if (unlikely(crng_init == 0 && entropy < POOL_MIN_BITS)) {
11321144
size_t ret = crng_pre_init_inject(buffer, count, true);
11331145
mix_pool_bytes(buffer, ret);
11341146
count -= ret;
@@ -1160,7 +1172,7 @@ EXPORT_SYMBOL_GPL(add_hwgenerator_randomness);
11601172
*/
11611173
void add_bootloader_randomness(const void *buf, size_t size)
11621174
{
1163-
if (IS_ENABLED(CONFIG_RANDOM_TRUST_BOOTLOADER))
1175+
if (trust_bootloader)
11641176
add_hwgenerator_randomness(buf, size, size * 8);
11651177
else
11661178
add_device_randomness(buf, size);

drivers/virt/vmgenid.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ static void vmgenid_notify(struct acpi_device *device, u32 event)
7878
}
7979

8080
static const struct acpi_device_id vmgenid_ids[] = {
81+
{ "VMGENCTR", 0 },
8182
{ "VM_GEN_COUNTER", 0 },
8283
{ }
8384
};

0 commit comments

Comments
 (0)