Linux (or any "normal" processes and virtual memory OS) leaves the smallest addresses unchanged, in particular to detect errors with a null pointer. consider the following example:
#include <unistd.h> #include <sys/mman.h> int main() { char *p = mmap(0,4096,PROT_READ|PROT_WRITE,MAP_ANONYMOUS|MAP_SHARED|MAP_FIXED,-1,0); if (p == MAP_FAILED) return 1; p[0] = 'x'; p[1] = '\n'; write(1,0,2); return 0; }
this works on pre-selinux systems (prints "x"), although on my desktop with selinux disabled, it only works as root, not a regular user. but the fact is that you, as a rule, control everything in your virtual address space. if you really want to put something at 0, you can, although you may encounter, for example, code that refuses to process a string at 0.
source share