]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
random-util: Add an environment variable to disable RDRAND.
authorKyle Huey <khuey@kylehuey.com>
Wed, 23 Sep 2020 21:19:09 +0000 (14:19 -0700)
committerLennart Poettering <lennart@poettering.net>
Thu, 24 Sep 2020 07:22:45 +0000 (09:22 +0200)
SYSTEMD_RDRAND=0 will prevent using RDRAND even on systems whose CPUID claims
to support it. All other values have no effect.

Fixes: #17112
docs/ENVIRONMENT.md
src/basic/random-util.c

index ea433a497a71c441cc6885ad2d48bb4cc36473aa..38752c916948690838c47e655d86508f50c50d44 100644 (file)
@@ -80,6 +80,9 @@ All tools:
   honoured on systems built with libxcrypt and is ignored on systems using
   glibc's original, internal crypt() implementation.)
 
+* `$SYSTEMD_RDRAND=0` — if set, the RDRAND instruction will never be used,
+  even if the CPU supports it.
+
 systemctl:
 
 * `$SYSTEMCTL_FORCE_BUS=1` — if set, do not connect to PID1's private D-Bus
index 6eeed9af346cc9037fae96fd240d79efdaa61d6e..2031262389202af45a7187229d807f2b17ba0a1c 100644 (file)
@@ -21,6 +21,7 @@
 #endif
 
 #include "alloc-util.h"
+#include "env-util.h"
 #include "errno-util.h"
 #include "fd-util.h"
 #include "fileio.h"
@@ -116,6 +117,15 @@ int rdrand(unsigned long *ret) {
 #endif
 
                 have_rdrand = !!(ecx & bit_RDRND);
+
+                if (have_rdrand > 0) {
+                        /* Allow disabling use of RDRAND with SYSTEMD_RDRAND=0
+                           If it is unset getenv_bool_secure will return a negative value. */
+                        if (getenv_bool_secure("SYSTEMD_RDRAND") == 0) {
+                                have_rdrand = false;
+                                return -EOPNOTSUPP;
+                        }
+                }
         }
 
         if (have_rdrand == 0)