diff options
author | Andy Lutomirski <luto@kernel.org> | 2019-12-23 11:20:46 +0300 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2020-01-08 00:07:00 +0300 |
commit | 75551dbf112c992bc6c99a972990b3f272247e23 (patch) | |
tree | 14f6622786b61f5e244eb9c0ec402e3d64cd8faa /drivers/char | |
parent | c6f1deb158789abba02a7eba600747843eeb3a57 (diff) | |
download | linux-75551dbf112c992bc6c99a972990b3f272247e23.tar.xz |
random: add GRND_INSECURE to return best-effort non-cryptographic bytes
Signed-off-by: Andy Lutomirski <luto@kernel.org>
Link: https://lore.kernel.org/r/d5473b56cf1fa900ca4bd2b3fc1e5b8874399919.1577088521.git.luto@kernel.org
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'drivers/char')
-rw-r--r-- | drivers/char/random.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c index 91954c0091a5..b7e2ad7eafca 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -2194,7 +2194,14 @@ SYSCALL_DEFINE3(getrandom, char __user *, buf, size_t, count, { int ret; - if (flags & ~(GRND_NONBLOCK|GRND_RANDOM)) + if (flags & ~(GRND_NONBLOCK|GRND_RANDOM|GRND_INSECURE)) + return -EINVAL; + + /* + * Requesting insecure and blocking randomness at the same time makes + * no sense. + */ + if ((flags & (GRND_INSECURE|GRND_RANDOM)) == (GRND_INSECURE|GRND_RANDOM)) return -EINVAL; if (count > INT_MAX) @@ -2203,7 +2210,7 @@ SYSCALL_DEFINE3(getrandom, char __user *, buf, size_t, count, if (flags & GRND_RANDOM) return _random_read(flags & GRND_NONBLOCK, buf, count); - if (!crng_ready()) { + if (!(flags & GRND_INSECURE) && !crng_ready()) { if (flags & GRND_NONBLOCK) return -EAGAIN; ret = wait_for_random_bytes(); |