diff options
| author | deraadt <> | 2014-07-13 13:37:38 +0000 |
|---|---|---|
| committer | deraadt <> | 2014-07-13 13:37:38 +0000 |
| commit | 7b3b70e21bf263aeb1b8fa2297e567734a24367c (patch) | |
| tree | c78f43217261ccd852fb0ee8b8c7188b18ae77d4 /src/lib/libcrypto/crypto/getentropy_linux.c | |
| parent | a92e6cbce8aeae0f9747c5742a2f860dc0e7573f (diff) | |
| download | openbsd-7b3b70e21bf263aeb1b8fa2297e567734a24367c.tar.gz openbsd-7b3b70e21bf263aeb1b8fa2297e567734a24367c.tar.bz2 openbsd-7b3b70e21bf263aeb1b8fa2297e567734a24367c.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 | ||
