From e3c038e4c08d68cc3ca03cf0c3dc09c3182e216a Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 31 May 2020 23:29:21 -0700 Subject: [PATCH] getrandom-tests: do not assume GRND_RANDOM yields short read MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * tests/test-getrandom.c (main): Omit assertion that getrandom (b, sizeof b, GRND_RANDOM | GRND_NONBLOCK) < sizeof b when b’s size is 100000. This assertion fails with Linux kernel 5.6.13, as that kernel ignores the GRND_RANDOM flag. The separate blocking pool is going away in the Linux kernel, and they’ve added a flag GRND_INSECURE instead; see: https://lore.kernel.org/linux-api/705c5a091b63cc5da70c99304bb97e0109be0a26.1577088521.git.luto@kernel.org/ The assertion was iffy anyway; what’s to prevent a kernel from lazily filling a large buffer with random bytes? --- ChangeLog | 11 +++++++++++ tests/test-getrandom.c | 19 +------------------ 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4d240e0d41..7b7e7d34c1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2020-05-31 Paul Eggert + getrandom-tests: do not assume GRND_RANDOM yields short read + * tests/test-getrandom.c (main): Omit assertion that + getrandom (b, sizeof b, GRND_RANDOM | GRND_NONBLOCK) < sizeof b + when b’s size is 100000. This assertion fails with Linux kernel + 5.6.13, as that kernel ignores the GRND_RANDOM flag. + The separate blocking pool is going away in the Linux kernel, and + they’ve added a flag GRND_INSECURE instead; see: + https://lore.kernel.org/linux-api/705c5a091b63cc5da70c99304bb97e0109be0a26.1577088521.git.luto@kernel.org/ + The assertion was iffy anyway; what’s to prevent a kernel from + lazily filling a large buffer with random bytes? + read-file-test: pacify --enable-gcc-warnings * tests/test-read-file.c (test_read_file): Now static. diff --git a/tests/test-getrandom.c b/tests/test-getrandom.c index f4a31c62d8..0e9fbb0c26 100644 --- a/tests/test-getrandom.c +++ b/tests/test-getrandom.c @@ -79,24 +79,7 @@ main (void) ASSERT (errno == ENOSYS || errno == EAGAIN || errno == EINVAL /* Solaris */); else - { - ASSERT (ret > 0); - /* This assertion fails on - - GNU/Hurd, - - Mac OS X, - - GNU/kFreeBSD, FreeBSD 12.0, - - OpenBSD 6.5, - - Minix 3.3, - - AIX 7.1, - - Haiku, - - native Windows. - This indicates that the function, when called with GRND_RANDOM flag, - probably does not return truly random numbers, but instead uses a - pseudo-random number generator. */ -#if !(defined __GNU__ || (defined __APPLE__ && defined __MACH__) || defined __FreeBSD_kernel__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __minix || defined _AIX || defined __HAIKU__ || (defined _WIN32 && ! defined __CYGWIN__)) - ASSERT (ret < (ssize_t) sizeof (large_buf)); -#endif - } + ASSERT (ret > 0); if (getrandom (buf1, 1, 0) < 1) if (getrandom (buf1, 1, GRND_RANDOM) < 1) -- 2.39.5