This is an archive of the discontinued LLVM Phabricator instance.

[sanitizers] Add a blocking boolean to GetRandom prototype
ClosedPublic

Authored by cryptoad on Aug 7 2017, 7:53 AM.

Details

Summary

On platforms with getrandom, the system call defaults to blocking. This
becomes an issue in the very early stage of the boot for Scudo, when the RNG
source is not set-up yet: the syscall will block and we'll stall.

Introduce a parameter to specify that the function should not block, defaulting
to blocking as the underlying syscall does.

Update Scudo to use the non-blocking version.

Event Timeline

cryptoad created this revision.Aug 7 2017, 7:53 AM
alekseyshl added inline comments.Aug 8 2017, 9:38 AM
lib/sanitizer_common/sanitizer_linux.cc
1704

Can you move those defines to the top of the file and define SANITIZER_USE_GETRANDOM? Then here you can do

if (SANITIZER_USE_GETRANDOM) {
  ...
}
cryptoad added inline comments.Aug 8 2017, 10:00 AM
lib/sanitizer_common/sanitizer_linux.cc
1704

So the compiler still wants SYSCALL(getrandom) and GRND_NONBLOCK to be defined with an if rather than an #if.
I am unsure how to cleanly address that. Macroing the internal_syscall part to do nothing?

cryptoad updated this revision to Diff 110240.Aug 8 2017, 11:15 AM

How about this code construct?

alekseyshl accepted this revision.Aug 11 2017, 7:52 AM
alekseyshl added inline comments.
lib/sanitizer_common/sanitizer_linux.cc
1704

You're right, this is not ideal too. Yep, let's keep #if SANITIZER_LINUX && defined(__NR_getrandom) block at the top of the file and use #if SANITIZER_USE_GETRANDOM here to avoid internal_getrandom definition. Other than that, looks good. Sorry for the delay!

This revision is now accepted and ready to land.Aug 11 2017, 7:52 AM
cryptoad updated this revision to Diff 110764.Aug 11 2017, 10:31 AM

Keeping SANITIZER_USE_GETRANDOM at the top, protecting the getrandom
syscall with an #if to keep the compiler happy.

cryptoad closed this revision.Aug 14 2017, 7:54 AM