random: remove outdated INT_MAX >> 6 check in urandom_read()
authorJason A. Donenfeld <Jason@zx2c4.com>
Mon, 7 Feb 2022 22:37:13 +0000 (23:37 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Wed, 16 Feb 2022 23:00:08 +0000 (00:00 +0100)
commit66b36424007fda6bb3258f6977cf14ddcb273e06
treebd3f6677e4880bfeb50e22daaacb66348c183a1e
parentc66a21451b644d1cee8df01f688c4342a293d713
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>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
drivers/char/random.c