From: deraadt Date: Sun, 13 Jul 2014 13:37:38 +0000 (+0000) Subject: Use dl_iterate_phdr() to iterate over the segments and throw the addresses X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=5a30a5b29fa0086d9798beb14607c9b8f4cf9e67;p=openbsd 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 --- diff --git a/lib/libcrypto/arc4random/getentropy_linux.c b/lib/libcrypto/arc4random/getentropy_linux.c index f06d95b281c..40ea8a14adb 100644 --- a/lib/libcrypto/arc4random/getentropy_linux.c +++ b/lib/libcrypto/arc4random/getentropy_linux.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getentropy_linux.c,v 1.23 2014/07/13 13:03:09 deraadt Exp $ */ +/* $OpenBSD: getentropy_linux.c,v 1.24 2014/07/13 13:37:38 deraadt Exp $ */ /* * Copyright (c) 2014 Theo de Raadt @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -81,6 +82,7 @@ static int getentropy_urandom(void *buf, size_t len); static int getentropy_sysctl(void *buf, size_t len); #endif static int getentropy_fallback(void *buf, size_t len); +static int getentropy_phdr(struct dl_phdr_info *info, size_t size, void *data); int getentropy(void *buf, size_t len) @@ -292,6 +294,15 @@ static int cl[] = { #endif }; +static int +getentropy_phdr(struct dl_phdr_info *info, size_t size, void *data) +{ + SHA512_CTX *ctx = data; + + SHA512_Update(ctx, &info->dlpi_addr, sizeof (info->dlpi_addr)); + return 0; +} + static int getentropy_fallback(void *buf, size_t len) { @@ -328,6 +339,8 @@ getentropy_fallback(void *buf, size_t len) cnt += (int)tv.tv_usec; } + dl_iterate_phdr(getentropy_phdr, &ctx); + for (ii = 0; ii < sizeof(cl)/sizeof(cl[0]); ii++) HX(clock_gettime(cl[ii], &ts) == -1, ts); diff --git a/lib/libcrypto/arc4random/getentropy_solaris.c b/lib/libcrypto/arc4random/getentropy_solaris.c index a2a4c366797..c6a9bfff4ba 100644 --- a/lib/libcrypto/arc4random/getentropy_solaris.c +++ b/lib/libcrypto/arc4random/getentropy_solaris.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getentropy_solaris.c,v 1.6 2014/07/13 13:03:09 deraadt Exp $ */ +/* $OpenBSD: getentropy_solaris.c,v 1.7 2014/07/13 13:37:38 deraadt Exp $ */ /* * Copyright (c) 2014 Theo de Raadt @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -74,6 +75,7 @@ static int gotdata(char *buf, size_t len); static int getentropy_urandom(void *buf, size_t len, const char *path, int devfscheck); static int getentropy_fallback(void *buf, size_t len); +static int getentropy_phdr(struct dl_phdr_info *info, size_t size, void *data); int getentropy(void *buf, size_t len) @@ -245,6 +247,15 @@ static const int cl[] = { #endif }; +static int +getentropy_phdr(struct dl_phdr_info *info, size_t size, void *data) +{ + SHA512_CTX *ctx = data; + + SHA512_Update(ctx, &info->dlpi_addr, sizeof (info->dlpi_addr)); + return 0; +} + static int getentropy_fallback(void *buf, size_t len) { @@ -282,6 +293,8 @@ getentropy_fallback(void *buf, size_t len) cnt += (int)tv.tv_usec; } + dl_iterate_phdr(getentropy_phdr, &ctx); + for (ii = 0; ii < sizeof(cl)/sizeof(cl[0]); ii++) HX(clock_gettime(cl[ii], &ts) == -1, ts); diff --git a/lib/libcrypto/crypto/getentropy_linux.c b/lib/libcrypto/crypto/getentropy_linux.c index f06d95b281c..40ea8a14adb 100644 --- a/lib/libcrypto/crypto/getentropy_linux.c +++ b/lib/libcrypto/crypto/getentropy_linux.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getentropy_linux.c,v 1.23 2014/07/13 13:03:09 deraadt Exp $ */ +/* $OpenBSD: getentropy_linux.c,v 1.24 2014/07/13 13:37:38 deraadt Exp $ */ /* * Copyright (c) 2014 Theo de Raadt @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -81,6 +82,7 @@ static int getentropy_urandom(void *buf, size_t len); static int getentropy_sysctl(void *buf, size_t len); #endif static int getentropy_fallback(void *buf, size_t len); +static int getentropy_phdr(struct dl_phdr_info *info, size_t size, void *data); int getentropy(void *buf, size_t len) @@ -292,6 +294,15 @@ static int cl[] = { #endif }; +static int +getentropy_phdr(struct dl_phdr_info *info, size_t size, void *data) +{ + SHA512_CTX *ctx = data; + + SHA512_Update(ctx, &info->dlpi_addr, sizeof (info->dlpi_addr)); + return 0; +} + static int getentropy_fallback(void *buf, size_t len) { @@ -328,6 +339,8 @@ getentropy_fallback(void *buf, size_t len) cnt += (int)tv.tv_usec; } + dl_iterate_phdr(getentropy_phdr, &ctx); + for (ii = 0; ii < sizeof(cl)/sizeof(cl[0]); ii++) HX(clock_gettime(cl[ii], &ts) == -1, ts); diff --git a/lib/libcrypto/crypto/getentropy_solaris.c b/lib/libcrypto/crypto/getentropy_solaris.c index a2a4c366797..c6a9bfff4ba 100644 --- a/lib/libcrypto/crypto/getentropy_solaris.c +++ b/lib/libcrypto/crypto/getentropy_solaris.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getentropy_solaris.c,v 1.6 2014/07/13 13:03:09 deraadt Exp $ */ +/* $OpenBSD: getentropy_solaris.c,v 1.7 2014/07/13 13:37:38 deraadt Exp $ */ /* * Copyright (c) 2014 Theo de Raadt @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -74,6 +75,7 @@ static int gotdata(char *buf, size_t len); static int getentropy_urandom(void *buf, size_t len, const char *path, int devfscheck); static int getentropy_fallback(void *buf, size_t len); +static int getentropy_phdr(struct dl_phdr_info *info, size_t size, void *data); int getentropy(void *buf, size_t len) @@ -245,6 +247,15 @@ static const int cl[] = { #endif }; +static int +getentropy_phdr(struct dl_phdr_info *info, size_t size, void *data) +{ + SHA512_CTX *ctx = data; + + SHA512_Update(ctx, &info->dlpi_addr, sizeof (info->dlpi_addr)); + return 0; +} + static int getentropy_fallback(void *buf, size_t len) { @@ -282,6 +293,8 @@ getentropy_fallback(void *buf, size_t len) cnt += (int)tv.tv_usec; } + dl_iterate_phdr(getentropy_phdr, &ctx); + for (ii = 0; ii < sizeof(cl)/sizeof(cl[0]); ii++) HX(clock_gettime(cl[ii], &ts) == -1, ts);