Consider this code running on an up-to-date Ubuntu 16.04 x86_64 system:
void main(int argc, char *argv[])
{
while(1) {
char *x = (char *)mmap(0, 1000, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
printf("%p\n", x);
munmap(x, 1000);
}
}
Whose output looks like this:
0x7f02ca14c000
0x7f02ca14c000
0x7f02ca14c000
0x7f02ca14c000
...
I would have expected, having provided an address hint of zero and ASLR being globally enabled to get random addresses here.
Is it possible to mmap() anonymous shared memory at random addresses?