Bug 1090598: Once we have hit the ah_crap_handler, allow any process (such as gdb) to ptrace us. r=froydnj
authorKyle Huey <khuey@kylehuey.com>
Tue, 28 Oct 2014 18:27:53 -0700
changeset 212776 544cb3ae4996fb5b3c74263f5f74f0c5dcf15c04
parent 212775 141414b0f7c76ee5396f05b09529382fdbc59e8b
child 212777 caa95b3423169165143ff29bfc00079737a13302
push id9626
push userkhuey@mozilla.com
push dateWed, 29 Oct 2014 01:28:21 +0000
treeherderfx-team@544cb3ae4996 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1090598
milestone36.0a1
Bug 1090598: Once we have hit the ah_crap_handler, allow any process (such as gdb) to ptrace us. r=froydnj
toolkit/xre/nsSigHandlers.cpp
--- a/toolkit/xre/nsSigHandlers.cpp
+++ b/toolkit/xre/nsSigHandlers.cpp
@@ -21,16 +21,17 @@
 #include "nsDebug.h"
 #include "nsXULAppAPI.h"
 
 #if defined(LINUX)
 #include <sys/time.h>
 #include <sys/resource.h>
 #include <unistd.h>
 #include <stdlib.h> // atoi
+#include <sys/prctl.h>
 #ifndef ANDROID // no Android impl
 #  include <ucontext.h>
 #endif
 #endif
 
 #if defined(SOLARIS)
 #include <sys/resource.h>
 #include <ucontext.h>
@@ -39,16 +40,23 @@
 static char _progname[1024] = "huh?";
 static unsigned int _gdb_sleep_duration = 300;
 
 #if defined(LINUX) && defined(DEBUG) && \
       (defined(__i386) || defined(__x86_64) || defined(PPC))
 #define CRAWL_STACK_ON_SIGSEGV
 #endif
 
+#ifndef PR_SET_PTRACER
+#define PR_SET_PTRACER 0x59616d61
+#endif
+#ifndef PR_SET_PTRACER_ANY
+#define PR_SET_PTRACER_ANY ((unsigned long)-1)
+#endif
+
 #if defined(CRAWL_STACK_ON_SIGSEGV)
 
 #include <unistd.h>
 #include "nsISupportsUtils.h"
 #include "nsStackWalk.h"
 
 // NB: keep me up to date with the same variable in
 // ipc/chromium/chrome/common/ipc_channel_posix.cc
@@ -82,16 +90,19 @@ ah_crap_handler(int signum)
   NS_StackWalk(PrintStackFrame, /* skipFrames */ 2, /* maxFrames */ 0,
                nullptr, 0, nullptr);
 
   printf("Sleeping for %d seconds.\n",_gdb_sleep_duration);
   printf("Type 'gdb %s %d' to attach your debugger to this thread.\n",
          _progname,
          getpid());
 
+  // Allow us to be ptraced by gdb on Linux with Yama restrictions enabled.
+  prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY);
+
   sleep(_gdb_sleep_duration);
 
   printf("Done sleeping...\n");
 
   _exit(signum);
 }
 
 void