user3723779 user3723779 - 1 year ago 52
C Question

Why am I unable to load an executable below 0x201.000 ( Which linear address space is seen as available in a linux process ? Where is it documented?)

I am using gcc on linux 3.16.0-29-generic.
I managed to instruct the gcc compiler to set as loading address of the code I am compiling 0x201.000 using the option of gcc

( it seems that 0x1000 are needed for the header of the ELF so I cannot go below 0x201.000 ).

Instead using
in other tests, I had been able to allocate also lower addresses as e.g. sometimes 0x10.000 never 0x0.000 to 0xF.000, and always all other addresses up to and over 0x800.000 ).
I am asking thus, from the OS user perspective which addresses are available to a generic process, and why the executable may not be loaded below 0x200.000 ?

Where is it documented or where should I look .
Is it guaranteed that some virtual memory should always be there ? at any requested address (unless there is a lack of physical memory ?).
Essentially the question is "what is the linear memory available to a process", or said differently what is the logic model offered to developers ?

Answer Source

Regarding the inability to mmap addresses bellow 0x10.000, the answer is in "" .

0-address protection

Since the kernel and userspace share virtual memory addresses, the "NULL" memory space needs to be protected so that userspace mmap'd memory cannot start at address 0, stopping "NULL dereference" kernel attacks. This is possible with 2.6.22 kernels, and was implemented with the "mmap_min_addr" sysctl setting. Since Ubuntu 9.04, the mmap_min_addr setting is built into the kernel. (64k for x86, 32k for ARM.)

We may change the "mmap_min_addr" by using the instruction sudo sysctl -w vm.mmap_min_addr=0

So the answer is that the whole address space is available without exceptions ( linear addresses ).