A few weeks ago, I posted an exploit and a bug report for a Linux local root exploit in Calibre. The author, Kovid Goyal, became incensed, and rather than work with me to fix it, he insulted my colleagues and me. After each one of his fixes, I released a new exploit breaking the latest. It got a lot of social media hype, and was kind of a big deal. After several days of media frenzy and bad publicity, the stubborn developer finally bent to the advice of the chorus of leading security researchers, and the mount helper was removed in entirety. In any case, the exploits show some neat race condition tricks that you might want to check out, using inotify and a toggler.
There’s plenty of technical explanation in the comments of the exploit code.
|CVE Assignment for Calibre|
|CVE-2011-4124||1. Ability to create root owned directory anywhere. The mount helper calls mkdir(argv, …).|
|2. Ability to remove any empty directory on the system.|
|3. Ability to create user_controlled_dir/.created_by_calibre_mount_helper anywhere on the filesystem.|
|4. Ability to delete user_controlled_dir/.created_by_calibre_mount_helper anywhere on the filesystem.|
|5. Ability to inject arguments into ‘mount’ being exec’d. On lines 78, 81, and 83, the final two arguments to mount are user controlled. On lines 1033, 106, 108, 139, and 141, the last argument to unmount/eject is user controlled. The “exists()” check can be subverted via race condition or by creating an existing file in the working directory with a filename equal to the desired injected argument.|
|6. Ability to unmount any device.|
|CVE-2011-4125||7. Ability to execute any program as root. The mount helper makes use of execlp on lines 78, 81, 83, 103, 106, 108, 139, and 141, and the first argument does not start with a / character. Because of this, execlp will search PATH for the executable to run. PATH is user controlled, and thus it is trivial to write a program that spawns a shell and give it “mount” as a filename, and direct PATH to its directory.|
|CVE-2011-4126||8. Race condition, allowing the ability to mount any device to anywhere. This leads to local root, since you can mount over /etc/ or /etc/pam.d/.|
My first three CVEs.
After that, I decided to learn about linker bugs, so I reread Tavis’ excellent two write-ups on CVE-2010-3856 and CVE-2010-3847. I saw that there was room for writing a newer exploit based on his research that did not depend on having read access to SUID executables or having a cron daemon installed, so I wrote I Can’t Read and I Won’t Race You Either. The source has plenty of explanation. I also suggest reading Tim Brown’s excellent paper on linker bugs.