BitUnmap: Attacking Android Ashmem (Project Zero blog)
Google's Project Zero blog has a detailed look at exploiting a vulnerability in Android's ashmem shared-memory facility. "The mismatch between the mmap-ed and munmap-ed length provides us with a great exploitation primitive! Specifically, we could supply a short length for the mmap operation and a longer length for the munmap operation - thus resulting in deletion of an arbitrarily large range of virtual memory following our bitmap object. Moreover, there's no need for the deleted range to contain one continuous memory mapping, since the range supplied in munmap simply ignores unmapped pages.Once we delete a range of memory, we can then attempt to "re-capture" that memory region with controlled data, by causing another allocation in the remote process. By doing so, we can forcibly "free" a data structure and replace its contents with our own chosen data -- effectively forcing a use-after-free condition."