From 537d84a07cab3152554ed0608a704958a979120f Mon Sep 17 00:00:00 2001 From: Pawel Dziepak Date: Tue, 5 Mar 2013 21:37:31 +0100 Subject: [PATCH] libroot: randomize position of areas created by mmap() When mmap() is invoked without specifying address hint B_RANDOMIZED_ANY_ADDRESS is used. Otherwise, unless MAP_FIXED flag is set (which requires mmap() to return an area positioned exactly at given address), B_RANDOMIZED_BASE_ADDRESS is used. --- src/system/libroot/posix/sys/mman.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/system/libroot/posix/sys/mman.cpp b/src/system/libroot/posix/sys/mman.cpp index 17866ee9ed..68dbf0a7a2 100644 --- a/src/system/libroot/posix/sys/mman.cpp +++ b/src/system/libroot/posix/sys/mman.cpp @@ -113,9 +113,13 @@ mmap(void* address, size_t length, int protection, int flags, int fd, int mapping = (flags & MAP_SHARED) != 0 ? REGION_NO_PRIVATE_MAP : REGION_PRIVATE_MAP; - uint32 addressSpec = address == NULL ? B_ANY_ADDRESS : B_BASE_ADDRESS; + uint32 addressSpec; if ((flags & MAP_FIXED) != 0) addressSpec = B_EXACT_ADDRESS; + else if (address != NULL) + addressSpec = B_RANDOMIZED_BASE_ADDRESS; + else + addressSpec = B_RANDOMIZED_ANY_ADDRESS; uint32 areaProtection = 0; if ((protection & PROT_READ) != 0)