Use __NR_getrandom rather than SYS_getrandom.

The former is defined by the kernel and is a straightforward number. The
latter is defined by glibc as:

  #define SYS_getrandom __NR_getrandom

which does not work when kernel headers are older than glibc headers.
Instead, use the kernel values.

Bug: chromium:742260
Change-Id: Id162f125db660643269e0b1329633437048575c4
Reviewed-on: https://boringssl-review.googlesource.com/17864
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Adam Langley <agl@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
This commit is contained in:
David Benjamin 2017-07-14 11:31:33 -04:00 committed by CQ bot account: commit-bot@chromium.org
parent 71dfad4d10
commit 7d53638872

View File

@ -45,33 +45,33 @@
#if defined(OPENSSL_LINUX)
#if defined(OPENSSL_X86_64)
#define EXPECTED_SYS_getrandom 318
#define EXPECTED_NR_getrandom 318
#elif defined(OPENSSL_X86)
#define EXPECTED_SYS_getrandom 355
#define EXPECTED_NR_getrandom 355
#elif defined(OPENSSL_AARCH64)
#define EXPECTED_SYS_getrandom 278
#define EXPECTED_NR_getrandom 278
#elif defined(OPENSSL_ARM)
#define EXPECTED_SYS_getrandom 384
#define EXPECTED_NR_getrandom 384
#elif defined(OPENSSL_PPC64LE)
#define EXPECTED_SYS_getrandom 359
#define EXPECTED_NR_getrandom 359
#endif
#if defined(EXPECTED_SYS_getrandom)
#define USE_SYS_getrandom
#if defined(EXPECTED_NR_getrandom)
#define USE_NR_getrandom
#if defined(SYS_getrandom)
#if defined(__NR_getrandom)
#if SYS_getrandom != EXPECTED_SYS_getrandom
#if __NR_getrandom != EXPECTED_NR_getrandom
#error "system call number for getrandom is not the expected value"
#endif
#else /* SYS_getrandom */
#else /* __NR_getrandom */
#define SYS_getrandom EXPECTED_SYS_getrandom
#define __NR_getrandom EXPECTED_NR_getrandom
#endif /* SYS_getrandom */
#endif /* __NR_getrandom */
#endif /* EXPECTED_SYS_getrandom */
#endif /* EXPECTED_NR_getrandom */
#if !defined(GRND_NONBLOCK)
#define GRND_NONBLOCK 1
@ -95,7 +95,7 @@ DEFINE_BSS_GET(int, urandom_fd);
DEFINE_STATIC_ONCE(rand_once);
#if defined(USE_SYS_getrandom) || defined(BORINGSSL_FIPS)
#if defined(USE_NR_getrandom) || defined(BORINGSSL_FIPS)
/* message writes |msg| to stderr. We use this because referencing |stderr|
* with |fprintf| generates relocations, which is a problem inside the FIPS
* module. */
@ -116,10 +116,10 @@ static void init_once(void) {
int fd = *urandom_fd_requested_bss_get();
CRYPTO_STATIC_MUTEX_unlock_read(rand_lock_bss_get());
#if defined(USE_SYS_getrandom)
#if defined(USE_NR_getrandom)
uint8_t dummy;
long getrandom_ret =
syscall(SYS_getrandom, &dummy, sizeof(dummy), GRND_NONBLOCK);
syscall(__NR_getrandom, &dummy, sizeof(dummy), GRND_NONBLOCK);
if (getrandom_ret == 1) {
*urandom_fd_bss_get() = kHaveGetrandom;
@ -132,7 +132,7 @@ static void init_once(void) {
do {
getrandom_ret =
syscall(SYS_getrandom, &dummy, sizeof(dummy), 0 /* no flags */);
syscall(__NR_getrandom, &dummy, sizeof(dummy), 0 /* no flags */);
} while (getrandom_ret == -1 && errno == EINTR);
if (getrandom_ret == 1) {
@ -140,7 +140,7 @@ static void init_once(void) {
return;
}
}
#endif /* USE_SYS_getrandom */
#endif /* USE_NR_getrandom */
if (fd == kUnset) {
do {
@ -234,7 +234,7 @@ void RAND_set_urandom_fd(int fd) {
}
}
#if defined(USE_SYS_getrandom) && defined(OPENSSL_MSAN)
#if defined(USE_NR_getrandom) && defined(OPENSSL_MSAN)
void __msan_unpoison(void *, size_t);
#endif
@ -245,9 +245,9 @@ static char fill_with_entropy(uint8_t *out, size_t len) {
ssize_t r;
if (*urandom_fd_bss_get() == kHaveGetrandom) {
#if defined(USE_SYS_getrandom)
#if defined(USE_NR_getrandom)
do {
r = syscall(SYS_getrandom, out, len, 0 /* no flags */);
r = syscall(__NR_getrandom, out, len, 0 /* no flags */);
} while (r == -1 && errno == EINTR);
#if defined(OPENSSL_MSAN)
@ -258,7 +258,7 @@ static char fill_with_entropy(uint8_t *out, size_t len) {
}
#endif /* OPENSSL_MSAN */
#else /* USE_SYS_getrandom */
#else /* USE_NR_getrandom */
abort();
#endif
} else {