Skip to content

Commit 3d64055

Browse files
committed
[scudo] Only read urandom if getrandom syscall isn't available.
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.
1 parent eabfed8 commit 3d64055

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

compiler-rt/lib/scudo/standalone/linux.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ bool getRandom(void *Buffer, uptr Length, UNUSED bool Blocking) {
192192
syscall(SYS_getrandom, Buffer, Length, Blocking ? 0 : GRND_NONBLOCK);
193193
if (ReadBytes == static_cast<ssize_t>(Length))
194194
return true;
195+
// If this system call is not implemented in the kernel, then we will try
196+
// and use /dev/urandom. Otherwise, if the syscall fails, return false
197+
// assuming that trying to read /dev/urandom will cause a delay waiting for
198+
// the random data to be usable.
199+
if (errno != ENOSYS)
200+
return false;
195201
#endif // defined(SYS_getrandom)
196202
// Up to 256 bytes, a read off /dev/urandom will not be interrupted.
197203
// Blocking is moot here, O_NONBLOCK has no effect when opening /dev/urandom.

0 commit comments

Comments
 (0)