Use RNG to get random behaviour
Subsystems (3)
v3 cover Use RNG to get random behaviour
From: Matthias Brugger <[email protected]>
For now bootp and uuid code use a weak seed for generating random data. U-Boot as support for RNG devices now, so we should change to code to use them if they are present. This will help mitigate issues like seen in CVE-2019-11690.
Changes in v3:
- use IS_ENABLED instead of #if
- use 4 byte for entropy
- use IS_ENABLED instead of #if
Changes in v2:
- fix dm_rng_read() parameters
- add missing include
- fix dm_rng_read() parameters
- add missing include file
Matthias Brugger (2):
lib: uuid: use RNG device if present
net: Use NDRNG device in srand_mac()
lib/uuid.c | 21 ++++++++++++++++++--- net/net_rand.h | 19 ++++++++++++++++++- 2 files changed, 36 insertions(+), 4 deletions(-)
Signature · 1 line
2.29.2
PATCH v3 1/2 lib: uuid: use RNG device if present
From: Matthias Brugger <[email protected]>
When calculating a random UUID we use a weak seed. Use a RNG device if present to increase entropy.
---
Changes in v3:
- use IS_ENABLED instead of #if
- use 4 byte for entropy
Changes in v2:
- fix dm_rng_read() parameters
- add missing include
lib/uuid.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
lib/uuid.c +18 -3
@@ -15,6 +15,8 @@#include <asm/io.h> #include <part_efi.h> #include <malloc.h> +#include <dm/uclass.h> +#include <rng.h> /* * UUID - Universally Unique IDentifier - 128 bits unique number.
@@ -249,9 +251,22 @@ void gen_rand_uuid(unsigned char *uuid_bin) {u32 ptr[4 ];struct uuid *uuid = (struct uuid *)ptr; -int i; - -srand (get_ticks () +rand ()); +int i, ret; +struct udevice *devp; +u32 randv =0 ; + +if (IS_ENABLED (CONFIG_DM_RNG )) { + ret =uclass_get_device (UCLASS_RNG ,0 , &devp); +if (ret) { + ret =dm_rng_read (devp, &randv,sizeof (randv)); +if (ret <0 ) + randv =0 ; + } + } +if (randv) +srand (randv); +else +srand (get_ticks () +rand ());/* Set all fields randomly */ for (i =0 ; i <4 ; i++)
Signature · 1 line
2.29.2
PATCH v3 1/2 lib: uuid: use RNG device if present
Quoted 6 lines · On Fri, 18 Dec 2020 10:28:03 +0100 matthias.bgg at kernel.org wrote:
From: Matthias Brugger <[email protected]>
When calculating a random UUID we use a weak seed. Use a RNG device if present to increase entropy.
Signed-off-by Matthias Brugger <[email protected]>
PATCH v3 1/2 lib: uuid: use RNG device if present
In reply to matthias.bgg at kernel.orgQuoted 7 lines · matthias.bgg at kernel.org
From: Matthias Brugger <[email protected]>
When calculating a random UUID we use a weak seed. Use a RNG device if present to increase entropy.
Signed-off-by Matthias Brugger <[email protected]>Reviewed-by Torsten Duwe <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210119/6e9947ad/attachment.sig>
Re: [PATCH v3 1/2] lib: uuid: use RNG device if present
In reply to matthias.bgg at kernel.orgHi
Quoted 37 lines · On 12/18/20 10:28 AM, [email protected] wrote:
From: Matthias Brugger <[email protected]>
When calculating a random UUID we use a weak seed. Use a RNG device if present to increase entropy.
Signed-off-by Matthias Brugger <[email protected]>---
Changes in v3:
- useIS_ENABLEDinstead of #if
- use 4 byte for entropyChanges in v2:
- fixdm_rng_read()parameters
- add missing includelib/uuid.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)lib/uuid.c +2
-0@@ -15,6 +15,8 @@#include <asm/io.h> #include <part_efi.h> #include <malloc.h> +#include <dm/uclass.h> +#include <rng.h> /* * UUID - Universally Unique IDentifier - 128 bits unique number. @@ -249,9 +251,22 @@ void gen_rand_uuid(unsigned char *uuid_bin) {u32 ptr[4 ];struct uuid *uuid = (struct uuid *)ptr;
lib/uuid.c void gen_rand_uuid(unsigned char *uuid_bin) · line 260
Quoted 10 lines
lib/uuid.c +7
-3-int i; - -srand (get_ticks () +rand ()); +int i, ret; +struct udevice *devp; +u32 randv =0 ; + +if (IS_ENABLED (CONFIG_DM_RNG )) { + ret =uclass_get_device (UCLASS_RNG ,0 , &devp); +if (ret) {
For information, as this patch already merged
here we need to test if ret == 0:
+ if (!ret) {
I push a patch to correct this test:
"lib: uuid: fix the test on RNG device presence"
lib/uuid.c void gen_rand_uuid(unsigned char *uuid_bin) · line 272
Quoted 12 lines
lib/uuid.c +9
-0+ ret =dm_rng_read (devp, &randv,sizeof (randv)); +if (ret <0 ) + randv =0 ; + } + } +if (randv) +srand (randv); +else +srand (get_ticks () +rand ());/* Set all fields randomly */ for (i =0 ; i <4 ; i++)
Regards
Patrick
PATCH v3 2/2 net: Use NDRNG device in srand_mac()
In reply to matthias.bgg at kernel.orgFrom: Matthias Brugger <[email protected]>
When calling srand_mac we use a weak seed dependent on the mac address. If present, use a RNG device instead to incerase entropy.
---
Changes in v3:
- use IS_ENABLED instead of #if
Changes in v2:
- fix dm_rng_read() parameters
- add missing include file
net/net_rand.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
net/net_rand.h +18 -1
@@ -10,6 +10,8 @@#define __NET_RAND_H__#include <common.h> +#include <dm/uclass.h> +#include <rng.h> /* * Return a seed for the PRNG derived from the eth0 MAC address.
@@ -37,7 +39,22 @@ static inline unsigned int seed_mac(void)*/ static inline void srand_mac (void ) { -srand (seed_mac ()); +int ret; +struct udevice *devp; +u32 randv =0 ; + +if (IS_ENABLED (CONFIG_DM_RNG )) { + ret =uclass_get_device (UCLASS_RNG ,0 , &devp); +if (ret) { + ret =dm_rng_read (devp, &randv,sizeof (randv)); +if (ret <0 ) + randv =0 ; + } + } +if (randv) +srand (randv); +else +srand (seed_mac ()); }#endif /* __NET_RAND_H__ */
Signature · 1 line
2.29.2
PATCH v3 2/2 net: Use NDRNG device in srand_mac()
Quoted 6 lines · On Fri, 18 Dec 2020 10:28:04 +0100 matthias.bgg at kernel.org wrote:
From: Matthias Brugger <[email protected]>
When calling
srand_macwe use a weak seed dependent on the mac address. If present, use a RNG device instead to incerase entropy.Signed-off-by Matthias Brugger <[email protected]>
PATCH v3 2/2 net: Use NDRNG device in srand_mac()
In reply to matthias.bgg at kernel.orgQuoted 7 lines · matthias.bgg at kernel.org
From: Matthias Brugger <[email protected]>
When calling
srand_macwe use a weak seed dependent on the mac address. If present, use a RNG device instead to incerase entropy.Signed-off-by Matthias Brugger <[email protected]>Reviewed-by Torsten Duwe <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210119/d441b15f/attachment.sig>