Skip to content

Commit d97c68d

Browse files
committed
random: treat bootloader trust toggle the same way as cpu trust toggle
If CONFIG_RANDOM_TRUST_CPU is set, the RNG initializes using RDRAND. But, the user can disable (or enable) this behavior by setting `random.trust_cpu=0/1` on the kernel command line. This allows system builders to do reasonable things while avoiding howls from tinfoil hatters. (Or vice versa.) CONFIG_RANDOM_TRUST_BOOTLOADER is basically the same thing, but regards the seed passed via EFI or device tree, which might come from RDRAND or a TPM or somewhere else. In order to allow distros to more easily enable this while avoiding those same howls (or vice versa), this commit adds the corresponding `random.trust_bootloader=0/1` toggle. Cc: Theodore Ts'o <tytso@mit.edu> Cc: Graham Christensen <graham@grahamc.com> Reviewed-by: Ard Biesheuvel <ardb@kernel.org> Reviewed-by: Dominik Brodowski <linux@dominikbrodowski.net> Link: NixOS/nixpkgs#165355 Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
1 parent af704c8 commit d97c68d

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,11 +948,17 @@ static bool drain_entropy(void *buf, size_t nbytes, bool force)
948948
**********************************************************************/
949949

950950
static bool trust_cpu __ro_after_init = IS_ENABLED(CONFIG_RANDOM_TRUST_CPU);
951+
static bool trust_bootloader __ro_after_init = IS_ENABLED(CONFIG_RANDOM_TRUST_BOOTLOADER);
951952
static int __init parse_trust_cpu(char *arg)
952953
{
953954
return kstrtobool(arg, &trust_cpu);
954955
}
956+
static int __init parse_trust_bootloader(char *arg)
957+
{
958+
return kstrtobool(arg, &trust_bootloader);
959+
}
955960
early_param("random.trust_cpu", parse_trust_cpu);
961+
early_param("random.trust_bootloader", parse_trust_bootloader);
956962

957963
/*
958964
* The first collection of entropy occurs at system boot while interrupts
@@ -1160,7 +1166,7 @@ EXPORT_SYMBOL_GPL(add_hwgenerator_randomness);
11601166
*/
11611167
void add_bootloader_randomness(const void *buf, size_t size)
11621168
{
1163-
if (IS_ENABLED(CONFIG_RANDOM_TRUST_BOOTLOADER))
1169+
if (trust_bootloader)
11641170
add_hwgenerator_randomness(buf, size, size * 8);
11651171
else
11661172
add_device_randomness(buf, size);

0 commit comments

Comments
 (0)