Blob Blame History Raw
diff -Naurp insight-7.8.50.20140825.orig/gdb/config.in insight-7.8.50.20140825.new/gdb/config.in
--- insight-7.8.50.20140825.orig/gdb/config.in	2014-08-25 18:28:06.147405696 +0200
+++ insight-7.8.50.20140825.new/gdb/config.in	2014-08-25 18:29:27.175081838 +0200
@@ -219,6 +219,9 @@
 /* Define if librpm library is being used. */
 #undef HAVE_LIBRPM
 
+/* Define to 1 if you have the `selinux' library (-lselinux). */
+#undef HAVE_LIBSELINUX
+
 /* Define to 1 if you have the <libunwind-ia64.h> header file. */
 #undef HAVE_LIBUNWIND_IA64_H
 
@@ -354,6 +357,9 @@
 /* Define to 1 if you have the `scm_new_smob' function. */
 #undef HAVE_SCM_NEW_SMOB
 
+/* Define to 1 if you have the <selinux/selinux.h> header file. */
+#undef HAVE_SELINUX_SELINUX_H
+
 /* Define to 1 if you have the `setenv' function. */
 #undef HAVE_SETENV
 
diff -Naurp insight-7.8.50.20140825.orig/gdb/configure insight-7.8.50.20140825.new/gdb/configure
--- insight-7.8.50.20140825.orig/gdb/configure	2014-08-25 18:28:06.152405738 +0200
+++ insight-7.8.50.20140825.new/gdb/configure	2014-08-25 18:29:27.184081913 +0200
@@ -13574,6 +13574,64 @@ cat >>confdefs.h <<_ACEOF
 _ACEOF
 
 
+for ac_header in selinux/selinux.h
+do :
+  ac_fn_c_check_header_mongrel "$LINENO" "selinux/selinux.h" "ac_cv_header_selinux_selinux_h" "$ac_includes_default"
+if test "x$ac_cv_header_selinux_selinux_h" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_SELINUX_SELINUX_H 1
+_ACEOF
+
+fi
+
+done
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for security_get_boolean_active in -lselinux" >&5
+$as_echo_n "checking for security_get_boolean_active in -lselinux... " >&6; }
+if test "${ac_cv_lib_selinux_security_get_boolean_active+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lselinux  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char security_get_boolean_active ();
+int
+main ()
+{
+return security_get_boolean_active ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_selinux_security_get_boolean_active=yes
+else
+  ac_cv_lib_selinux_security_get_boolean_active=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_selinux_security_get_boolean_active" >&5
+$as_echo "$ac_cv_lib_selinux_security_get_boolean_active" >&6; }
+if test "x$ac_cv_lib_selinux_security_get_boolean_active" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_LIBSELINUX 1
+_ACEOF
+
+  LIBS="-lselinux $LIBS"
+
+fi
+
+
 
 # Support for --with-sysroot is a copy of GDB_AC_WITH_DIR,
 # except that the argument to --with-sysroot is optional.
diff -Naurp insight-7.8.50.20140825.orig/gdb/configure.ac insight-7.8.50.20140825.new/gdb/configure.ac
--- insight-7.8.50.20140825.orig/gdb/configure.ac	2014-08-25 18:28:06.155405763 +0200
+++ insight-7.8.50.20140825.new/gdb/configure.ac	2014-08-25 18:29:27.153081654 +0200
@@ -2161,6 +2161,10 @@ case $host_os in
 esac
 AC_DEFINE_UNQUOTED(GDBINIT,"$gdbinit",[The .gdbinit filename.])
 
+dnl Check security_get_boolean_active availability.
+AC_CHECK_HEADERS(selinux/selinux.h)
+AC_CHECK_LIB(selinux, security_get_boolean_active)
+
 dnl Handle optional features that can be enabled.
 
 # Support for --with-sysroot is a copy of GDB_AC_WITH_DIR,
