The Calibre Bug

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.

CVE Assignment for Calibre
CVE-2011-4124 1. Ability to create root owned directory anywhere. The mount helper calls mkdir(argv[3], ...).
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/.