summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
authoreric <eric@openbsd.org>2013-03-26 17:29:04 +0000
committereric <eric@openbsd.org>2013-03-26 17:29:04 +0000
commit7a1b2c1db6b2b6896c17a6a661aaa866c97d6872 (patch)
tree5c25e56273f4e2cfcdd8061686866994b398535e /lib/libc
parentupdate define name to reflect fact this is openbsd. kill dead code. (diff)
downloadwireguard-openbsd-7a1b2c1db6b2b6896c17a6a661aaa866c97d6872.tar.xz
wireguard-openbsd-7a1b2c1db6b2b6896c17a6a661aaa866c97d6872.zip
protect the PRG state with a mutex in res_randomid().
ok deraadt@ guenther@ djm@
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/net/res_random.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/libc/net/res_random.c b/lib/libc/net/res_random.c
index f0beb7a5732..d1cb0a0cf45 100644
--- a/lib/libc/net/res_random.c
+++ b/lib/libc/net/res_random.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: res_random.c,v 1.17 2008/04/13 00:28:35 djm Exp $ */
+/* $OpenBSD: res_random.c,v 1.18 2013/03/26 17:29:04 eric Exp $ */
/*
* Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
@@ -68,6 +68,8 @@
#include <stdlib.h>
#include <string.h>
+#include "thread_private.h"
+
#define RU_OUT 180 /* Time after wich will be reseeded */
#define RU_MAX 30000 /* Uniq cycle, avoid blackjack prediction */
#define RU_GEN 2 /* Starting generator */
@@ -225,8 +227,13 @@ u_int
res_randomid(void)
{
struct timeval tv;
+ u_int r;
+ _THREAD_PRIVATE_MUTEX(random);
gettimeofday(&tv, NULL);
+
+ _THREAD_PRIVATE_MUTEX_LOCK(random);
+
if (ru_counter >= RU_MAX || tv.tv_sec > ru_reseed)
res_initid();
@@ -234,7 +241,11 @@ res_randomid(void)
ru_x = (ru_a * ru_x + ru_b) % RU_M;
ru_counter++;
- return permute15(ru_seed ^ pmod(ru_g, ru_seed2 + ru_x, RU_N)) | ru_msb;
+ r = permute15(ru_seed ^ pmod(ru_g, ru_seed2 + ru_x, RU_N)) | ru_msb;
+
+ _THREAD_PRIVATE_MUTEX_UNLOCK(random);
+
+ return (r);
}
#if 0