Skip to content

Yama: add PTRACE exception tracking

Kees Cook lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 17 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2security: create task_free security callbackinclude/linux/security.h kernel/fork.c security/capability.c +1 more+18 -00 replies
2/2Yama: add PTRACE exception trackinginclude/linux/prctl.h security/yama/yama_lsm.c+193 -188 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/2] Yama: add PTRACE exception tracking

The primary exception to Yama's descendant-based PTRACE restrictions is when an application has a predefined crash handler that is spawned in parallel with the crashed application (e.g. KDE, Chromium). These applications want to bypass the common RLIMIT_CORE=0, and gather state information from the process for upstream problem reporting. When the main application crashes, it generally has access to the PID of what will debug it (e.g. when a KDE app crashes, it knows the parent PID of the debugger that will be spawned).

So, since this programmatic method of PTRACEing is useful, there should be a way for processes to actively declare who can PTRACE them. This patch adds a prctl hook for Yama so that processes can exempt themselves from the PTRACE restrictions in the case of a crash when they know their debugger's PID.

As a matter of demonstration, here is what the patch to KDE4 would look like to support Yama, or other PTRACE-restricting LSMs that wanted to grant a similar exception:

kdeui/util/kcrash.cpp +2 -0
@@ -41,6 +41,7 @@
 #include <sys/wait.h>
 #include <sys/un.h>
 #include <sys/socket.h>
+#include <sys/prctl.h>
 #include <errno.h>
 
 #include <qwindowdefs.h>
@@ -437,6 +438,7 @@
             //if the process was started directly, use waitpid(), as it's a child...
             while(waitpid(-1, NULL, 0) != pid) {}
         } else {
+            prctl(PR_SET_PTRACER, pid, 0, 0, 0);
             //...else poll its status using kill()
             while(kill(pid, 0) >= 0) {
                 sleep(1);
Signature · 2 lines
Kees Cook
Ubuntu Security Team