“Most serious” Linux privilege-escalation bug ever is under active exploit
Can someone help me better understand how this works, or perhaps point me to a decent article explaining more of the details? Most of the articles I can find just briefly explain the exploit, but not really how it works (in detail).<p>From looking at the example code, it seems like the general process is:<p>- Open some (normally un-writable) file as read-only and mmap it in to your process.<p>- Kick off two threads. One thread to repeatedly write to the same mmap-ed address via /proc/PID/mem and another thread to keep issuing the madvise call.<p>- Wait for some race condition to be (un)satisfied such that you're able to write to a cached copy of the file.<p>What I don’t fully understand is how the /proc/PID/mem thing works.<p>Here’s what I’m curious about:<p>1. What would happen if you tried to write to the mmap-ed region directly? Since it’s been mapped in  with “PROT_READ”, does this mean that you’ll get a segmentation fault or something? From the manpage, it seems like “MAP_PRIVATE” allows it to be a COW mapping, but I don’t see how the combination of “PROT_READ” and “MAP_PRIVATE” is even valid. Unless this means that any writes to data copied from the mmap-ed region into other buffers will be COW-ed and that you can’t actually write to the mmap-ed region itself? That would make sense to me.<p>2.How is writing to /proc/PID/mem any different than writing through the mmap-ed region directly? Assume that you weren’t running the madvice thread. What would happen then if you tried to write to the /proc/PID/mem file? Presumably the same thing that happens if you just tried to write to the file directly…<p>3. Finally, how does the madvice call cause a race condition? I realize this might be a little too much to cover in a comment, but this seems like the meat of it.