[U-Boot] [PATCH] lib: uuid: Improve randomness of uuid values on RANDOM_UUID=y
Eugeniu Rosca
roscaeugeniu at gmail.com
Fri Apr 26 21:54:58 UTC 2019
The random uuid values (enabled via CONFIG_RANDOM_UUID=y) on our
platform are always the same. Below is consistent on each cold boot:
=> ### reach U-Boot prompt
=> setenv uuid_gpt_misc
=> gpt verify mmc 1 $partitions
Verify GPT: success!
=> print uuid_gpt_misc
uuid_gpt_misc=d117f98e-6f2c-d04b-a5b2-331a19f91cb2
=> setenv uuid_gpt_misc
=> gpt verify mmc 1 $partitions
Verify GPT: success!
=> print uuid_gpt_misc
uuid_gpt_misc=ad5ec4b6-2d9f-8544-9417-fe3bd1c9b1b3
While the uuids do change on every 'gpt {write,verify}' command,
the values appear to be taken from the same pool, in the same order.
As a user, I expect a trully random uuid value in the above example.
Otherwise, system/RFS designers and OS people might assume they have
a reliable/consistent uuid passed by the bootloader, while the truth
is U-Boot simply lacks entropy to generate a random string.
Let's use get_timer() to update the seed, same as done in commit
da384a9d7628 ("net: rename and refactor eth_rand_ethaddr() function").
Signed-off-by: Eugeniu Rosca <erosca at de.adit-jv.com>
---
lib/uuid.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/lib/uuid.c b/lib/uuid.c
index fa20ee39fc32..8a82cb234b88 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -238,6 +238,8 @@ void gen_rand_uuid(unsigned char *uuid_bin)
unsigned int *ptr = (unsigned int *)&uuid;
int i;
+ srand(get_timer(0));
+
/* Set all fields randomly */
for (i = 0; i < sizeof(struct uuid) / sizeof(*ptr); i++)
*(ptr + i) = cpu_to_be32(rand());
--
2.21.0
More information about the U-Boot
mailing list