Commit 75551dbf authored by Andy Lutomirski's avatar Andy Lutomirski Committed by Theodore Ts'o

random: add GRND_INSECURE to return best-effort non-cryptographic bytes

Signed-off-by: default avatarAndy Lutomirski <luto@kernel.org>
Link: https://lore.kernel.org/r/d5473b56cf1fa900ca4bd2b3fc1e5b8874399919.1577088521.git.luto@kernel.orgSigned-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent c6f1deb1
...@@ -2194,7 +2194,14 @@ SYSCALL_DEFINE3(getrandom, char __user *, buf, size_t, count, ...@@ -2194,7 +2194,14 @@ SYSCALL_DEFINE3(getrandom, char __user *, buf, size_t, count,
{ {
int ret; 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; return -EINVAL;
if (count > INT_MAX) if (count > INT_MAX)
...@@ -2203,7 +2210,7 @@ SYSCALL_DEFINE3(getrandom, char __user *, buf, size_t, count, ...@@ -2203,7 +2210,7 @@ SYSCALL_DEFINE3(getrandom, char __user *, buf, size_t, count,
if (flags & GRND_RANDOM) if (flags & GRND_RANDOM)
return _random_read(flags & GRND_NONBLOCK, buf, count); return _random_read(flags & GRND_NONBLOCK, buf, count);
if (!crng_ready()) { if (!(flags & GRND_INSECURE) && !crng_ready()) {
if (flags & GRND_NONBLOCK) if (flags & GRND_NONBLOCK)
return -EAGAIN; return -EAGAIN;
ret = wait_for_random_bytes(); ret = wait_for_random_bytes();
......
...@@ -49,8 +49,10 @@ struct rand_pool_info { ...@@ -49,8 +49,10 @@ struct rand_pool_info {
* *
* GRND_NONBLOCK Don't block and return EAGAIN instead * GRND_NONBLOCK Don't block and return EAGAIN instead
* GRND_RANDOM Use the /dev/random pool instead of /dev/urandom * GRND_RANDOM Use the /dev/random pool instead of /dev/urandom
* GRND_INSECURE Return non-cryptographic random bytes
*/ */
#define GRND_NONBLOCK 0x0001 #define GRND_NONBLOCK 0x0001
#define GRND_RANDOM 0x0002 #define GRND_RANDOM 0x0002
#define GRND_INSECURE 0x0004
#endif /* _UAPI_LINUX_RANDOM_H */ #endif /* _UAPI_LINUX_RANDOM_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment