From: Ludwig Nussel Date: Wed, 24 Aug 2011 23:46:16 +0000 (+1000) Subject: On x86_32 casting the unsigned int result of get_random_int() to long may X-Git-Tag: next-20110912~1^2~140 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=f940df367d4c14c2883ab8b894ba351624e9df2e;p=karo-tx-linux.git On x86_32 casting the unsigned int result of get_random_int() to long may result in a negative value. On x86_32 the range of mmap_rnd() therefore was -255 to 255. The 32bit mode on x86_64 used 0 to 255 as intended. The bug was introduced by 675a081 ("x86: unify mmap_{32|64}.c") in January 2008. Signed-off-by: Ludwig Nussel Cc: Ingo Molnar Cc: Thomas Gleixner Cc: "H. Peter Anvin" Cc: Harvey Harrison Signed-off-by: Andrew Morton --- diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c index 4b5ba85eb5c9..845df6835f9f 100644 --- a/arch/x86/mm/mmap.c +++ b/arch/x86/mm/mmap.c @@ -75,9 +75,9 @@ static unsigned long mmap_rnd(void) */ if (current->flags & PF_RANDOMIZE) { if (mmap_is_ia32()) - rnd = (long)get_random_int() % (1<<8); + rnd = get_random_int() % (1<<8); else - rnd = (long)(get_random_int() % (1<<28)); + rnd = get_random_int() % (1<<28); } return rnd << PAGE_SHIFT; }