Skip to contentSkip to conversation

utils/genrandconfig: use high quality random for KCONFIG_SEED

PATCH Applied James Hilliard 2 participants 2 messages May 3, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 utils/genrandconfig: use high quality random for KCONFIG_SEED

Internally genrandconfig will use gettimeofday when generating a KCONFIG_SEED, since autobuild-run executes genrandconfig at the same time for multiple autobuilder runners this could potentially result in the same KCONFIG_SEED being generated for those test runs started at the same time.

To ensure this doesn't happen set the KCONFIG_SEED using the urandom entropy source.

---
 utils/genrandconfig | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
utils/genrandconfig +8 -3
index 70af84f002..8ed2783a6d 100755
@@ -18,6 +18,7 @@
 
 # This script generates a random configuration for testing Buildroot.
 
+from binascii import hexlify
 import contextlib
 import csv
 import os
@@ -605,9 +606,13 @@ def gen_config(args):
                   file=sys.stderr)
             return 1
         bounded_loop -= 1
-        subprocess.check_call(["make", "O=%s" % args.outputdir, "-C", args.buildrootdir,
-                               "KCONFIG_PROBABILITY=%d" % randint(1, 20),
-                               "randpackageconfig" if args.toolchains_csv else "randconfig"])
+        make_rand = [
+            "make", "O=%s" % args.outputdir, "-C", args.buildrootdir,
+            "KCONFIG_SEED=0x%s" % hexlify(os.urandom(4)).decode("ascii").upper(),
+            "KCONFIG_PROBABILITY=%d" % randint(1, 20),
+            "randpackageconfig" if args.toolchains_csv else "randconfig"
+        ]
+        subprocess.check_call(make_rand)
 
         if fixup_config(sysinfo, configfile):
             break
Signature · 6 lines
2.25.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw
Quoted 10 lines · James Hilliard

Internally genrandconfig will use gettimeofday when generating a KCONFIG_SEED, since autobuild-run executes genrandconfig at the same time for multiple autobuilder runners this could potentially result in the same KCONFIG_SEED being generated for those test runs started at the same time.

To ensure this doesn't happen set the KCONFIG_SEED using the urandom entropy source.

Applied to master, thanks.

Regards,
Arnout

Quoted 23 lines
---
  utils/genrandconfig | 11 ++++++++---
  1 file changed, 8 insertions(+), 3 deletions(-)
utils/genrandconfig +1 -3
index 70af84f002..8ed2783a6d 100755
@@ -18,6 +18,7 @@
 
  # This script generates a random configuration for testing Buildroot.
 
+from binascii import hexlify
  import contextlib
  import csv
  import os
@@ -605,9 +606,13 @@ def gen_config(args):
                    file=sys.stderr)
              return 1
          bounded_loop -= 1
-        subprocess.check_call(["make", "O=%s" % args.outputdir, "-C", args.buildrootdir,
-                               "KCONFIG_PROBABILITY=%d" % randint(1, 20),
-                               "randpackageconfig" if args.toolchains_csv else "randconfig"])

utils/genrandconfig def gen_config(args): · line 618

Quoted 10 lines
utils/genrandconfig +7 -0
+        make_rand = [
+            "make", "O=%s" % args.outputdir, "-C", args.buildrootdir,
+            "KCONFIG_SEED=0x%s" % hexlify(os.urandom(4)).decode("ascii").upper(),
+            "KCONFIG_PROBABILITY=%d" % randint(1, 20),
+            "randpackageconfig" if args.toolchains_csv else "randconfig"
+        ]
+        subprocess.check_call(make_rand)
 
          if fixup_config(sysinfo, configfile):
              break

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot