rockchip: board: Increase rng-seed size to make it sufficient for modern Linux
Subsystems (3)
PATCH v4 1/1 rockchip: board: Increase rng-seed size to make it sufficient for modern Linux
Increase rng-seed size to make Linux happy and initialize rng pool instantly. Linux 5.19+ requires 32 bytes of entropy to initialize random pool, but u-boot currently provides only 8 bytes.
Linux 5.18 and probably some versions before it used to require 64 bytes. Bump min value to 64 bytes to be on a safe side.
Boot with 8 byte rng-seed (Linux 6.11):
# dmesg | grep crng
[ 12.089286] random: crng init done
Boot with 32 byte rng-seed (Linux 6.11):
# dmesg | grep crng
[ 0.000000] random: crng init doneLinux source references:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/char/random.c?h=v5.19#n551
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/char/random.c?h=v5.18#n236
---
Changes in v4:
- fix typos and code style
Changes in v3:
- reword warning
- increase default rng_seed_size to support older linux as well
- reword commit message
Changes in v2:
- add env config knob rng_seed_size
- add warning for small rng_seed_size
- 12-character commit SHA in Fixes
arch/arm/mach-rockchip/board.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
arch/arm/mach-rockchip/board.c +10 -1
@@ -472,9 +472,18 @@ __weak int misc_init_r(void)__weak int board_rng_seed (struct abuf *buf) {struct udevice *dev; -size_t len =0x8 ; +ulong len =env_get_ulong ("rng_seed_size" ,10 ,64 );u64 *data; +if (len <64 ) { +/* +* rng_seed_size should be at least 32 bytes for Linux 5.19+, +* or 64 for older Linux kernel versions +*/ +log_warning ("Value for rng_seed_size too low (%lu) and likely insufficient for the Linux RNG initialization\n" , + len); + } + data =malloc (len);if (!data) {printf ("Out of memory\n" );
Signature · 1 line
2.34.1
Quoted 13 lines · Alex Shumsky
Increase rng-seed size to make Linux happy and initialize rng pool instantly. Linux 5.19+ requires 32 bytes of entropy to initialize random pool, but u-boot currently provides only 8 bytes.
Linux 5.18 and probably some versions before it used to require 64 bytes. Bump min value to 64 bytes to be on a safe side.Boot with 8 byte rng-seed (Linux 6.11):
# dmesg | grep crng [ 12.089286] random: crng init done Boot with 32 byte rng-seed (Linux 6.11): # dmesg | grep crng [ 0.000000] random: crng init done
Quoted 7 lines
Linux source references:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/char/random.c?h=v5.19#n551
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/char/random.c?h=v5.18#n236Signed-off-by Alex Shumsky <[email protected]>Fixes d2048bafae40 ("rockchip: board: Add board_rng_seed() for all Rockchip devices")Reviewed-by Dragan Simic <[email protected]>
Thanks
Hello Alex,
Quoted 17 lines · Alex Shumsky
Increase rng-seed size to make Linux happy and initialize rng pool instantly. Linux 5.19+ requires 32 bytes of entropy to initialize random pool, but u-boot currently provides only 8 bytes.
Linux 5.18 and probably some versions before it used to require 64 bytes. Bump min value to 64 bytes to be on a safe side.Boot with 8 byte rng-seed (Linux 6.11):
# dmesg | grep crng [ 12.089286] random: crng init done Boot with 32 byte rng-seed (Linux 6.11): # dmesg | grep crng [ 0.000000] random: crng init doneLinux source references:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/char/random.c?h=v5.19#n551
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/char/random.c?h=v5.18#n236
Quoted 8 lines
Signed-off-by Alex Shumsky <[email protected]>Fixes d2048bafae40 ("rockchip: board: Add board_rng_seed() for allRockchip devices")
Reviewed-by Dragan Simic <[email protected]>---
Changes in v4:
- fix typos and code style
The v4 is looking good, thanks!
Quoted 38 lines
Changes in v3:
- reword warning
- increase defaultrng_seed_sizeto support older linux as well
- reword commit messageChanges in v2:
- add env config knobrng_seed_size
- add warning for smallrng_seed_size
- 12-character commit SHA in Fixesarch/arm/mach-rockchip/board.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)arch/arm/mach-rockchip/board.c +10
-1@@ -472,9 +472,18 @@ __weak int misc_init_r(void)__weak int board_rng_seed (struct abuf *buf) {struct udevice *dev; -size_t len =0x8 ; +ulong len =env_get_ulong ("rng_seed_size" ,10 ,64 );u64 *data; +if (len <64 ) { +/* +* rng_seed_size should be at least 32 bytes for Linux 5.19+, +* or 64 for older Linux kernel versions +*/ + log_warning("Value for rng_seed_size too low (%lu) and likely insufficient for the Linux RNG initialization\n", + len); + } + data =malloc (len);if (!data) {
printf("Out of memory\n");
Hi Alex,
Quoted 43 lines · Alex Shumsky
Increase rng-seed size to make Linux happy and initialize rng pool instantly. Linux 5.19+ requires 32 bytes of entropy to initialize random pool, but u-boot currently provides only 8 bytes.
Linux 5.18 and probably some versions before it used to require 64 bytes. Bump min value to 64 bytes to be on a safe side.Boot with 8 byte rng-seed (Linux 6.11):
# dmesg | grep crng [ 12.089286] random: crng init done Boot with 32 byte rng-seed (Linux 6.11): # dmesg | grep crng [ 0.000000] random: crng init doneLinux source references:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/char/random.c?h=v5.19#n551
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/char/random.c?h=v5.18#n236Signed-off-by Alex Shumsky <[email protected]>Fixes d2048bafae40 ("rockchip: board: Add board_rng_seed() for all Rockchip devices")Reviewed-by Dragan Simic <[email protected]>---
Changes in v4:
- fix typos and code styleChanges in v3:
- reword warning
- increase defaultrng_seed_sizeto support older linux as well
- reword commit messageChanges in v2:
- add env config knobrng_seed_size
- add warning for smallrng_seed_size
- 12-character commit SHA in Fixesarch/arm/mach-rockchip/board.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)arch/arm/mach-rockchip/board.c +0
-0
arch/arm/mach-rockchip/board.c __weak int misc_init_r(void) · line 475
Quoted 5 lines
arch/arm/mach-rockchip/board.c +1
-1@@ -472,9 +472,18 @@ __weak int misc_init_r(void)__weak int board_rng_seed (struct abuf *buf) {struct udevice *dev; -size_t len =0x8 ; +ulong len =env_get_ulong ("rng_seed_size" ,10 ,64 );
I'm wondering if we have somewhere some documentation on the environment variables that exist and what they used for because this would be a nice addition. At the very least, we can mention this variable in:
- include/fdt_support.h for the function
- common/Kconfig for the symbol
I'm also a bit torn on the base though, I think the assumed base is generally hex and not dec, so maybe we should rather have that?
Looking good otherwise :)
Cheers,
Quentin
Quoted 5 lines · Quentin Schulz
I'm wondering if we have somewhere some documentation on the environment variables that exist and what they used for because this would be a nice addition. At the very least, we can mention this variable in:
-include/fdt_support.hfor the function
- common/Kconfig for the symbol
I'm not sure if we can expect that all boards can implement the rng_seed_size config knob? Currently rockchip is the only board that implements board_rng_seed.
common/Kconfig BOARD_RNG_SEED description looks rather generic:
It is up to the board code (and more generally the whole BSP) where and how to store (or generate) such a seed, how to ensure a given seed is only used once, how to create a new seed for use on subsequent boots, and whether or not the kernel should account any entropy from the given seed.
Quoted 2 lines
I'm also a bit torn on the base though, I think the assumed base is generally hex and not dec, so maybe we should rather have that?
We need a poll here )
Marek Vasut prefers decimal.
Hi Alex,
Quoted 8 lines · Alex Shumsky
Quoted 5 lines · Quentin Schulz
I'm wondering if we have somewhere some documentation on the environment variables that exist and what they used for because this would be a nice addition. At the very least, we can mention this variable in:
-include/fdt_support.hfor the function
- common/Kconfig for the symbol
Quoted 4 lines
I'm not sure if we can expect that all boards can implement the
rng_seed_sizeconfig knob? Currently rockchip is the only board that implementsboard_rng_seed.
That;s the neat part, we're the only implementation so far, so we kinda get to say what's supposed to be "standard". I think allowing to get a specific size makes sense generally.
Basically, I would like to avoid 1) people not knowing how to change this value 2) avoid having different implementations using a different environment variable.
Tom has just told me on IRC that we have doc/usage/environment.rst for environment variables' documentation, so that would be a good place to put some documentation for this new variable :)
Quoted 8 lines
common/Kconfig
BOARD_RNG_SEEDdescription looks rather generic:It is up to the board code (and more generally the whole BSP) where and how to store (or generate) such a seed, how to ensure a given seed is only used once, how to create a new seed for use on subsequent boots, and whether or not the kernel should account any entropy from the given seed.
Quoted 5 lines
Quoted 2 lines
I'm also a bit torn on the base though, I think the assumed base is generally hex and not dec, so maybe we should rather have that?
We need a poll here )
Marek Vasut prefers decimal.
Hehe, I think this "debate" will never end, I already had it with Simon and Tom a few weeks ago. The "issue" is that once that's decided, we cannot really change it as that would basically break compatibility (new env with old U-Boot or vice-versa). Not a blocker as such, but needs to make sure it's aligned with expectations.
https://docs.u-boot.org/en/latest/usage/cmdline.html#representing-numbers
Cheers,
Quentin
Quoted 56 lines · Quentin Schulz
Hi Alex,
Quoted 43 lines · Alex Shumsky
Increase rng-seed size to make Linux happy and initialize rng pool instantly. Linux 5.19+ requires 32 bytes of entropy to initialize random pool, but u-boot currently provides only 8 bytes.
Linux 5.18 and probably some versions before it used to require 64 bytes. Bump min value to 64 bytes to be on a safe side.Boot with 8 byte rng-seed (Linux 6.11):
# dmesg | grep crng [ 12.089286] random: crng init done Boot with 32 byte rng-seed (Linux 6.11): # dmesg | grep crng [ 0.000000] random: crng init doneLinux source references:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/ tree/drivers/char/random.c?h=v5.19#n551
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/ tree/drivers/char/random.c?h=v5.18#n236Signed-off-by Alex Shumsky <[email protected]>Fixes d2048bafae40 ("rockchip: board: Add board_rng_seed() for all Rockchip devices")Reviewed-by Dragan Simic <[email protected]>---
Changes in v4:
- fix typos and code styleChanges in v3:
- reword warning
- increase defaultrng_seed_sizeto support older linux as well
- reword commit messageChanges in v2:
- add env config knobrng_seed_size
- add warning for smallrng_seed_size
- 12-character commit SHA in Fixes
arch/arm/mach-rockchip/board.c| 11 ++++++++++-1 file changed, 10 insertions(+), 1 deletion(-)arch/arm/mach-rockchip/board.c +0
-0arch/arm/mach-rockchip/board.c __weak int misc_init_r(void) · line 475
Quoted 5 lines
arch/arm/mach-rockchip/board.c +1
-1@@ -472,9 +472,18 @@ __weak int misc_init_r(void) __weak int board_rng_seed(struct abuf *buf) { struct udevice *dev; - size_t len = 0x8; + ulong len = env_get_ulong("rng_seed_size", 10, 64);I'm wondering if we have somewhere some documentation on the environment variables that exist and what they used for because this would be a nice addition. At the very least, we can mention this variable in:
-include/fdt_support.hfor the function
- common/Kconfig for the symbol
Quoted 1 line
I'm also a bit torn on the base though, I think the assumed base is generally hex and not dec, so maybe we should rather have that?
It is a decimal number, similar to e.g. bootcount , hence base 10 .