0002-util-fall-back-to-reading-dev-urandom-when-getrandom.patch 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. From 7c5bd948bb7e21fa0ee22f29e97748b2d0360319 Mon Sep 17 00:00:00 2001
  2. From: Miroslav Lichvar <mlichvar@redhat.com>
  3. Date: Thu, 17 May 2018 14:16:58 +0200
  4. Subject: [PATCH] util: fall back to reading /dev/urandom when getrandom()
  5. blocks
  6. With recent changes in the Linux kernel, the getrandom() system call may
  7. block for a long time after boot on machines that don't have enough
  8. entropy. It blocks the chronyd's initialization before it can detach
  9. from the terminal and may cause a chronyd service to fail to start due
  10. to a timeout.
  11. At least for now, enable the GRND_NONBLOCK flag to make the system call
  12. non-blocking and let the code fall back to reading /dev/urandom (which
  13. never blocks) if the system call failed with EAGAIN or any other error.
  14. This makes the start of chronyd non-deterministic with respect to files
  15. that it needs to open and possibly also makes it slightly easier to
  16. guess the transmit/receive timestamp in client requests until the
  17. urandom source is fully initialized.
  18. Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
  19. ---
  20. util.c | 2 +-
  21. 1 file changed, 1 insertion(+), 1 deletion(-)
  22. diff --git a/util.c b/util.c
  23. index 4b3e455..76417d5 100644
  24. --- a/util.c
  25. +++ b/util.c
  26. @@ -1224,7 +1224,7 @@ get_random_bytes_getrandom(char *buf, unsigned int len)
  27. if (disabled)
  28. break;
  29. - if (getrandom(rand_buf, sizeof (rand_buf), 0) != sizeof (rand_buf)) {
  30. + if (getrandom(rand_buf, sizeof (rand_buf), GRND_NONBLOCK) != sizeof (rand_buf)) {
  31. disabled = 1;
  32. break;
  33. }
  34. --
  35. 2.11.0