Resources

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!

XNU VM copy-on-write bypass due to incorrect shadow creation logic during unaligned vm_map_copy operations- 1081

Ian Beer - Project Zero (P0)Posted 3 Years Ago
  • 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.
  • The function 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.
  • The condition of 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.
  • How can we exploit this?
    1. Start a privileged process.
    2. Fork from the process with readable regions, such as the code sections.
    3. Use the vulnerability above with unaligned mappings to make the address mappings editable.
    4. Edit the code from the privileged process! This can be used to get root relatively easy I would guess.
  • Overall, I love this vulnerability. This is a major memory corruption vulnerability that would have NOT been picked up by Rust, since the page mappings are a logic bug. A good explanation of this can be found at DayZeroSec as well.