]> xenbits.xensource.com Git - qemu-xen.git/commitdiff
crypto: Use O_CLOEXEC in qcrypto_random_init
authorRichard Henderson <richard.henderson@linaro.org>
Thu, 14 Mar 2019 04:05:54 +0000 (21:05 -0700)
committerRichard Henderson <richard.henderson@linaro.org>
Wed, 22 May 2019 16:38:54 +0000 (12:38 -0400)
Avoids leaking the /dev/urandom fd into any child processes.

Reviewed-by: Laurent Vivier <lvivier@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
crypto/random-platform.c

index 260b64564d9a0945d14c3f31cfbf3f0caaae489b..6df40744c7085a6bf6d2e74e6bf29168a2fa469f 100644 (file)
@@ -42,9 +42,9 @@ int qcrypto_random_init(Error **errp)
 #else
     /* TBD perhaps also add support for BSD getentropy / Linux
      * getrandom syscalls directly */
-    fd = open("/dev/urandom", O_RDONLY);
+    fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC);
     if (fd == -1 && errno == ENOENT) {
-        fd = open("/dev/random", O_RDONLY);
+        fd = open("/dev/random", O_RDONLY | O_CLOEXEC);
     }
 
     if (fd < 0) {