4 ms·
> dereferencing null is perfectly fine on Cortex-M processors and is well-defined It's also perfectly fine on x86, in kernel memory page 0 is often mapped, the
by masklinn 11y ago
> dereferencing null is perfectly fine on Cortex-M processors and is well-defined
It's also perfectly fine on x86, in kernel memory page 0 is often mapped, the OS is the one mapping page 0 so that userland dereferencing it faults.
- qb45 11y agoWhich x86 kernel maps something at 0? In Windows and Linux, the low part of virtual address space is reserved for userspace. In fact, Linux had several privilege escalation bugs which involved putting something at 0 and executing a buggy syscall which loaded this thing due to NULL dereference and believed it's some legit internal kernel data.
- 0x0 11y agoWhich was probably the reason why "mmap_min_addr" was added :) https://wiki.debian.org/mmap_min_addr https://wiki.debian.org/mmap_min_addr
- makomk 11y agoMappings at zero are used by legacy code like 16-bit Windows applications, if I remember correctly.
- jevinskie 11y agoOS X and iOS map in __TEXT,__PAGEZERO to 0x0.* Of course, it is mapped without any protection levels so it isn't of much use except for catching most nullptr dereferences (just 4 GB of protection on x86_64!). * Well, this is implemented by the default system toolchain. You'r particular toolchain can opt out of this behavior if they want to.
- noselasd 11y ago"perfectly fine" does not depend on the processor alone, it depends on the compiler. A compiler for x86 can assume dereferencing a NULL pointer is undefined behavior, and optimize your code in ways you perhaps didn't expect. Or it could document and provide a well defined behavior of derefrencing a NULL pointer. (e.g. gcc provides -fdelete-null-pointer-checks to control this)
- masklinn 11y ago> "perfectly fine" does not depend on the processor alone, it depends on the compiler. as(1).