diff -Naurp insight-7.8.50.20140825.orig/gdb/gdbserver/config.in insight-7.8.50.20140825.new/gdb/gdbserver/config.in
--- insight-7.8.50.20140825.orig/gdb/gdbserver/config.in	2014-08-25 14:46:22.000000000 +0200
+++ insight-7.8.50.20140825.new/gdb/gdbserver/config.in	2014-08-25 18:29:27.189081955 +0200
@@ -75,6 +75,9 @@
 /* Define to 1 if you have the `mcheck' library (-lmcheck). */
 #undef HAVE_LIBMCHECK
 
+/* Define to 1 if you have the `selinux' library (-lselinux). */
+#undef HAVE_LIBSELINUX
+
 /* Define if the target supports branch tracing. */
 #undef HAVE_LINUX_BTRACE
 
@@ -148,6 +151,9 @@
 /* Define to 1 if you have the `readlink' function. */
 #undef HAVE_READLINK
 
+/* Define to 1 if you have the <selinux/selinux.h> header file. */
+#undef HAVE_SELINUX_SELINUX_H
+
 /* Define to 1 if you have the <sgtty.h> header file. */
 #undef HAVE_SGTTY_H
 
diff -Naurp insight-7.8.50.20140825.orig/gdb/gdbserver/configure insight-7.8.50.20140825.new/gdb/gdbserver/configure
--- insight-7.8.50.20140825.orig/gdb/gdbserver/configure	2014-08-25 14:46:22.000000000 +0200
+++ insight-7.8.50.20140825.new/gdb/gdbserver/configure	2014-08-25 18:29:27.192081980 +0200
@@ -6339,6 +6339,64 @@ if $want_ipa ; then
    fi
 fi
 
+for ac_header in selinux/selinux.h
+do :
+  ac_fn_c_check_header_mongrel "$LINENO" "selinux/selinux.h" "ac_cv_header_selinux_selinux_h" "$ac_includes_default"
+if test "x$ac_cv_header_selinux_selinux_h" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_SELINUX_SELINUX_H 1
+_ACEOF
+
+fi
+
+done
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for security_get_boolean_active in -lselinux" >&5
+$as_echo_n "checking for security_get_boolean_active in -lselinux... " >&6; }
+if test "${ac_cv_lib_selinux_security_get_boolean_active+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lselinux  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char security_get_boolean_active ();
+int
+main ()
+{
+return security_get_boolean_active ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_selinux_security_get_boolean_active=yes
+else
+  ac_cv_lib_selinux_security_get_boolean_active=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_selinux_security_get_boolean_active" >&5
+$as_echo "$ac_cv_lib_selinux_security_get_boolean_active" >&6; }
+if test "x$ac_cv_lib_selinux_security_get_boolean_active" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_LIBSELINUX 1
+_ACEOF
+
+  LIBS="-lselinux $LIBS"
+
+fi
+
+
 
 
 
diff -Naurp insight-7.8.50.20140825.orig/gdb/gdbserver/configure.ac insight-7.8.50.20140825.new/gdb/gdbserver/configure.ac
--- insight-7.8.50.20140825.orig/gdb/gdbserver/configure.ac	2014-08-25 14:46:22.000000000 +0200
+++ insight-7.8.50.20140825.new/gdb/gdbserver/configure.ac	2014-08-25 18:29:27.157081688 +0200
@@ -456,6 +456,10 @@ if $want_ipa ; then
    fi
 fi
 
+dnl Check security_get_boolean_active availability.
+AC_CHECK_HEADERS(selinux/selinux.h)
+AC_CHECK_LIB(selinux, security_get_boolean_active)
+
 AC_SUBST(GDBSERVER_DEPFILES)
 AC_SUBST(GDBSERVER_LIBS)
 AC_SUBST(srv_xmlbuiltin)
