u-boot/common
Rasmus Villemoes 6dca1d9ad3 fdt_support: add optional board_rng_seed() hook
A recurring theme on LKML is the boot process deadlocking due to some
process blocking waiting for random numbers, while the kernel's
Cryptographic Random Number Generator (crng) is not initalized yet,
but that very blocking means no activity happens that would generate
the entropy necessary to finalize seeding the crng.

This is not a problem on boards that have a good hwrng (when the
kernel is configured to trust it), whether in the CPU or in a TPM or
elsewhere. However, that's far from all boards out there. Moreover,
there are consumers in the kernel that try to obtain random numbers
very early, before the kernel has had any chance to initialize any
hwrng or other peripherals.

Allow a board to provide a board_rng_seed() function, which is
responsible for providing a value to be put into the rng-seed property
under the /chosen node.

The board code is responsible for how to actually obtain those
bytes.

- One possibility is for the board to load a seed "file" from
  somewhere (it need not be a file in a filesystem of course), and
  then ensure that that the same seed file does not get used on
  subsequent boots.

  * One way to do that is to delete the file, or otherwise mark it as
    invalid, then rely on userspace to create a new one, and living
    with the possibility of not finding a seed file during some boots.

  * Another is to use the scheme used by systemd-boot and create a new
    seed file immediately, but in a way that the seed passed to the
    kernel and the new (i.e. next) seed cannot be deduced from each
    other, see the explanation at
    https://lore.kernel.org/lkml/20190929090512.GB13049@gardel-login/
    and the current code at
    https://github.com/systemd/systemd/blob/main/src/boot/efi/random-seed.c

- The board may have an hwrng from which some bytes can be read; while
  the kernel can also do that, doing it in U-Boot and providing a seed
  ensures that even very early users in the kernel get good random
  numbers.

- If the board has a sensor of some sort (temperature, humidity, GPS,
  RTC, whatever), mixing in a reading of that doesn't hurt.

- etc. etc.

These can of course be combined.

The rng-seed property is mixed into the pool used by the linux
kernel's CRNG very early during boot. Whether it then actually
contributes towards the kernel considering the CRNG initialized
depends on whether the kernel has been configured with
CONFIG_RANDOM_TRUST_BOOTLOADER (nowadays overridable via the
random.trust_bootloader command line option). But that's for the BSP
developer to ultimately decide.

So, if the board needs to have all that logic, why not also just have
it do the actual population of /chosen/rng-seed in ft_board_setup(),
which is not that many extra lines of code?

I considered that, but decided handling this logically belongs in
fdt_chosen(). Also, apart from saving the board code from the few
lines of boilerplate, doing it in ft_board_setup() is too late for at
least some use cases. For example, I want to allow the board logic to
decide

  ok, let's pass back this buffer and use that as seed, but also let's
  set random.trust_bootloader=n so no entropy is credited.

