Skip to content

Commit 57b362b

Browse files
authored
random: Do not trust arc4random_buf() on glibc (#10390)
This effectively reverts #8984. As discussed in #10327 which will enable the use of the getrandom(2) syscall on NetBSD instead of relying on the userland arc4random_buf(), the CSPRNG should prioritize security over speed [1] and history has shown that userland implementations unavoidably fall short on the security side. In fact the glibc implementation is a thin wrapper around the syscall due to security concerns and thus does not provide any benefit over just calling getrandom(2) ourselves. Even without any performance optimizations the CSPRNG should be plenty fast for the vast majority of applications, because they often only need a few bytes of randomness to generate a session ID. If speed is desired, the OO API offers faster, but non-cryptographically secure engines.
1 parent 8173205 commit 57b362b

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ PHP NEWS
88
- GMP:
99
. Properly implement GMP::__construct(). (nielsdos)
1010

11+
- Random:
12+
. Fix GH-10390 (Do not trust arc4random_buf() on glibc). (timwolla)
13+
1114
- Standard:
1215
- Fixed bug GH-8086 (Introduce mail.mixed_lf_and_crlf INI). (Jakub Zelenka)
1316

ext/random/random.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ PHPAPI int php_random_bytes(void *bytes, size_t size, bool should_throw)
505505
}
506506
return FAILURE;
507507
}
508-
#elif HAVE_DECL_ARC4RANDOM_BUF && ((defined(__OpenBSD__) && OpenBSD >= 201405) || (defined(__NetBSD__) && __NetBSD_Version__ >= 700000001) || defined(__APPLE__) || defined(__GLIBC__))
508+
#elif HAVE_DECL_ARC4RANDOM_BUF && ((defined(__OpenBSD__) && OpenBSD >= 201405) || (defined(__NetBSD__) && __NetBSD_Version__ >= 700000001) || defined(__APPLE__))
509509
arc4random_buf(bytes, size);
510510
#else
511511
size_t read_bytes = 0;

0 commit comments

Comments
 (0)