Skip to content

Commit

Permalink
powerpc/mm: Fix possible out-of-bounds shift in arch_mmap_rnd()
Browse files Browse the repository at this point in the history
The recent patch to add runtime configuration of the ASLR limits added a bug in
arch_mmap_rnd() where we may shift an integer (32-bits) by up to 33 bits,
leading to undefined behaviour.

In practice it exhibits as every process seg faulting instantly, presumably
because the rnd value hasn't been restricited by the modulus at all. We didn't
notice because it only happens under certain kernel configurations and if the
number of bits is actually set to a large value.

Fix it by switching to unsigned long.

Fixes: 9fea59b ("powerpc/mm: Add support for runtime configuration of ASLR limits")
Reported-by: Balbir Singh <bsingharora@gmail.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
  • Loading branch information
Michael Ellerman committed Apr 26, 2017
1 parent 9765ad1 commit b409946
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion arch/powerpc/mm/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ unsigned long arch_mmap_rnd(void)
if (is_32bit_task())
shift = mmap_rnd_compat_bits;
#endif
rnd = get_random_long() % (1 << shift);
rnd = get_random_long() % (1ul << shift);

return rnd << PAGE_SHIFT;
}
Expand Down

0 comments on commit b409946

Please sign in to comment.