Detect and support syscall(SYS_getrandom, [..]) as well

This commit is contained in:
Sebastian Pipping committed 2017-05-31 23:31:15 +02:00
1 parent 9e02465f09
commit f356fb56fb
3 files changed
+36 -8

No files matched your search

+1 -1
View File
@@ -5,7 +5,7 @@ Release ??????????
Use high quality entropy for hash initialization:
* arc4random_buf on BSD, systems with libbsd, CloudABI
* RtlGenRandom on Windows XP / Server 2003 and later
* getrandom on glic 2.25+ Linux 3.17+
* getrandom on Linux 3.17+
In a way, that's still part of CVE-2016-5300.
For packaging, feel free to configure using
--(with|without)-libbsd to bypass auto-detection.
+17
View File
@@ -142,6 +142,23 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([
AC_MSG_RESULT([yes])
], [
AC_MSG_RESULT([no])
AC_MSG_CHECKING([for syscall SYS_getrandom (Linux 3.17+)])
AC_LINK_IFELSE([AC_LANG_SOURCE([
#include <stdlib.h> /* for NULL */
#include <unistd.h> /* for syscall */
#include <sys/syscall.h> /* for SYS_getrandom */
int main() {
syscall(SYS_getrandom, NULL, 0, 0);
return 0;
}
])], [
AC_DEFINE([HAVE_SYSCALL_GETRANDOM], [1],
[Define to 1 if you have `syscall' and `SYS_getrandom'.])
AC_MSG_RESULT([yes])
], [
AC_MSG_RESULT([no])
])
])
+18 -7
View File
@@ -700,11 +700,17 @@ static const XML_Char implicitContext[] = {
};
#if defined(HAVE_GETRANDOM)
# include <sys/random.h>
#if defined(HAVE_GETRANDOM) || defined(HAVE_SYSCALL_GETRANDOM)
# include <errno.h>
/* Obtain entropy on Linux 3.17+ with glibc 2.25+ */
# if defined(HAVE_GETRANDOM)
# include <sys/random.h> /* getrandom */
# else
# include <unistd.h> /* syscall */
# include <sys/syscall.h> /* SYS_getrandom */
# endif
/* Obtain entropy on Linux 3.17+ */
static int
writeRandomBytes_getrandom(void * target, size_t count) {
int success = 0; /* full count bytes written? */
@@ -715,8 +721,13 @@ writeRandomBytes_getrandom(void * target, size_t count) {
void * const currentTarget = (void*)((char*)target + bytesWrittenTotal);
const size_t bytesToWrite = count - bytesWrittenTotal;
const int bytesWrittenMore
= getrandom(currentTarget, bytesToWrite, getrandomFlags);
const int bytesWrittenMore =
#if defined(HAVE_GETRANDOM)
getrandom(currentTarget, bytesToWrite, getrandomFlags);
#else
syscall(SYS_getrandom, currentTarget, bytesToWrite, getrandomFlags);
#endif
if (bytesWrittenMore > 0) {
bytesWrittenTotal += bytesWrittenMore;
if (bytesWrittenTotal >= count)
@@ -727,7 +738,7 @@ writeRandomBytes_getrandom(void * target, size_t count) {
return success;
}
#endif /* defined(HAVE_GETRANDOM) */
#endif /* defined(HAVE_GETRANDOM) || defined(HAVE_SYSCALL_GETRANDOM) */
#ifdef _WIN32
@@ -812,7 +823,7 @@ generate_hash_secret_salt(XML_Parser parser)
if (writeRandomBytes_RtlGenRandom((void *)&entropy, sizeof(entropy))) {
return ENTROPY_DEBUG("RtlGenRandom", entropy);
}
#elif defined(HAVE_GETRANDOM)
#elif defined(HAVE_GETRANDOM) || defined(HAVE_SYSCALL_GETRANDOM)
if (writeRandomBytes_getrandom((void *)&entropy, sizeof(entropy))) {
return ENTROPY_DEBUG("getrandom", entropy);
}