summaryrefslogtreecommitdiff
path: root/drivers/char/random.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2022-02-07 23:37:13 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2022-02-21 21:14:00 +0100
commit434537ae54ad37e93555de21b6ac8133d6d773a9 (patch)
tree92138e44646e566972c8a9532cd900d136a12377 /drivers/char/random.c
parent04ec96b768c9dd43946b047c3da60dcc66431370 (diff)
random: remove outdated INT_MAX >> 6 check in urandom_read()
In 79a8468747c5 ("random: check for increase of entropy_count because of signed conversion"), a number of checks were added around what values were passed to account(), because account() was doing fancy fixed point fractional arithmetic, and a user had some ability to pass large values directly into it. One of things in that commit was limiting those values to INT_MAX >> 6. The first >> 3 was for bytes to bits, and the next >> 3 was for bits to 1/8 fractional bits. However, for several years now, urandom reads no longer touch entropy accounting, and so this check serves no purpose. The current flow is: urandom_read_nowarn()-->get_random_bytes_user()-->chacha20_block() Of course, we don't want that size_t to be truncated when adding it into the ssize_t. But we arrive at urandom_read_nowarn() in the first place either via ordinary fops, which limits reads to MAX_RW_COUNT, or via getrandom() which limits reads to INT_MAX. Cc: Theodore Ts'o <tytso@mit.edu> Reviewed-by: Dominik Brodowski <linux@dominikbrodowski.net> Reviewed-by: Jann Horn <jannh@google.com> Reviewed-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'drivers/char/random.c')
-rw-r--r--drivers/char/random.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 768dee5e081a..896ec54f8f5c 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1286,9 +1286,8 @@ void rand_initialize_disk(struct gendisk *disk)
static ssize_t urandom_read_nowarn(struct file *file, char __user *buf,
size_t nbytes, loff_t *ppos)
{
- int ret;
+ ssize_t ret;
- nbytes = min_t(size_t, nbytes, INT_MAX >> 6);
ret = get_random_bytes_user(buf, nbytes);
trace_urandom_read(nbytes, input_pool.entropy_count);
return ret;