Skip to content

Commit a1ee38a

Browse files
zx2c4geertu
authored andcommitted
m68k: virt: Use RNG seed from bootinfo block
Other virt VMs can pass RNG seeds via the "rng-seed" device tree property or via UEFI, but m68k doesn't have either. Instead it has its own bootinfo protocol. So this commit adds support for receiving a RNG seed from it, which will be used at the earliest possible time in boot, just like device tree. Reviewed-by: Laurent Vivier <[email protected]> Signed-off-by: Jason A. Donenfeld <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Geert Uytterhoeven <[email protected]>
1 parent 6f08e51 commit a1ee38a

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

arch/m68k/include/uapi/asm/bootinfo-virt.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
#define BI_VIRT_VIRTIO_BASE 0x8004
1414
#define BI_VIRT_CTRL_BASE 0x8005
1515

16+
/*
17+
* A random seed used to initialize the RNG. Record format:
18+
*
19+
* - length [ 2 bytes, 16-bit big endian ]
20+
* - seed data [ `length` bytes, padded to preserve 2-byte alignment ]
21+
*/
22+
#define BI_VIRT_RNG_SEED 0x8006
23+
1624
#define VIRT_BOOTI_VERSION MK_BI_VERSION(2, 0)
1725

1826
#endif /* _UAPI_ASM_M68K_BOOTINFO_MAC_H */

arch/m68k/virt/config.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <linux/reboot.h>
44
#include <linux/serial_core.h>
5+
#include <linux/random.h>
56
#include <clocksource/timer-goldfish.h>
67

78
#include <asm/bootinfo.h>
@@ -92,6 +93,16 @@ int __init virt_parse_bootinfo(const struct bi_record *record)
9293
data += 4;
9394
virt_bi_data.virtio.irq = be32_to_cpup(data);
9495
break;
96+
case BI_VIRT_RNG_SEED: {
97+
u16 len = be16_to_cpup(data);
98+
add_bootloader_randomness(data + 2, len);
99+
/*
100+
* Zero the data to preserve forward secrecy, and zero the
101+
* length to prevent kexec from using it.
102+
*/
103+
memzero_explicit((void *)data, len + 2);
104+
break;
105+
}
95106
default:
96107
unknown = 1;
97108
break;

0 commit comments

Comments
 (0)