]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
x86: fix mmap random address range
authorLudwig Nussel <ludwig.nussel@suse.de>
Tue, 8 Nov 2011 00:19:51 +0000 (11:19 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Wed, 9 Nov 2011 02:10:04 +0000 (13:10 +1100)
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 <ludwig.nussel@suse.de>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Harvey Harrison <harvey.harrison@gmail.com>
Cc: <stable@kernel.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
arch/x86/mm/mmap.c

index 4b5ba85eb5c95ebb705f8ce420acbff85c052f47..845df6835f9ff5fc216ab01857100d41eba77fbf 100644 (file)
@@ -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;
 }