[compiler-rt] f642236 - [scudo] Only read urandom if getrandom syscall isn't available. (#161889)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 6 13:17:37 PDT 2025
Author: Christopher Ferris
Date: 2025-10-06T13:17:32-07:00
New Revision: f64223647e1969253ddc1bd8725bfacfc0456215
URL: https://github.com/llvm/llvm-project/commit/f64223647e1969253ddc1bd8725bfacfc0456215
DIFF: https://github.com/llvm/llvm-project/commit/f64223647e1969253ddc1bd8725bfacfc0456215.diff
LOG: [scudo] Only read urandom if getrandom syscall isn't available. (#161889)
If the getrandom system call is available, but the call returns an
error, it could mean that the system doesn't have enough randomness to
respond yet. Trying to read /dev/urandom will likely block and cause
initialization to be stalled. Therefore, return false in this case and
use the backup random data.
Added:
Modified:
compiler-rt/lib/scudo/standalone/linux.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/scudo/standalone/linux.cpp b/compiler-rt/lib/scudo/standalone/linux.cpp
index 6cc8e0c786e06..57171edac1e9e 100644
--- a/compiler-rt/lib/scudo/standalone/linux.cpp
+++ b/compiler-rt/lib/scudo/standalone/linux.cpp
@@ -192,6 +192,12 @@ bool getRandom(void *Buffer, uptr Length, UNUSED bool Blocking) {
syscall(SYS_getrandom, Buffer, Length, Blocking ? 0 : GRND_NONBLOCK);
if (ReadBytes == static_cast<ssize_t>(Length))
return true;
+ // If this system call is not implemented in the kernel, then we will try
+ // and use /dev/urandom. Otherwise, if the syscall fails, return false
+ // assuming that trying to read /dev/urandom will cause a delay waiting for
+ // the random data to be usable.
+ if (errno != ENOSYS)
+ return false;
#endif // defined(SYS_getrandom)
// Up to 256 bytes, a read off /dev/urandom will not be interrupted.
// Blocking is moot here, O_NONBLOCK has no effect when opening /dev/urandom.
More information about the llvm-commits
mailing list