* [Buildroot] [PATCH] chrony: backport upstream patch to fix blocking on getrandom() at startup with recent kernels
@ 2018-08-09 15:57 Peter Korsgaard
2018-08-09 20:11 ` Thomas Petazzoni
2018-08-24 7:33 ` Peter Korsgaard
0 siblings, 2 replies; 3+ messages in thread
From: Peter Korsgaard @ 2018-08-09 15:57 UTC (permalink / raw)
To: buildroot
chrony calls getrandom() at startup if available, so it needs a workaround
for the blocking behaviour on recent (4.14.39+), similar to what was done
for util-linux in commit c4d86707cd6 (util-linux: add two upstream patches
to fix blocking on getrandom() with recent kernels).
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
---
...ack-to-reading-dev-urandom-when-getrandom.patch | 42 ++++++++++++++++++++++
1 file changed, 42 insertions(+)
create mode 100644 package/chrony/0002-util-fall-back-to-reading-dev-urandom-when-getrandom.patch
diff --git a/package/chrony/0002-util-fall-back-to-reading-dev-urandom-when-getrandom.patch b/package/chrony/0002-util-fall-back-to-reading-dev-urandom-when-getrandom.patch
new file mode 100644
index 0000000000..d71685e5cd
--- /dev/null
+++ b/package/chrony/0002-util-fall-back-to-reading-dev-urandom-when-getrandom.patch
@@ -0,0 +1,42 @@
+From 7c5bd948bb7e21fa0ee22f29e97748b2d0360319 Mon Sep 17 00:00:00 2001
+From: Miroslav Lichvar <mlichvar@redhat.com>
+Date: Thu, 17 May 2018 14:16:58 +0200
+Subject: [PATCH] util: fall back to reading /dev/urandom when getrandom()
+ blocks
+
+With recent changes in the Linux kernel, the getrandom() system call may
+block for a long time after boot on machines that don't have enough
+entropy. It blocks the chronyd's initialization before it can detach
+from the terminal and may cause a chronyd service to fail to start due
+to a timeout.
+
+At least for now, enable the GRND_NONBLOCK flag to make the system call
+non-blocking and let the code fall back to reading /dev/urandom (which
+never blocks) if the system call failed with EAGAIN or any other error.
+
+This makes the start of chronyd non-deterministic with respect to files
+that it needs to open and possibly also makes it slightly easier to
+guess the transmit/receive timestamp in client requests until the
+urandom source is fully initialized.
+
+Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
+---
+ util.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/util.c b/util.c
+index 4b3e455..76417d5 100644
+--- a/util.c
++++ b/util.c
+@@ -1224,7 +1224,7 @@ get_random_bytes_getrandom(char *buf, unsigned int len)
+ if (disabled)
+ break;
+
+- if (getrandom(rand_buf, sizeof (rand_buf), 0) != sizeof (rand_buf)) {
++ if (getrandom(rand_buf, sizeof (rand_buf), GRND_NONBLOCK) != sizeof (rand_buf)) {
+ disabled = 1;
+ break;
+ }
+--
+2.11.0
+
--
2.11.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* [Buildroot] [PATCH] chrony: backport upstream patch to fix blocking on getrandom() at startup with recent kernels
2018-08-09 15:57 [Buildroot] [PATCH] chrony: backport upstream patch to fix blocking on getrandom() at startup with recent kernels Peter Korsgaard
@ 2018-08-09 20:11 ` Thomas Petazzoni
2018-08-24 7:33 ` Peter Korsgaard
1 sibling, 0 replies; 3+ messages in thread
From: Thomas Petazzoni @ 2018-08-09 20:11 UTC (permalink / raw)
To: buildroot
Hello,
On Thu, 9 Aug 2018 17:57:28 +0200, Peter Korsgaard wrote:
> chrony calls getrandom() at startup if available, so it needs a workaround
> for the blocking behaviour on recent (4.14.39+), similar to what was done
> for util-linux in commit c4d86707cd6 (util-linux: add two upstream patches
> to fix blocking on getrandom() with recent kernels).
>
> Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
> ---
> ...ack-to-reading-dev-urandom-when-getrandom.patch | 42 ++++++++++++++++++++++
> 1 file changed, 42 insertions(+)
> create mode 100644 package/chrony/0002-util-fall-back-to-reading-dev-urandom-when-getrandom.patch
Applied to master, thanks.
Thomas
--
Thomas Petazzoni, CTO, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Buildroot] [PATCH] chrony: backport upstream patch to fix blocking on getrandom() at startup with recent kernels
2018-08-09 15:57 [Buildroot] [PATCH] chrony: backport upstream patch to fix blocking on getrandom() at startup with recent kernels Peter Korsgaard
2018-08-09 20:11 ` Thomas Petazzoni
@ 2018-08-24 7:33 ` Peter Korsgaard
1 sibling, 0 replies; 3+ messages in thread
From: Peter Korsgaard @ 2018-08-24 7:33 UTC (permalink / raw)
To: buildroot
>>>>> "Peter" == Peter Korsgaard <peter@korsgaard.com> writes:
> chrony calls getrandom() at startup if available, so it needs a workaround
> for the blocking behaviour on recent (4.14.39+), similar to what was done
> for util-linux in commit c4d86707cd6 (util-linux: add two upstream patches
> to fix blocking on getrandom() with recent kernels).
> Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Committed to 2018.02.x and 2018.05.x, thanks.
--
Bye, Peter Korsgaard
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-08-24 7:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-09 15:57 [Buildroot] [PATCH] chrony: backport upstream patch to fix blocking on getrandom() at startup with recent kernels Peter Korsgaard
2018-08-09 20:11 ` Thomas Petazzoni
2018-08-24 7:33 ` Peter Korsgaard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox