OSDN Git Service

Call prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY) if app is debuggable.
authorOleksiy Vyalov <ovyalov@google.com>
Tue, 21 Jun 2016 23:21:37 +0000 (16:21 -0700)
committerOleksiy Vyalov <ovyalov@google.com>
Wed, 22 Jun 2016 17:58:07 +0000 (10:58 -0700)
Enabled Yama security may prevent non-privileged debugger from
attaching to the app. However, if app is marked is debuggable
then it should acceptable to allow debugger with arbitrary pid
to connect the app.

Bug: 29549463

Change-Id: I50c79dbca272dc473e489cc61471628e2fdc4a03

runtime/native/dalvik_system_ZygoteHooks.cc

index 1aa789f..9da44a4 100644 (file)
@@ -46,6 +46,16 @@ static void EnableDebugger() {
   if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) == -1) {
     PLOG(ERROR) << "prctl(PR_SET_DUMPABLE) failed for pid " << getpid();
   }
+
+  // Even if Yama is on a non-privileged native debugger should
+  // be able to attach to the debuggable app.
+  if (prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY, 0, 0, 0) == -1) {
+    // if Yama is off prctl(PR_SET_PTRACER) returns EINVAL - don't log in this
+    // case since it's expected behaviour.
+    if (errno != EINVAL) {
+      PLOG(ERROR) << "prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY) failed for pid " << getpid();
+    }
+  }
 #endif
   // We don't want core dumps, though, so set the core dump size to 0.
   rlimit rl;