util-linux: add two upstream patches to fix blocking on getrandom() with recent kernels
As part of the fix for CVE-2018-1108 (kernel drivers before version 4.17-rc1 are vulnerable to a weakness in the Linux kernel's implementation of random seed data. Programs, early in the boot sequence, could use the data allocated for the seed before it was sufficiently generated), the kernel random number generator initialization routine was changed. See the project-zero writeup for more details:
https://bugs.chromium.org/p/project-zero/issues/detail?id=1559
These changes have now also been backported to 4.14.x (since 4.14.39) and 4.16.x (since 4.16.7).
This change unfortunately causes users of libuuid from util-linux to block for a very long time waiting for sufficient entropy. An example of this is mke2fs, which uses libuuid to generate the filesystem UUID.
Fix this by backporting two post-2.31 fixes from upstream.
--- ...2-lib-randutils-Do-not-block-on-getrandom.patch | 52 ++++++++++++++++ ...andutils-don-t-break-on-EAGAIN-use-usleep.patch | 71 ++++++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 package/util-linux/0002-lib-randutils-Do-not-block-on-getrandom.patch create mode 100644 package/util-linux/0003-lib-randutils-don-t-break-on-EAGAIN-use-usleep.patch
package/util-linux/0002-lib-randutils-Do-not-block-on-getrandom.patch new file +52 -0
@@ -0,0 +1,52 @@ +From a9cf659e0508c1f56813a7d74c64f67bbc962538 Mon Sep 17 00:00:00 2001 +From: Carlo Caione <[email protected]> +Date: Mon, 19 Mar 2018 10:31:07 +0000 +Subject: [PATCH] lib/randutils: Do not block on getrandom() + +In Endless we have hit a problem when using 'sfdisk' on the really first +boot to automatically expand the rootfs partition. On this platform +'sfdisk' is blocking on getrandom() because not enough random bytes are +available. This is an ARM platform without a hwrng. + +We fix this passing GRND_NONBLOCK to getrandom(). 'sfdisk' will use the +best entropy it has available and fallback only as necessary. + +Signed-off-by: Carlo Caione <[email protected]> +Signed-off-by: Peter Korsgaard <[email protected]> +--- + lib/randutils.c | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +diff --git a/lib/randutils.c b/lib/randutils.c +index e1c4059e1..02c3d9eb0 100644 +--- a/lib/randutils.c ++++ b/lib/randutils.c +@@ -36,6 +36,8 @@ + + #if !defined(HAVE_GETRANDOM) && defined(SYS_getrandom) + /* libc without function, but we have syscal */ ++#define GRND_NONBLOCK 0x01 ++#define GRND_RANDOM 0x02 + static int getrandom(void *buf, size_t buflen, unsigned int flags) + { + return (syscall(SYS_getrandom, buf, buflen, flags)); +@@ -104,13 +106,15 @@ void random_get_bytes(void *buf, size_t nbytes) + int x; + + errno = 0; +- x = getrandom(cp, n, 0); ++ x = getrandom(cp, n, GRND_NONBLOCK); + if (x > 0) { /* success */ + n -= x; + cp += x; + lose_counter = 0; + } else if (errno == ENOSYS) /* kernel without getrandom() */ + break; ++ else if (errno == EAGAIN) ++ break; + else if (lose_counter++ > 16) /* entropy problem? */ + break; + } +-- +2.11.0 +
package/util-linux/0003-lib-randutils-don-t-break-on-EAGAIN-use-usleep.patch new file +71 -0
71 lines not on this page · raw message
Signature · 1 line
2.11.0
Carlos Santos
Tested-byQuoted 18 lines
From: "Peter Korsgaard" <[email protected]>
To: "Carlos Santos" <[email protected]>, "buildroot" <[email protected]>
Cc: "Peter Korsgaard" <[email protected]>
Sent: Sunday, May 27, 2018 7:39:49 AM
Subject: [PATCH-2018.02.x] util-linux: add two upstream patches to fix blocking ongetrandom()with recent kernelsAs part of the fix for CVE-2018-1108 (kernel drivers before version 4.17-rc1 are vulnerable to a weakness in the Linux kernel's implementation of random seed data. Programs, early in the boot sequence, could use the data allocated for the seed before it was sufficiently generated), the kernel random number generator initialization routine was changed. See the project-zero writeup for more details:
https://bugs.chromium.org/p/project-zero/issues/detail?id=1559
These changes have now also been backported to 4.14.x (since 4.14.39) and 4.16.x (since 4.16.7).
Quoted 7 lines
This change unfortunately causes users of libuuid from util-linux to block for a very long time waiting for sufficient entropy. An example of this is mke2fs, which uses libuuid to generate the filesystem UUID.
Fix this by backporting two post-2.31 fixes from upstream.
Signed-off-by Peter Korsgaard <[email protected]>
Built host and target util-linux for x86_64 systems running Linux kernel 4.16.11 (Fedora 28) and 4.14.39 (Buildroot), respectively.
Ran mke2fs from an early init script to check that it did not block.
Signature · 1 line
Carlos Santos (Casantos) - DATACOM, P&D
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Carlos" == Carlos Santos <[email protected]> writes:
Hi,
Quoted 6 lines
Quoted 6 lines
This change unfortunately causes users of libuuid from util-linux to block for a very long time waiting for sufficient entropy. An example of this is mke2fs, which uses libuuid to generate the filesystem UUID.
Fix this by backporting two post-2.31 fixes from upstream.
Quoted 8 lines
Quoted 1 line
Signed-off-by Peter Korsgaard <[email protected]>Tested-by Carlos Santos <[email protected]>Built host and target util-linux for
x86_64systems running Linux kernel 4.16.11 (Fedora 28) and 4.14.39 (Buildroot), respectively.Ran mke2fs from an early init script to check that it did not block.
Committed to 2018.02.x, thanks.
Signature · 1 line
Bye, Peter Korsgaard