Skip to content

Commit b409946

Browse files
committed
powerpc/mm: Fix possible out-of-bounds shift in arch_mmap_rnd()
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 <[email protected]> Reviewed-by: Kees Cook <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent 9765ad1 commit b409946

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

arch/powerpc/mm/mmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ unsigned long arch_mmap_rnd(void)
6666
if (is_32bit_task())
6767
shift = mmap_rnd_compat_bits;
6868
#endif
69-
rnd = get_random_long() % (1 << shift);
69+
rnd = get_random_long() % (1ul << shift);
7070

7171
return rnd << PAGE_SHIFT;
7272
}

0 commit comments

Comments
 (0)