diff options
author | deraadt <> | 2014-07-13 13:37:38 +0000 |
---|---|---|
committer | deraadt <> | 2014-07-13 13:37:38 +0000 |
commit | 29dfc21d062d6f2453c4a90cddbf08f7f7e4e1fe (patch) | |
tree | c78f43217261ccd852fb0ee8b8c7188b18ae77d4 /src/lib/libcrypto/crypto/getentropy_linux.c | |
parent | a507f9dd9387923514b8801e5f4424765bf792d1 (diff) | |
download | openbsd-29dfc21d062d6f2453c4a90cddbf08f7f7e4e1fe.tar.gz openbsd-29dfc21d062d6f2453c4a90cddbf08f7f7e4e1fe.tar.bz2 openbsd-29dfc21d062d6f2453c4a90cddbf08f7f7e4e1fe.zip |
Use dl_iterate_phdr() to iterate over the segments and throw the addresses
into the hash; hoping the system has some ASLR or PIE. This replaces and
substantially improves upon &main which proved problematic with some picky
linkers.
Work with kettenis, testing by beck
Diffstat (limited to 'src/lib/libcrypto/crypto/getentropy_linux.c')
-rw-r--r-- | src/lib/libcrypto/crypto/getentropy_linux.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/lib/libcrypto/crypto/getentropy_linux.c b/src/lib/libcrypto/crypto/getentropy_linux.c index f06d95b281..40ea8a14ad 100644 --- a/src/lib/libcrypto/crypto/getentropy_linux.c +++ b/src/lib/libcrypto/crypto/getentropy_linux.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: getentropy_linux.c,v 1.23 2014/07/13 13:03:09 deraadt Exp $ */ | 1 | /* $OpenBSD: getentropy_linux.c,v 1.24 2014/07/13 13:37:38 deraadt Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org> | 4 | * Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org> |
@@ -39,6 +39,7 @@ | |||
39 | #include <stdlib.h> | 39 | #include <stdlib.h> |
40 | #include <stdint.h> | 40 | #include <stdint.h> |
41 | #include <stdio.h> | 41 | #include <stdio.h> |
42 | #include <link.h> | ||
42 | #include <termios.h> | 43 | #include <termios.h> |
43 | #include <fcntl.h> | 44 | #include <fcntl.h> |
44 | #include <signal.h> | 45 | #include <signal.h> |
@@ -81,6 +82,7 @@ static int getentropy_urandom(void *buf, size_t len); | |||
81 | static int getentropy_sysctl(void *buf, size_t len); | 82 | static int getentropy_sysctl(void *buf, size_t len); |
82 | #endif | 83 | #endif |
83 | static int getentropy_fallback(void *buf, size_t len); | 84 | static int getentropy_fallback(void *buf, size_t len); |
85 | static int getentropy_phdr(struct dl_phdr_info *info, size_t size, void *data); | ||
84 | 86 | ||
85 | int | 87 | int |
86 | getentropy(void *buf, size_t len) | 88 | getentropy(void *buf, size_t len) |
@@ -293,6 +295,15 @@ static int cl[] = { | |||
293 | }; | 295 | }; |
294 | 296 | ||
295 | static int | 297 | static int |
298 | getentropy_phdr(struct dl_phdr_info *info, size_t size, void *data) | ||
299 | { | ||
300 | SHA512_CTX *ctx = data; | ||
301 | |||
302 | SHA512_Update(ctx, &info->dlpi_addr, sizeof (info->dlpi_addr)); | ||
303 | return 0; | ||
304 | } | ||
305 | |||
306 | static int | ||
296 | getentropy_fallback(void *buf, size_t len) | 307 | getentropy_fallback(void *buf, size_t len) |
297 | { | 308 | { |
298 | uint8_t results[SHA512_DIGEST_LENGTH]; | 309 | uint8_t results[SHA512_DIGEST_LENGTH]; |
@@ -328,6 +339,8 @@ getentropy_fallback(void *buf, size_t len) | |||
328 | cnt += (int)tv.tv_usec; | 339 | cnt += (int)tv.tv_usec; |
329 | } | 340 | } |
330 | 341 | ||
342 | dl_iterate_phdr(getentropy_phdr, &ctx); | ||
343 | |||
331 | for (ii = 0; ii < sizeof(cl)/sizeof(cl[0]); ii++) | 344 | for (ii = 0; ii < sizeof(cl)/sizeof(cl[0]); ii++) |
332 | HX(clock_gettime(cl[ii], &ts) == -1, ts); | 345 | HX(clock_gettime(cl[ii], &ts) == -1, ts); |
333 | 346 | ||