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_solaris.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_solaris.c')
-rw-r--r-- | src/lib/libcrypto/crypto/getentropy_solaris.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/lib/libcrypto/crypto/getentropy_solaris.c b/src/lib/libcrypto/crypto/getentropy_solaris.c index a2a4c36679..c6a9bfff4b 100644 --- a/src/lib/libcrypto/crypto/getentropy_solaris.c +++ b/src/lib/libcrypto/crypto/getentropy_solaris.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: getentropy_solaris.c,v 1.6 2014/07/13 13:03:09 deraadt Exp $ */ | 1 | /* $OpenBSD: getentropy_solaris.c,v 1.7 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> |
@@ -34,6 +34,7 @@ | |||
34 | #include <stdlib.h> | 34 | #include <stdlib.h> |
35 | #include <stdint.h> | 35 | #include <stdint.h> |
36 | #include <stdio.h> | 36 | #include <stdio.h> |
37 | #include <link.h> | ||
37 | #include <termios.h> | 38 | #include <termios.h> |
38 | #include <fcntl.h> | 39 | #include <fcntl.h> |
39 | #include <signal.h> | 40 | #include <signal.h> |
@@ -74,6 +75,7 @@ static int gotdata(char *buf, size_t len); | |||
74 | static int getentropy_urandom(void *buf, size_t len, const char *path, | 75 | static int getentropy_urandom(void *buf, size_t len, const char *path, |
75 | int devfscheck); | 76 | int devfscheck); |
76 | static int getentropy_fallback(void *buf, size_t len); | 77 | static int getentropy_fallback(void *buf, size_t len); |
78 | static int getentropy_phdr(struct dl_phdr_info *info, size_t size, void *data); | ||
77 | 79 | ||
78 | int | 80 | int |
79 | getentropy(void *buf, size_t len) | 81 | getentropy(void *buf, size_t len) |
@@ -246,6 +248,15 @@ static const int cl[] = { | |||
246 | }; | 248 | }; |
247 | 249 | ||
248 | static int | 250 | static int |
251 | getentropy_phdr(struct dl_phdr_info *info, size_t size, void *data) | ||
252 | { | ||
253 | SHA512_CTX *ctx = data; | ||
254 | |||
255 | SHA512_Update(ctx, &info->dlpi_addr, sizeof (info->dlpi_addr)); | ||
256 | return 0; | ||
257 | } | ||
258 | |||
259 | static int | ||
249 | getentropy_fallback(void *buf, size_t len) | 260 | getentropy_fallback(void *buf, size_t len) |
250 | { | 261 | { |
251 | uint8_t results[SHA512_DIGEST_LENGTH]; | 262 | uint8_t results[SHA512_DIGEST_LENGTH]; |
@@ -282,6 +293,8 @@ getentropy_fallback(void *buf, size_t len) | |||
282 | cnt += (int)tv.tv_usec; | 293 | cnt += (int)tv.tv_usec; |
283 | } | 294 | } |
284 | 295 | ||
296 | dl_iterate_phdr(getentropy_phdr, &ctx); | ||
297 | |||
285 | for (ii = 0; ii < sizeof(cl)/sizeof(cl[0]); ii++) | 298 | for (ii = 0; ii < sizeof(cl)/sizeof(cl[0]); ii++) |
286 | HX(clock_gettime(cl[ii], &ts) == -1, ts); | 299 | HX(clock_gettime(cl[ii], &ts) == -1, ts); |
287 | 300 | ||