As I discussed last year, Ubuntu has been restricting the use of ptrace for a few releases now. I’m excited to see Fedora starting to introduce similar restrictions, but I’m disappointed at the specific implementation:
- A method for doing this already exists (Yama). Yama is not plumbed into SELinux, but I would argue that’s not needed.
- The SELinux method depends, unsurprisingly, on an active SELinux policy on the system, which isn’t everyone.
- It’s not possible for regular developers (not system developers) to debug their own processes.
- It will break all ptrace-based crash handlers (e.g. KDE, Firefox, Chrome) or tools that depend on ptrace to do their regular job (e.g. Wine, gdb, strace, ltrace).
Blocking ptrace blocks exactly one type of attack: credential extraction from a running process. In the face of a persistent attack, ultimately, anything running as the user can be trojaned, regardless of ptrace. Blocking ptrace, however, stalls the initial attack. At the moment an attacker arrives on a system, they cannot immediately extend their reach by examining the other processes (e.g. jumping down existing SSH connections, pulling passwords out of Firefox, etc). Some sensitive processes are already protected from this kind of thing because they are not “dumpable” (due to either specifically requesting this from prctl(PR_SET_DUMPABLE, ...)
or due to a uid/gid transition), but many are open for abuse.
The primary “valid” use cases for ptrace are crash handlers, debuggers, and memory analysis tools. In each case, they have a single common element: the process being ptraced knows which process should have permission to attach to it. What Linux lacked was a way to declare these relationships, which is what Yama added. The use of SELinux policy, for example, isn’t sufficient because the permissions are too wide (e.g. giving gdb
the ability to ptrace anything just means the attacker has to use gdb
to do the job). Right now, due to the use of Yama in Ubuntu, all the mentioned tools have the awareness of how to programmatically declare the ptrace relationships at runtime with prctl(PR_SET_PTRACER, ...)
. I find it disappointing that Fedora won’t be using this to their advantage when it is available and well tested.
Even ChromeOS uses Yama now. ;)
© 2012, Kees Cook. This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License.