]> granicus.if.org Git - libevent/commitdiff
Really remove RNG seeds from the stack
authorNick Mathewson <nickm@torproject.org>
Mon, 19 Aug 2013 13:52:29 +0000 (09:52 -0400)
committerNick Mathewson <nickm@torproject.org>
Mon, 19 Aug 2013 14:02:26 +0000 (10:02 -0400)
arc4random.c
evutil.c
util-internal.h

index 7a6c4ff548f9d0aa14b827d51ecb0a4f2f8ae828..39773399a55a7febc0762c989d158b3989bb43bc 100644 (file)
@@ -161,7 +161,7 @@ arc4_seed_win32(void)
        if (!CryptGenRandom(provider, sizeof(buf), buf))
                return -1;
        arc4_addrandom(buf, sizeof(buf));
-       memset(buf, 0, sizeof(buf));
+       evutil_memclear_(buf, sizeof(buf));
        arc4_seeded_ok = 1;
        return 0;
 }
@@ -199,7 +199,7 @@ arc4_seed_sysctl_linux(void)
                return -1;
 
        arc4_addrandom(buf, sizeof(buf));
-       memset(buf, 0, sizeof(buf));
+       evutil_memclear_(buf, sizeof(buf));
        arc4_seeded_ok = 1;
        return 0;
 }
@@ -239,7 +239,7 @@ arc4_seed_sysctl_bsd(void)
                return -1;
 
        arc4_addrandom(buf, sizeof(buf));
-       memset(buf, 0, sizeof(buf));
+       evutil_memclear_(buf, sizeof(buf));
        arc4_seeded_ok = 1;
        return 0;
 }
@@ -284,8 +284,8 @@ arc4_seed_proc_sys_kernel_random_uuid(void)
                arc4_addrandom(entropy, nybbles/2);
                bytes += nybbles/2;
        }
-       memset(entropy, 0, sizeof(entropy));
-       memset(buf, 0, sizeof(buf));
+       evutil_memclear_(entropy, sizeof(entropy));
+       evutil_memclear_(buf, sizeof(buf));
        arc4_seeded_ok = 1;
        return 0;
 }
@@ -309,7 +309,7 @@ static int arc4_seed_urandom_helper_(const char *fname)
        if (n != sizeof(buf))
                return -1;
        arc4_addrandom(buf, sizeof(buf));
-       memset(buf, 0, sizeof(buf));
+       evutil_memclear_(buf, sizeof(buf));
        arc4_seeded_ok = 1;
        return 0;
 }
index b9521ec645a5f90b6470326e00b53f7aa736808c..33445170f64af268a0cf50da64c6b771a55fc9e0 100644 (file)
--- a/evutil.c
+++ b/evutil.c
@@ -2109,6 +2109,18 @@ _evutil_weakrand(void)
 #endif
 }
 
+/**
+ * Volatile pointer to memset: we use this to keep the compiler from
+ * eliminating our call to memset.
+ */
+void * (*volatile evutil_memset_volatile_)(void *, int, size_t) = memset;
+
+void
+evutil_memclear_(void *mem, size_t len)
+{
+       evutil_memset_volatile_(mem, 0, len);
+}
+
 int
 evutil_sockaddr_is_loopback(const struct sockaddr *addr)
 {
index 538f1fe3e330a95cebd0c8a5ff545152147edbbb..01ebc1718f681418e712006f5e57975e758de851 100644 (file)
@@ -320,6 +320,8 @@ HANDLE evutil_load_windows_system_library(const TCHAR *library_name);
 #endif
 #endif
 
+void evutil_memclear_(void *mem, size_t len);
+
 #ifdef __cplusplus
 }
 #endif