Skip to contentSkip to conversation

x86: Fix mmap random address range

tip:x86/mm tip-bot for Ludwig Nussel 2 participants 2 messages Dec 5, 2011 – Dec 7, 2011 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Commit-ID:  9af0c7a6fa860698d080481f24a342ba74b68982
Gitweb:     http://git.kernel.org/tip/9af0c7a6fa860698d080481f24a342ba74b68982
Author:     Ludwig Nussel <[email protected]>
AuthorDate: Tue, 15 Nov 2011 14:46:46 -0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 5 Dec 2011 17:07:23 +0100

x86: Fix mmap random address range

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.

---
 arch/x86/mm/mmap.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/mm/mmap.c +2 -2
index 4b5ba85..845df68 100644
@@ -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;
 }
#2 lore raw
Quoted 7 lines · tip-bot for Ludwig Nussel
Commit-ID:  9af0c7a6fa860698d080481f24a342ba74b68982
Gitweb:     http://git.kernel.org/tip/9af0c7a6fa860698d080481f24a342ba74b68982
Author:     Ludwig Nussel <[email protected]>
AuthorDate: Tue, 15 Nov 2011 14:46:46 -0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 5 Dec 2011 17:07:23 +0100
Quoted 6 lines

x86: Fix mmap random address range

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.

Will somebody please hand me a big dose of caffeine and explain to me how the range could have been -255 to 255? -256 maybe, or -128 to 127, but -255??!?