My first reaction to this headline was "Surely there is never any circumstance where this is genuinely a smart thing to do, no matter how clever" but I confess I wasn't thinking in terms of security vulnerabilities.
I believe some old borland compilers mapped 0 to a guard value, and checked if it ever changed to see if there were accidental writes to null.
I feel that was a stupid approach, and having 0 unmapped is actually the better choice -- instant seqfault is imho a better way to know your program failed.
Heh, in DOS a far NULL pointer was the start of the interrupt vector table -- divide by zero being first. I remember writing a program that wrote the address of one of my subroutines to a far NULL pointer and then dividing by zero.
In a related bit of cleverness I've heard that the JVM doesn't actually put NULL checks in it's generated ASM, instead it installs a SIGSEGV handler that catchs the null pointer exception and does the right thing.
And C# on .NET disallows non-virtual method calls on null instance locations. It does so by emitting a callvirt IL instruction for the non-virtual method, which in turn is translated by the CLR to:
Plenty. In fact many get irate when you explain to them that thier nice "close to the metal" language is actualy doesnt talk directly to the memory, it has to go through a (albeit hardware assisted) transform moderated by a couple layers of stuff. The whole point of VM is to keep the illusion of working directly with memory/hw, because it is useful sometimes.
These null pointers are sometimes function pointers. Wow. You don't even need to muck with the stack and change the return address to get arbitrary code execution.
I admit I'm surprised Linux even lets you mmap 0x0. I suppose most systems won't, since mmap_min_addr will probably be set to a sane address, but it's still a legit vulnerability.
Not under HP-UX on a "PA" processor. The page at 0x0 isn't neccessarily unmapped or marked noread/nowrite/nonothing. As I recall one or the other HP C compilers has a way around this, but unless you take care, you won't use that compiler flag, and you end up having NULL pointer de-refs.