* [PATCH v2] rockchip: board: Increase rng-seed size to make it sufficient for modern Linux
@ 2024-10-14 17:53 Alex Shumsky
2024-10-14 18:19 ` Dragan Simic
0 siblings, 1 reply; 7+ messages in thread
From: Alex Shumsky @ 2024-10-14 17:53 UTC (permalink / raw)
To: u-boot
Cc: Alex Shumsky, Ben Wolsieffer, Chris Morgan, Dragan Simic,
Jonas Karlman, Kever Yang, Marek Vasut, Philipp Tomsich,
Philipp Tomsich, Quentin Schulz, Simon Glass, Tom Rini
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
Signed-off-by: Alex Shumsky <alexthreed@gmail.com>
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(-)
diff --git a/arch/arm/mach-rockchip/board.c b/arch/arm/mach-rockchip/board.c
index 3fadf7e412..f9f0d7214c 100644
--- a/arch/arm/mach-rockchip/board.c
+++ b/arch/arm/mach-rockchip/board.c
@@ -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");
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v2] rockchip: board: Increase rng-seed size to make it sufficient for modern Linux
2024-10-14 17:53 [PATCH v2] rockchip: board: Increase rng-seed size to make it sufficient for modern Linux Alex Shumsky
@ 2024-10-14 18:19 ` Dragan Simic
2024-10-14 18:50 ` Alex ThreeD
0 siblings, 1 reply; 7+ messages in thread
From: Dragan Simic @ 2024-10-14 18:19 UTC (permalink / raw)
To: Alex Shumsky
Cc: u-boot, Ben Wolsieffer, Chris Morgan, Jonas Karlman, Kever Yang,
Marek Vasut, Philipp Tomsich, Philipp Tomsich, Quentin Schulz,
Simon Glass, Tom Rini
Hello Alex,
Thanks for the v2. Please see a few comments below.
On 2024-10-14 19:53, Alex Shumsky wrote:
> 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
>
> Signed-off-by: Alex Shumsky <alexthreed@gmail.com>
> 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.
> - 12-character commit SHA in Fixes
>
> arch/arm/mach-rockchip/board.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/arch/arm/mach-rockchip/board.c
> b/arch/arm/mach-rockchip/board.c
> index 3fadf7e412..f9f0d7214c 100644
> --- a/arch/arm/mach-rockchip/board.c
> +++ b/arch/arm/mach-rockchip/board.c
> @@ -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
Shouldn't it be 8 for older kernels?
> + 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"
> + }
> +
> data = malloc(len);
> if (!data) {
> printf("Out of memory\n");
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v2] rockchip: board: Increase rng-seed size to make it sufficient for modern Linux
2024-10-14 18:19 ` Dragan Simic
@ 2024-10-14 18:50 ` Alex ThreeD
2024-10-14 19:00 ` Dragan Simic
0 siblings, 1 reply; 7+ messages in thread
From: Alex ThreeD @ 2024-10-14 18:50 UTC (permalink / raw)
To: Dragan Simic
Cc: u-boot, Ben Wolsieffer, Chris Morgan, Jonas Karlman, Kever Yang,
Marek Vasut, Philipp Tomsich, Philipp Tomsich, Quentin Schulz,
Simon Glass, Tom Rini
On Mon, Oct 14, 2024 at 9:19 PM Dragan Simic <dsimic@manjaro.org> wrote:
> > + // 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.
>
> > + 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.
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v2] rockchip: board: Increase rng-seed size to make it sufficient for modern Linux
2024-10-14 18:50 ` Alex ThreeD
@ 2024-10-14 19:00 ` Dragan Simic
2024-10-14 19:17 ` Alex ThreeD
0 siblings, 1 reply; 7+ messages in thread
From: Dragan Simic @ 2024-10-14 19:00 UTC (permalink / raw)
To: Alex ThreeD
Cc: u-boot, Ben Wolsieffer, Chris Morgan, Jonas Karlman, Kever Yang,
Marek Vasut, Philipp Tomsich, Philipp Tomsich, Quentin Schulz,
Simon Glass, Tom Rini
On 2024-10-14 20:50, Alex ThreeD wrote:
> On Mon, Oct 14, 2024 at 9:19 PM Dragan Simic <dsimic@manjaro.org>
> wrote:
>> > + // 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.
>>
>> > + 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!
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v2] rockchip: board: Increase rng-seed size to make it sufficient for modern Linux
2024-10-14 19:00 ` Dragan Simic
@ 2024-10-14 19:17 ` Alex ThreeD
2024-10-14 19:28 ` Dragan Simic
0 siblings, 1 reply; 7+ messages in thread
From: Alex ThreeD @ 2024-10-14 19:17 UTC (permalink / raw)
To: Dragan Simic
Cc: u-boot, Ben Wolsieffer, Chris Morgan, Jonas Karlman, Kever Yang,
Marek Vasut, Philipp Tomsich, Philipp Tomsich, Quentin Schulz,
Simon Glass, Tom Rini
On Mon, Oct 14, 2024 at 10:00 PM Dragan Simic <dsimic@manjaro.org> wrote:
> 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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] rockchip: board: Increase rng-seed size to make it sufficient for modern Linux
2024-10-14 19:17 ` Alex ThreeD
@ 2024-10-14 19:28 ` Dragan Simic
2024-10-14 20:12 ` Marek Vasut
0 siblings, 1 reply; 7+ messages in thread
From: Dragan Simic @ 2024-10-14 19:28 UTC (permalink / raw)
To: Alex ThreeD
Cc: u-boot, Ben Wolsieffer, Chris Morgan, Jonas Karlman, Kever Yang,
Marek Vasut, Philipp Tomsich, Philipp Tomsich, Quentin Schulz,
Simon Glass, Tom Rini
On 2024-10-14 21:17, Alex ThreeD wrote:
> On Mon, Oct 14, 2024 at 10:00 PM Dragan Simic <dsimic@manjaro.org>
> wrote:
>> 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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] rockchip: board: Increase rng-seed size to make it sufficient for modern Linux
2024-10-14 19:28 ` Dragan Simic
@ 2024-10-14 20:12 ` Marek Vasut
0 siblings, 0 replies; 7+ messages in thread
From: Marek Vasut @ 2024-10-14 20:12 UTC (permalink / raw)
To: Dragan Simic, Alex ThreeD
Cc: u-boot, Ben Wolsieffer, Chris Morgan, Jonas Karlman, Kever Yang,
Philipp Tomsich, Philipp Tomsich, Quentin Schulz, Simon Glass,
Tom Rini
On 10/14/24 9:28 PM, Dragan Simic wrote:
> On 2024-10-14 21:17, Alex ThreeD wrote:
>> On Mon, Oct 14, 2024 at 10:00 PM Dragan Simic <dsimic@manjaro.org> wrote:
>>> 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 !
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-10-14 20:14 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-14 17:53 [PATCH v2] rockchip: board: Increase rng-seed size to make it sufficient for modern Linux Alex Shumsky
2024-10-14 18:19 ` Dragan Simic
2024-10-14 18:50 ` Alex ThreeD
2024-10-14 19:00 ` Dragan Simic
2024-10-14 19:17 ` Alex ThreeD
2024-10-14 19:28 ` Dragan Simic
2024-10-14 20:12 ` Marek Vasut
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.