Skip to content

Commit 056a68c

Browse files
zx2c4tsbogend
authored andcommitted
mips: allow firmware to pass RNG seed to kernel
Nearly all other firmware environments have some way of passing a RNG seed to initialize the RNG: DTB's rng-seed, EFI's RNG protocol, m68k's bootinfo block, x86's setup_data, and so forth. This adds something similar for MIPS, which will allow various firmware environments, bootloaders, and hypervisors to pass an RNG seed to initialize the kernel's RNG. Signed-off-by: Jason A. Donenfeld <[email protected]> Signed-off-by: Thomas Bogendoerfer <[email protected]>
1 parent 8e6ec6c commit 056a68c

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

arch/mips/kernel/setup.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include <asm/setup.h>
4343
#include <asm/smp-ops.h>
4444
#include <asm/prom.h>
45+
#include <asm/fw/fw.h>
4546

4647
#ifdef CONFIG_MIPS_ELF_APPENDED_DTB
4748
char __section(".appended_dtb") __appended_dtb[0x100000];
@@ -756,6 +757,24 @@ static void __init prefill_possible_map(void)
756757
static inline void prefill_possible_map(void) {}
757758
#endif
758759

760+
static void __init setup_rng_seed(void)
761+
{
762+
char *rng_seed_hex = fw_getenv("rngseed");
763+
u8 rng_seed[512];
764+
size_t len;
765+
766+
if (!rng_seed_hex)
767+
return;
768+
769+
len = min(sizeof(rng_seed), strlen(rng_seed_hex) / 2);
770+
if (hex2bin(rng_seed, rng_seed_hex, len))
771+
return;
772+
773+
add_bootloader_randomness(rng_seed, len);
774+
memzero_explicit(rng_seed, len);
775+
memzero_explicit(rng_seed_hex, len * 2);
776+
}
777+
759778
void __init setup_arch(char **cmdline_p)
760779
{
761780
cpu_probe();
@@ -786,6 +805,8 @@ void __init setup_arch(char **cmdline_p)
786805
paging_init();
787806

788807
memblock_dump_all();
808+
809+
setup_rng_seed();
789810
}
790811

791812
unsigned long kernelsp[NR_CPUS];

0 commit comments

Comments
 (0)