summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorderaadt <>2014-07-13 13:37:38 +0000
committerderaadt <>2014-07-13 13:37:38 +0000
commit29dfc21d062d6f2453c4a90cddbf08f7f7e4e1fe (patch)
treec78f43217261ccd852fb0ee8b8c7188b18ae77d4
parenta507f9dd9387923514b8801e5f4424765bf792d1 (diff)
downloadopenbsd-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
-rw-r--r--src/lib/libcrypto/arc4random/getentropy_linux.c15
-rw-r--r--src/lib/libcrypto/arc4random/getentropy_solaris.c15
-rw-r--r--src/lib/libcrypto/crypto/getentropy_linux.c15
-rw-r--r--src/lib/libcrypto/crypto/getentropy_solaris.c15
4 files changed, 56 insertions, 4 deletions
diff --git a/src/lib/libcrypto/arc4random/getentropy_linux.c b/src/lib/libcrypto/arc4random/getentropy_linux.c
index f06d95b281..40ea8a14ad 100644
--- a/src/lib/libcrypto/arc4random/getentropy_linux.c
+++ b/src/lib/libcrypto/arc4random/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);
81static int getentropy_sysctl(void *buf, size_t len); 82static int getentropy_sysctl(void *buf, size_t len);
82#endif 83#endif
83static int getentropy_fallback(void *buf, size_t len); 84static int getentropy_fallback(void *buf, size_t len);
85static int getentropy_phdr(struct dl_phdr_info *info, size_t size, void *data);
84 86
85int 87int
86getentropy(void *buf, size_t len) 88getentropy(void *buf, size_t len)
@@ -293,6 +295,15 @@ static int cl[] = {
293}; 295};
294 296
295static int 297static int
298getentropy_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
306static int
296getentropy_fallback(void *buf, size_t len) 307getentropy_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
diff --git a/src/lib/libcrypto/arc4random/getentropy_solaris.c b/src/lib/libcrypto/arc4random/getentropy_solaris.c
index a2a4c36679..c6a9bfff4b 100644
--- a/src/lib/libcrypto/arc4random/getentropy_solaris.c
+++ b/src/lib/libcrypto/arc4random/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);
74static int getentropy_urandom(void *buf, size_t len, const char *path, 75static int getentropy_urandom(void *buf, size_t len, const char *path,
75 int devfscheck); 76 int devfscheck);
76static int getentropy_fallback(void *buf, size_t len); 77static int getentropy_fallback(void *buf, size_t len);
78static int getentropy_phdr(struct dl_phdr_info *info, size_t size, void *data);
77 79
78int 80int
79getentropy(void *buf, size_t len) 81getentropy(void *buf, size_t len)
@@ -246,6 +248,15 @@ static const int cl[] = {
246}; 248};
247 249
248static int 250static int
251getentropy_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
259static int
249getentropy_fallback(void *buf, size_t len) 260getentropy_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
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);
81static int getentropy_sysctl(void *buf, size_t len); 82static int getentropy_sysctl(void *buf, size_t len);
82#endif 83#endif
83static int getentropy_fallback(void *buf, size_t len); 84static int getentropy_fallback(void *buf, size_t len);
85static int getentropy_phdr(struct dl_phdr_info *info, size_t size, void *data);
84 86
85int 87int
86getentropy(void *buf, size_t len) 88getentropy(void *buf, size_t len)
@@ -293,6 +295,15 @@ static int cl[] = {
293}; 295};
294 296
295static int 297static int
298getentropy_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
306static int
296getentropy_fallback(void *buf, size_t len) 307getentropy_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
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);
74static int getentropy_urandom(void *buf, size_t len, const char *path, 75static int getentropy_urandom(void *buf, size_t len, const char *path,
75 int devfscheck); 76 int devfscheck);
76static int getentropy_fallback(void *buf, size_t len); 77static int getentropy_fallback(void *buf, size_t len);
78static int getentropy_phdr(struct dl_phdr_info *info, size_t size, void *data);
77 79
78int 80int
79getentropy(void *buf, size_t len) 81getentropy(void *buf, size_t len)
@@ -246,6 +248,15 @@ static const int cl[] = {
246}; 248};
247 249
248static int 250static int
251getentropy_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
259static int
249getentropy_fallback(void *buf, size_t len) 260getentropy_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