FROMLIST: drivers: char: random: add get_random_long()
authordcashman <dcashman@google.com>
Wed, 24 Feb 2016 21:27:06 +0000 (13:27 -0800)
committerDmitry Shmidt <dimitrysh@google.com>
Wed, 16 Mar 2016 23:50:21 +0000 (16:50 -0700)
commit9a3fe392e468775da2b63a813f60b923eb6476c5
tree660cfb150038b5f6fc848a631fa108693af47bc7
parent157aa28fd7bf66bf3d9d1774398fddc7dc255c52
FROMLIST: drivers: char: random: add get_random_long()

(cherry picked from commit https://lkml.org/lkml/2016/2/4/831)

d07e22597d1d355 ("mm: mmap: add new /proc tunable for mmap_base ASLR")
added the ability to choose from a range of values to use for entropy
count in generating the random offset to the mmap_base address.  The
maximum value on this range was set to 32 bits for 64-bit x86 systems, but
this value could be increased further, requiring more than the 32 bits of
randomness provided by get_random_int(), as is already possible for arm64.
Add a new function: get_random_long() which more naturally fits with the
mmap usage of get_random_int() but operates exactly the same as
get_random_int().

Also, fix the shifting constant in mmap_rnd() to be an unsigned long so
that values greater than 31 bits generate an appropriate mask without
overflow.  This is especially important on x86, as its shift instruction
uses a 5-bit mask for the shift operand, which meant that any value for
mmap_rnd_bits over 31 acts as a no-op and effectively disables mmap_base
randomization.

Finally, replace calls to get_random_int() with get_random_long() where
appropriate.

Bug: 26963541
Signed-off-by: Daniel Cashman <dcashman@android.com>
Signed-off-by: Daniel Cashman <dcashman@google.com>
Change-Id: I5b45621088666d5d1dfbf43952f25ea0798b10ba
drivers/char/random.c
include/linux/random.h