diff -Naurp insight-7.8.50.20140825.orig/gdb/gdbserver/linux-low.c insight-7.8.50.20140825.new/gdb/gdbserver/linux-low.c
--- insight-7.8.50.20140825.orig/gdb/gdbserver/linux-low.c	2014-08-25 14:46:22.000000000 +0200
+++ insight-7.8.50.20140825.new/gdb/gdbserver/linux-low.c	2014-08-25 18:29:27.162081729 +0200
@@ -537,6 +537,29 @@ add_lwp (ptid_t ptid)
   return lwp;
 }
 
+/* Execute PTRACE_TRACEME with error checking.  */
+
+static void
+linux_traceme (const char *program)
+{
+  int save_errno;
+  struct buffer buffer;
+
+  errno = 0;
+  if (ptrace (PTRACE_TRACEME, 0,
+	      (PTRACE_TYPE_ARG3) 0, (PTRACE_TYPE_ARG4) 0) == 0)
+    return;
+
+  save_errno = errno;
+  buffer_init (&buffer);
+  linux_ptrace_create_warnings (&buffer);
+  buffer_grow_str0 (&buffer, "");
+  fprintf (stderr, _("%sCannot trace created process %s: %s.\n"),
+	   buffer_finish (&buffer), program, strerror (save_errno));
+  fflush (stderr);
+  _exit (0177);
+}
+
 /* Start an inferior process and returns its pid.
    ALLARGS is a vector of program-name and args. */
 