This requires the rng-seed handling to happen before bootargs
handling. For example, during the very first boot, the board might not
have a proper seed file, but the board could still return (a hash of)
some CPU serial# or whatnot, so that at least no two boards ever get
the same seed - the kernel always mixes in the value passed in
rng-seed, but if it is not "trusted", the kernel would still go
through the same motions as it would if no rng-seed was passed before
considering its CRNG initialized. I.e., by returning that
unique-to-this-board value and setting random.trust_bootloader=n, the
board would be no worse off than if board_rng_seed() returned nothing
at all.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
2022-09-12 06:41:14 -06:00
..
eeprom SPDX: Convert all of our single license tags to Linux Kernel style 2018-05-07 09:34:12 -04:00
init board_init: Do not reserve MALLOC_F area on stack if non-zero MALLOC_F_ADDR 2022-07-08 12:20:28 -04:00
spl spl: opensbi: convert scratch options to config 2022-08-11 18:46:41 +08:00
autoboot.c env: Move the doc comment to the code 2022-04-07 16:50:53 -04:00
avb_verify.c avb: Fix error when partition not found 2021-03-17 12:50:19 -04:00
bloblist.c common: Drop display_options.h from common header 2022-08-10 13:46:55 -04:00
board_f.c common: Drop display_options.h from common header 2022-08-10 13:46:55 -04:00
board_info.c board-info: Call sysinfo_detect() before sysinfo_get_str() 2021-07-14 16:48:00 -04:00
board_r.c common: Drop display_options.h from common header 2022-08-10 13:46:55 -04:00
bootstage.c bootstage: Show func name for bootstage_mark/error 2022-08-20 18:07:32 -06:00
bouncebuf.c common: Drop log.h from common header 2020-05-18 21:19:18 -04:00
cli.c fdt: Start a test for the fdt command 2022-07-26 02:30:56 -06:00
cli_hush.c cli: slighly more clear error messages 2021-05-17 17:06:42 -04:00
cli_readline.c cli: support bracketed paste 2022-07-18 17:21:49 +02:00
cli_simple.c cli: Support macro processing with a fixed-size buffer 2020-12-04 16:10:01 -05:00
command.c doc: replace @return by Return: 2022-01-19 18:11:34 +01:00
console.c common/console.c: prevent pre-console buffer contents from being added to itself 2022-08-31 12:16:01 -04:00
cros_ec.c common: Drop log.h from common header 2020-05-18 21:19:18 -04:00
ddr_spd.c SPDX: Convert all of our single license tags to Linux Kernel style 2018-05-07 09:34:12 -04:00
dfu.c dfu: add support for the dfu_alt_info reintialization from the flashed script 2021-01-31 14:08:56 +01:00
dlmalloc.c malloc: Annotate allocator for valgrind 2022-04-11 10:00:30 -04:00
dlmalloc.src
edid.c doc: replace @return by Return: 2022-01-19 18:11:34 +01:00
event.c event: Add an event for device tree fixups 2022-08-12 08:17:11 -04:00
exports.c common: Drop asm/global_data.h from common header 2021-02-02 15:33:42 -05:00
fdt_simplefb.c common: add fdt_simplefb_enable_and_mem_rsv function 2021-11-30 16:43:28 +01:00
fdt_support.c fdt_support: add optional board_rng_seed() hook 2022-09-12 06:41:14 -06:00
flash.c Audit <flash.h> inclusion 2022-08-04 16:18:47 -04:00
hash.c doc: replace @return by Return: 2022-01-19 18:11:34 +01:00
hwconfig.c hwconfig: Allow to use restricted env 2022-08-20 18:12:51 -04:00
iomux.c IOMUX: Fix buffer overflow in iomux_replace_device() 2021-04-27 08:05:30 -04:00
iotrace.c common: Drop asm/global_data.h from common header 2021-02-02 15:33:42 -05:00
kallsyms.c global: Convert simple_strtoul() with hex to hextoul() 2021-08-02 13:32:14 -04:00
Kconfig fdt_support: add optional board_rng_seed() hook 2022-09-12 06:41:14 -06:00
kgdb.c common: board_r: drop initr_kgdb wrapper 2022-01-18 08:31:02 -05:00
kgdb_stubs.c common: Drop asm/ptrace.h from common header 2020-05-18 21:19:23 -04:00
lcd.c video: Drop CONFIG_LCD_BMP_RLE8 2022-03-28 20:30:33 +02:00
lcd_console.c WS cleanup: remove trailing empty lines 2021-09-30 08:08:56 -04:00
lcd_console_rotation.c SPDX: Convert all of our single license tags to Linux Kernel style 2018-05-07 09:34:12 -04:00
log.c common: Drop display_options.h from common header 2022-08-10 13:46:55 -04:00
log_console.c log: Allow padding of the function name 2021-07-21 10:27:35 -06:00
log_syslog.c common: Drop asm/global_data.h from common header 2021-02-02 15:33:42 -05:00
main.c efi_loader: split efi_init_obj_list() into two stages 2022-04-23 22:05:41 +02:00
Makefile common: usb: Update logic for usb.o, usb_hub.o and usb_storage.o 2022-06-28 17:11:48 -04:00
malloc_simple.c malloc: Annotate allocator for valgrind 2022-04-11 10:00:30 -04:00
memsize.c common: Drop asm/global_data.h from common header 2021-02-02 15:33:42 -05:00
menu.c bootmenu: factor out the user input handling 2022-05-07 23:17:26 +02:00
miiphyutil.c Convert CONFIG_PHY_RESET_DELAY to Kconfig 2022-03-25 12:01:15 +00:00
qfw.c x86: qemu: move QFW to its own uclass 2021-04-12 17:44:55 -04:00
s_record.c SPDX: Convert all of our single license tags to Linux Kernel style 2018-05-07 09:34:12 -04:00
scp03.c common: SCP03 control (enable and provision of keys) 2021-03-13 13:14:52 -05:00
splash.c common: Drop display_options.h from common header 2022-08-10 13:46:55 -04:00
splash_source.c video: Support virtio devices with the splash screen 2021-12-26 23:33:24 +01:00
stackprot.c Add support for stack-protector 2021-04-20 07:31:12 -04:00
stdio.c video: Drop references to CONFIG_VIDEO et al 2022-03-28 20:17:07 +02:00
system_map.c
update.c Audit <flash.h> inclusion 2022-08-04 16:18:47 -04:00
usb.c Convert CONFIG_USB_MAX_CONTROLLER_COUNT to Kconfig 2022-06-28 17:11:48 -04:00
usb_hub.c usb: hub: introduce HUB_DEBOUNCE_TIMEOUT 2022-07-12 21:59:54 +02:00
usb_kbd.c usb: kbd: allow probing even if usbkbd not in stdin 2022-07-12 21:59:54 +02:00
usb_storage.c bootstd: usb: Add a bootdev driver 2022-04-25 10:00:04 -04:00
xyzModem.c xyz-modem: Allow to cancel transfer also by CTRL+C 2021-09-03 14:32:41 -04:00