Skip to contentSkip to conversation

rockchip: board: Increase rng-seed size to make it sufficient for modern Linux

PATCH Superseded Alex Shumsky 3 participants 7 messages Oct 14, 2024

Subsystems (3)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 rockchip: board: Increase rng-seed size to make it sufficient for modern Linux

Modern Linux requires 32 byte seed to initialize random pool, but u-boot currently provides only 8 bytes. Increase rng-seed size to make Linux happy and initialize rng pool instantly.

Boot with 8 byte rng-seed:

    # dmesg | grep crng
    [   12.089286] random: crng init done
Boot with 32 byte rng-seed:
    # dmesg | grep crng
    [    0.000000] random: crng init done

https://github.com/torvalds/linux/blob/7234e2ea0edd00bfb6bb2159e55878c19885ce68/drivers/char/random.c#L632

Fixes d2048bafae40 ("rockchip: board: Add board_rng_seed() for all Rockchip devices")

---

Changes in v2:
- add env config knob rng_seed_size
- 12-character commit SHA in Fixes

 arch/arm/mach-rockchip/board.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
arch/arm/mach-rockchip/board.c +7 -1
index 3fadf7e412..f9f0d7214c 100644
@@ -472,9 +472,15 @@ __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, 32);
 	u64 *data;
 
+	if (len < 32) {
+		// rng_seed_size should be 32 bytes for Linux 5.19+, or 64 for older Linux'es
+		log_warning("Too small rng_seed_size (%lu). It is likely insufficient to init linux crng\n",
+			    len);
+	}
+
 	data = malloc(len);
 	if (!data) {
 		printf("Out of memory\n");
Signature · 1 line
2.34.1
#1 lore raw

Hello Alex,

Thanks for the v2. Please see a few comments below.

Quoted 13 lines · Alex Shumsky

Modern Linux requires 32 byte seed to initialize random pool, but u-boot currently provides only 8 bytes. Increase rng-seed size to make Linux happy and initialize rng pool instantly.

Boot with 8 byte rng-seed:

    # dmesg | grep crng
    [   12.089286] random: crng init done
Boot with 32 byte rng-seed:
    # dmesg | grep crng
    [    0.000000] random: crng init done

https://github.com/torvalds/linux/blob/7234e2ea0edd00bfb6bb2159e55878c19885ce68/drivers/char/random.c#L632

Quoted 7 lines
Fixes d2048bafae40 ("rockchip: board: Add board_rng_seed() for all

Rockchip devices")
---

Changes in v2:
- add env config knob rng_seed_size

Perhaps the emitted warning should also be mentioned here.

Quoted 19 lines

- 12-character commit SHA in Fixes

 arch/arm/mach-rockchip/board.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
arch/arm/mach-rockchip/board.c +3 -1
index 3fadf7e412..f9f0d7214c 100644
@@ -472,9 +472,15 @@ __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, 32);
 	u64 *data;
 
+	if (len < 32) {
+		// rng_seed_size should be 32 bytes for Linux 5.19+, or 64 for older 
Quoted 1 line

Linux'es

Shouldn't it be 8 for older kernels?

arch/arm/mach-rockchip/board.c __weak int misc_init_r(void) · line 481

Quoted 3 lines
arch/arm/mach-rockchip/board.c +1 -0
+		log_warning("Too small rng_seed_size (%lu). It is likely

insufficient to init linux crng\n",

arch/arm/mach-rockchip/board.c +1 -0
+			    len);

Perhaps this would read better:

"Value for rng_seed_size too low (%lu) and likely insufficient for the Linux RNG initialization"

Quoted 5 lines
arch/arm/mach-rockchip/board.c +2 -0
+	}
+
 	data = malloc(len);
 	if (!data) {
 		printf("Out of memory\n");
#2 lore raw
Quoted 4 lines · Dragan Simic
Quoted 2 lines

+ // rng_seed_size should be 32 bytes for Linux 5.19+, or 64 for older
Linux'es

Shouldn't it be 8 for older kernels?

Looking into source code I would say Linux 5.17 requires 64 bytes to init crng. 8 bytes rng_seed should help somehow, but It will not init crng instantly. Maybe some even Linux required only 8 bytes but I doubt so.
8 bytes was too small for cryptographic PRNG yet 20 years ago.

Quoted 9 lines
Quoted 4 lines

+ log_warning("Too small rng_seed_size (%lu). It is likely
insufficient to init linux crng\n",
+ len);

Perhaps this would read better:

"Value for rng_seed_size too low (%lu) and likely insufficient for the Linux RNG initialization"

Thanks, I will apply It in v3.

#3 lore raw
Quoted 10 lines · Alex ThreeD
Quoted 4 lines · Dragan Simic
Quoted 2 lines

+ // rng_seed_size should be 32 bytes for Linux 5.19+, or 64 for older
Linux'es

Shouldn't it be 8 for older kernels?

Looking into source code I would say Linux 5.17 requires 64 bytes to init crng. 8 bytes rng_seed should help somehow, but It will not init crng instantly. Maybe some even Linux required only 8 bytes but I doubt so.
8 bytes was too small for cryptographic PRNG yet 20 years ago.

To sum up the replies from Marek, the lower limit should be 64.

Quoted 11 lines
Quoted 9 lines
Quoted 4 lines

+ log_warning("Too small rng_seed_size (%lu). It is likely
insufficient to init linux crng\n",
+ len);

Perhaps this would read better:

"Value for rng_seed_size too low (%lu) and likely insufficient for the Linux RNG initialization"

Thanks, I will apply It in v3.

Great, thanks!

#4 lore raw
Quoted 1 line · Dragan Simic

To sum up the replies from Marek, the lower limit should be 64.

64 by default, warning for custom values less than 32. Right? Since 32 bytes is sufficient for kernels released in the last 2 years.

#5 lore raw
Quoted 5 lines · Alex ThreeD
Quoted 1 line · Dragan Simic

To sum up the replies from Marek, the lower limit should be 64.

64 by default, warning for custom values less than 32. Right? Since 32 bytes is sufficient for kernels released in the last 2 years.

I'd keep both the default and the warning threshold at 64. I think it's much safer that way.

#6 lore raw
Quoted 9 lines · Dragan Simic
Quoted 5 lines · Alex ThreeD
Quoted 1 line · Dragan Simic

To sum up the replies from Marek, the lower limit should be 64.

64 by default, warning for custom values less than 32. Right? Since 32 bytes is sufficient for kernels released in the last 2 years.

I'd keep both the default and the warning threshold at 64.  I think it's much safer that way.

Sounds good to me, thanks !