diff options
author | 2014-06-27 17:37:42 +0000 | |
---|---|---|
committer | 2014-06-27 17:37:42 +0000 | |
commit | 9ef1c0337cd32f3aef2ca7858dff3f7a8d50a161 (patch) | |
tree | 2bd0868fe7639a3ea0827613de86a49c09f97db5 /lib/libc/stdlib/malloc.c | |
parent | Update list of .S depencies over assym.h. (diff) | |
download | wireguard-openbsd-9ef1c0337cd32f3aef2ca7858dff3f7a8d50a161.tar.xz wireguard-openbsd-9ef1c0337cd32f3aef2ca7858dff3f7a8d50a161.zip |
Move to a smaller rbytes buffer and skip a random part. Not to
improve the random stream itself (it doesn't), but to introduce
noise in the arc4random calling pattern. Thanks to matthew@ who
pointed out bias in a previous diff, ok deraadt@ matthew@
Diffstat (limited to 'lib/libc/stdlib/malloc.c')
-rw-r--r-- | lib/libc/stdlib/malloc.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c index ba8bd3ad8fb..5d5437dc1fd 100644 --- a/lib/libc/stdlib/malloc.c +++ b/lib/libc/stdlib/malloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: malloc.c,v 1.167 2014/06/02 08:49:38 otto Exp $ */ +/* $OpenBSD: malloc.c,v 1.168 2014/06/27 17:37:42 otto Exp $ */ /* * Copyright (c) 2008, 2010, 2011 Otto Moerbeek <otto@drijf.net> * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org> @@ -118,7 +118,7 @@ struct dir_info { /* delayed free chunk slots */ void *delayed_chunks[MALLOC_DELAYED_CHUNK_MASK + 1]; size_t rbytesused; /* random bytes used */ - u_char rbytes[512]; /* random bytes */ + u_char rbytes[32]; /* random bytes */ u_short chunk_start; #ifdef MALLOC_STATS size_t inserts; @@ -276,7 +276,8 @@ static void rbytes_init(struct dir_info *d) { arc4random_buf(d->rbytes, sizeof(d->rbytes)); - d->rbytesused = 0; + /* add 1 to account for using d->rbytes[0] */ + d->rbytesused = 1 + d->rbytes[0] % (sizeof(d->rbytes) / 2); } static inline u_char |