People often ask me "How did you learn how to hack?" The answer: by reading. This page is a collection of the blog posts and other articles that I have accumulated over the years of my journey. Enjoy!
Copy on Write is functionality in the Linux kernel for only remapping memory once it has been written to after a fork. This is a major optimization, since forked code can reuse memory from other processes. The copy only occurs only a write to the address space occurs.vm_map_copy_overwrite handles large copies with two different routes: unaligned and aligned. With the unaligned route, the extra condition checks whether the mapping is VM_PROT_WRITE. If this is true, it will create a shadow copy of the page only once it is writable.VM_PROT_WRITE should NOT be possible, with this code being later in the chain. The usage of needs_copy and VM_PROT_WRITE should not b possible. However, this can be raced! If we change the page mapping back from VM_PROT_WRITE after the verification in the upper code path but BEFORE the shadow copy call, we can hit this condition.