coperating-systemposixpagingvirtual-memory

Why do `sbrk`, `mmap` etc. return very long addresses?


When I mmap a block of memory, the returned pointer might be something like 2607194112 or 3614339072 (both actual values I've gotten).

Why are these values seemingly so random? It's all virtual anyway, so why not just give me address 4096 to start us off?

I suppose this question extends also to something like malloc, but that will use one of these under the hood anyways.


Solution

  • Like @erik258 mentioned, it's because of Address space layout randomization (ASLR). Without that feature, it would be pretty easier for attackers to predict addresses of your code and libc functions and execute return-to-libc attacks. It implemented under the kernel - so far all this functions get such random values (malloc, mmap, etc).