@@ -578,7 +601,7 @@ linux_create_inferior (char *program, ch
   if (pid == 0)
     {
       close_most_fds ();
-      ptrace (PTRACE_TRACEME, 0, (PTRACE_TYPE_ARG3) 0, (PTRACE_TYPE_ARG4) 0);
+      linux_traceme (program);
 
 #ifndef __ANDROID__ /* Bionic doesn't use SIGRTMIN the way glibc does.  */
       signal (__SIGRTMIN + 1, SIG_DFL);
diff -Naurp insight-7.8.50.20140825.orig/gdb/inf-ptrace.c insight-7.8.50.20140825.new/gdb/inf-ptrace.c
--- insight-7.8.50.20140825.orig/gdb/inf-ptrace.c	2014-08-25 14:46:22.000000000 +0200
+++ insight-7.8.50.20140825.new/gdb/inf-ptrace.c	2014-08-25 18:29:27.165081754 +0200
@@ -102,7 +102,15 @@ static void
 inf_ptrace_me (void)
 {
   /* "Trace me, Dr. Memory!"  */
+  errno = 0;
   ptrace (PT_TRACE_ME, 0, (PTRACE_TYPE_ARG3)0, 0);
+  if (errno != 0)
+    {
+      fprintf_unfiltered (gdb_stderr, _("Cannot create process: %s\n"),
+			  safe_strerror (errno));
+      gdb_flush (gdb_stderr);
+      _exit (0177);
+    }
 }
 
 /* Start a new inferior Unix child process.  EXEC_FILE is the file to
diff -Naurp insight-7.8.50.20140825.orig/gdb/linux-nat.c insight-7.8.50.20140825.new/gdb/linux-nat.c
--- insight-7.8.50.20140825.orig/gdb/linux-nat.c	2014-08-25 18:28:06.053404912 +0200
+++ insight-7.8.50.20140825.new/gdb/linux-nat.c	2014-08-25 18:29:27.171081805 +0200
@@ -1289,6 +1289,7 @@ linux_nat_create_inferior (struct target
 #ifdef HAVE_PERSONALITY
   int personality_orig = 0, personality_set = 0;
 #endif /* HAVE_PERSONALITY */
+  volatile struct gdb_exception ex;
 
   /* The fork_child mechanism is synchronous and calls target_wait, so
      we have to mask the async mode.  */
@@ -1313,7 +1314,10 @@ linux_nat_create_inferior (struct target
   /* Make sure we report all signals during startup.  */
   linux_nat_pass_signals (ops, 0, NULL);
 
-  linux_ops->to_create_inferior (ops, exec_file, allargs, env, from_tty);
+  TRY_CATCH (ex, RETURN_MASK_ERROR)
+    {
+      linux_ops->to_create_inferior (ops, exec_file, allargs, env, from_tty);
+    }
 
 #ifdef HAVE_PERSONALITY
   if (personality_set)
@@ -1325,6 +1329,24 @@ linux_nat_create_inferior (struct target
 		 safe_strerror (errno));
     }
 #endif /* HAVE_PERSONALITY */
+
+  if (ex.reason < 0)
+    {
+      struct buffer buffer;
+      char *message, *buffer_s;
+
+      message = xstrdup (ex.message);
+      make_cleanup (xfree, message);
+
+      buffer_init (&buffer);
+      linux_ptrace_create_warnings (&buffer);
+
+      buffer_grow_str0 (&buffer, "");
+      buffer_s = buffer_finish (&buffer);
+      make_cleanup (xfree, buffer_s);
+
+      throw_error (ex.error, "%s%s", buffer_s, message);
+    }
 }
 
 static void
diff -Naurp insight-7.8.50.20140825.orig/gdb/nat/linux-ptrace.c insight-7.8.50.20140825.new/gdb/nat/linux-ptrace.c
--- insight-7.8.50.20140825.orig/gdb/nat/linux-ptrace.c	2014-08-25 14:46:22.000000000 +0200
+++ insight-7.8.50.20140825.new/gdb/nat/linux-ptrace.c	2014-08-25 18:29:07.909921078 +0200
@@ -30,6 +30,10 @@
 
 #include <stdint.h>
 
+#ifdef HAVE_SELINUX_SELINUX_H
+# include <selinux/selinux.h>
+#endif /* HAVE_SELINUX_SELINUX_H */
+
 /* Stores the currently supported ptrace options.  A value of
    -1 means we did not check for features yet.  A value of 0 means
    there are no supported features.  */
@@ -58,6 +62,8 @@ linux_ptrace_attach_fail_reason (pid_t p
     buffer_xml_printf (buffer, _("process %d is a zombie "
 				 "- the process has already terminated"),
 		       (int) pid);
+
+  linux_ptrace_create_warnings (buffer);
 }
 
 #if defined __i386__ || defined __x86_64__
@@ -555,3 +561,19 @@ linux_ptrace_set_additional_flags (int f
 {
   additional_flags = flags;
 }
+
+/* Print all possible reasons we could fail to create a traced process.  */
+
+void
+linux_ptrace_create_warnings (struct buffer *buffer)
+{
+#ifdef HAVE_LIBSELINUX
+  /* -1 is returned for errors, 0 if it has no effect, 1 if PTRACE_ATTACH is
+     forbidden.  */
+  if (security_get_boolean_active ("deny_ptrace") == 1)
+    buffer_xml_printf (buffer,
+		       _("the SELinux boolean 'deny_ptrace' is enabled, "
+			 "you can disable this process attach protection by: "
+			 "(gdb) shell sudo setsebool deny_ptrace=0"));
+#endif /* HAVE_LIBSELINUX */
+}
diff -Naurp insight-7.8.50.20140825.orig/gdb/nat/linux-ptrace.h insight-7.8.50.20140825.new/gdb/nat/linux-ptrace.h
--- insight-7.8.50.20140825.orig/gdb/nat/linux-ptrace.h	2014-07-25 15:10:37.000000000 +0200
+++ insight-7.8.50.20140825.new/gdb/nat/linux-ptrace.h	2014-08-25 18:29:27.149081621 +0200
@@ -85,6 +85,7 @@ struct buffer;
 
 extern void linux_ptrace_attach_fail_reason (pid_t pid, struct buffer *buffer);
 extern void linux_ptrace_init_warnings (void);
+extern void linux_ptrace_create_warnings (struct buffer *buffer);
 extern void linux_enable_event_reporting (pid_t pid);
 extern void linux_disable_event_reporting (pid_t pid);
 extern int linux_supports_tracefork (void);