2017-12-10 22:00:49 +00:00
|
|
|
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
|
2017-12-04 19:24:00 +00:00
|
|
|
From: Fedora GDB patches <invalid@email.com>
|
|
|
|
Date: Fri, 27 Oct 2017 21:07:50 +0200
|
2018-06-19 00:10:24 +00:00
|
|
|
Subject: gdb-attach-fail-reasons-5of5.patch
|
2017-12-04 19:24:00 +00:00
|
|
|
|
2017-12-08 04:31:26 +00:00
|
|
|
;; Print reasons for failed attach/spawn incl. SELinux deny_ptrace (BZ 786878).
|
|
|
|
;;=push+jan
|
2017-12-04 19:24:00 +00:00
|
|
|
|
|
|
|
http://sourceware.org/ml/gdb-patches/2012-03/msg00171.html
|
|
|
|
|
2012-03-06 06:57:07 +00:00
|
|
|
Hi,
|
|
|
|
|
|
|
|
and here is the last bit for new SELinux 'deny_ptrace':
|
|
|
|
https://bugzilla.redhat.com/show_bug.cgi?id=786878
|
|
|
|
|
|
|
|
As even PTRACE_TRACEME fails in such case it needs to install hook for even
|
|
|
|
that event.
|
|
|
|
|
|
|
|
Thanks,
|
|
|
|
Jan
|
|
|
|
|
|
|
|
gdb/
|
|
|
|
2012-03-06 Jan Kratochvil <jan.kratochvil@redhat.com>
|
|
|
|
|
|
|
|
* common/linux-ptrace.c [HAVE_SELINUX_SELINUX_H]: include
|
|
|
|
selinux/selinux.h.
|
|
|
|
(linux_ptrace_attach_warnings): Call linux_ptrace_create_warnings.
|
|
|
|
(linux_ptrace_create_warnings): New.
|
|
|
|
* common/linux-ptrace.h (linux_ptrace_create_warnings): New declaration.
|
|
|
|
* config.in: Regenerate.
|
|
|
|
* configure: Regenerate.
|
|
|
|
* configure.ac: Check selinux/selinux.h and the selinux library.
|
|
|
|
* inf-ptrace.c (inf_ptrace_me): Check the ptrace result.
|
|
|
|
* linux-nat.c (linux_nat_create_inferior): New variable ex. Wrap
|
|
|
|
to_create_inferior into TRY_CATCH, call linux_ptrace_create_warnings.
|
|
|
|
|
|
|
|
gdb/gdbserver/
|
|
|
|
* config.in: Regenerate.
|
|
|
|
* configure: Regenerate.
|
|
|
|
* configure.ac: Check selinux/selinux.h and the selinux library.
|
|
|
|
* linux-low.c (linux_traceme): New function.
|
|
|
|
(linux_create_inferior, linux_tracefork_child): Call it instead of
|
|
|
|
direct ptrace.
|
|
|
|
|
2017-12-08 04:31:26 +00:00
|
|
|
diff --git a/gdb/config.in b/gdb/config.in
|
|
|
|
--- a/gdb/config.in
|
|
|
|
+++ b/gdb/config.in
|
2018-05-31 18:47:56 +00:00
|
|
|
@@ -276,6 +276,9 @@
|
2013-08-02 20:26:03 +00:00
|
|
|
/* 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
|
|
|
|
|
2018-05-31 18:47:56 +00:00
|
|
|
@@ -399,6 +402,9 @@
|
2014-06-19 20:14:32 +00:00
|
|
|
/* Define to 1 if you have the `scm_new_smob' function. */
|
|
|
|
#undef HAVE_SCM_NEW_SMOB
|
2013-08-02 20:26:03 +00:00
|
|
|
|
|
|
|
+/* Define to 1 if you have the <selinux/selinux.h> header file. */
|
|
|
|
+#undef HAVE_SELINUX_SELINUX_H
|
|
|
|
+
|
2014-10-30 21:21:18 +00:00
|
|
|
/* Define to 1 if you have the `setlocale' function. */
|
|
|
|
#undef HAVE_SETLOCALE
|
2013-08-02 20:26:03 +00:00
|
|
|
|
2017-12-08 04:31:26 +00:00
|
|
|
diff --git a/gdb/configure b/gdb/configure
|
|
|
|
--- a/gdb/configure
|
|
|
|
+++ b/gdb/configure
|
2018-06-29 23:32:31 +00:00
|
|
|
@@ -15854,6 +15854,64 @@ cat >>confdefs.h <<_ACEOF
|
2013-08-02 20:26:03 +00:00
|
|
|
_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.
|
2017-12-08 04:31:26 +00:00
|
|
|
diff --git a/gdb/configure.ac b/gdb/configure.ac
|
|
|
|
--- a/gdb/configure.ac
|
|
|
|
+++ b/gdb/configure.ac
|
2018-06-29 23:32:31 +00:00
|
|
|
@@ -2054,6 +2054,10 @@ case $host_os in
|
2017-12-08 04:31:26 +00:00
|
|
|
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 --git a/gdb/gdbserver/config.in b/gdb/gdbserver/config.in
|
|
|
|
--- a/gdb/gdbserver/config.in
|
|
|
|
+++ b/gdb/gdbserver/config.in
|
|
|
|
@@ -126,6 +126,9 @@
|
2014-02-07 18:38:14 +00:00
|
|
|
/* Define to 1 if you have the `mcheck' library (-lmcheck). */
|
|
|
|
#undef HAVE_LIBMCHECK
|
2013-08-02 20:26:03 +00:00
|
|
|
|
|
|
|
+/* Define to 1 if you have the `selinux' library (-lselinux). */
|
|
|
|
+#undef HAVE_LIBSELINUX
|
|
|
|
+
|
|
|
|
/* Define if the target supports branch tracing. */
|
|
|
|
#undef HAVE_LINUX_BTRACE
|
|
|
|
|
2017-12-08 04:31:26 +00:00
|
|
|
@@ -202,6 +205,9 @@
|
2015-11-14 16:06:06 +00:00
|
|
|
/* Define to 1 if you have the `pwrite' function. */
|
|
|
|
#undef HAVE_PWRITE
|
2013-08-02 20:26:03 +00:00
|
|
|
|
|
|
|
+/* Define to 1 if you have the <selinux/selinux.h> header file. */
|
|
|
|
+#undef HAVE_SELINUX_SELINUX_H
|
|
|
|
+
|
2015-11-14 16:06:06 +00:00
|
|
|
/* Define to 1 if you have the `setns' function. */
|
|
|
|
#undef HAVE_SETNS
|
2013-08-02 20:26:03 +00:00
|
|
|
|
2017-12-08 04:31:26 +00:00
|
|
|
diff --git a/gdb/gdbserver/configure b/gdb/gdbserver/configure
|
|
|
|
--- a/gdb/gdbserver/configure
|
|
|
|
+++ b/gdb/gdbserver/configure
|
2018-06-27 19:50:46 +00:00
|
|
|
@@ -8535,6 +8535,64 @@ if $want_ipa ; then
|
2013-08-02 20:26:03 +00:00
|
|
|
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
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-12-08 04:31:26 +00:00
|
|
|
diff --git a/gdb/gdbserver/configure.ac b/gdb/gdbserver/configure.ac
|
|
|
|
--- a/gdb/gdbserver/configure.ac
|
|
|
|
+++ b/gdb/gdbserver/configure.ac
|
2018-06-27 19:50:46 +00:00
|
|
|
@@ -486,6 +486,10 @@ if $want_ipa ; then
|
2017-12-08 04:31:26 +00:00
|
|
|
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 --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
|
|
|
|
--- a/gdb/gdbserver/linux-low.c
|
|
|
|
+++ b/gdb/gdbserver/linux-low.c
|
2018-06-05 19:25:07 +00:00
|
|
|
@@ -967,7 +967,16 @@ linux_ptrace_fun ()
|
2017-12-08 04:31:26 +00:00
|
|
|
{
|
|
|
|
if (ptrace (PTRACE_TRACEME, 0, (PTRACE_TYPE_ARG3) 0,
|
|
|
|
(PTRACE_TYPE_ARG4) 0) < 0)
|
|
|
|
- trace_start_error_with_name ("ptrace");
|
|
|
|
+ {
|
|
|
|
+ int save_errno = errno;
|
|
|
|
+
|
2018-05-31 18:47:56 +00:00
|
|
|
+ std::string msg (linux_ptrace_create_warnings ());
|
2017-12-08 04:31:26 +00:00
|
|
|
+
|
2018-05-31 18:47:56 +00:00
|
|
|
+ msg += _("Cannot trace created process");
|
2017-12-08 04:31:26 +00:00
|
|
|
+
|
|
|
|
+ errno = save_errno;
|
|
|
|
+ trace_start_error_with_name (msg.c_str ());
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if (setpgid (0, 0) < 0)
|
|
|
|
trace_start_error_with_name ("setpgid");
|
|
|
|
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
|
|
|
|
--- a/gdb/linux-nat.c
|
|
|
|
+++ b/gdb/linux-nat.c
|
2018-05-31 18:47:56 +00:00
|
|
|
@@ -1088,7 +1088,17 @@ linux_nat_target::create_inferior (const char *exec_file,
|
2017-12-08 04:31:26 +00:00
|
|
|
/* Make sure we report all signals during startup. */
|
2018-05-31 18:47:56 +00:00
|
|
|
pass_signals (0, NULL);
|
2017-12-08 04:31:26 +00:00
|
|
|
|
2018-05-31 18:47:56 +00:00
|
|
|
- inf_ptrace_target::create_inferior (exec_file, allargs, env, from_tty);
|
2017-12-08 04:31:26 +00:00
|
|
|
+ TRY
|
|
|
|
+ {
|
2018-05-31 18:47:56 +00:00
|
|
|
+ inf_ptrace_target::create_inferior (exec_file, allargs, env, from_tty);
|
2017-12-08 04:31:26 +00:00
|
|
|
+ }
|
|
|
|
+ CATCH (ex, RETURN_MASK_ERROR)
|
|
|
|
+ {
|
2018-05-31 18:47:56 +00:00
|
|
|
+ std::string result = linux_ptrace_create_warnings ();
|
2017-12-08 04:31:26 +00:00
|
|
|
+
|
2018-05-31 18:47:56 +00:00
|
|
|
+ throw_error (ex.error, "%s%s", result.c_str (), ex.message);
|
2017-12-08 04:31:26 +00:00
|
|
|
+ }
|
|
|
|
+ END_CATCH
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Callback for linux_proc_attach_tgid_threads. Attach to PTID if not
|
|
|
|
diff --git a/gdb/nat/linux-ptrace.c b/gdb/nat/linux-ptrace.c
|
|
|
|
--- a/gdb/nat/linux-ptrace.c
|
|
|
|
+++ b/gdb/nat/linux-ptrace.c
|
2018-05-31 18:47:56 +00:00
|
|
|
@@ -25,6 +25,10 @@
|
2017-12-08 04:31:26 +00:00
|
|
|
#include <sys/procfs.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
+#ifdef HAVE_SELINUX_SELINUX_H
|
|
|
|
+# include <selinux/selinux.h>
|
|
|
|
+#endif /* HAVE_SELINUX_SELINUX_H */
|
|
|
|
+
|
|
|
|
/* Stores the ptrace options supported by the running kernel.
|
|
|
|
A value of -1 means we did not check for features yet. A value
|
|
|
|
of 0 means there are no supported features. */
|
2018-05-31 18:47:56 +00:00
|
|
|
@@ -50,6 +54,8 @@ linux_ptrace_attach_fail_reason (pid_t pid)
|
|
|
|
"terminated"),
|
|
|
|
(int) pid);
|
|
|
|
|
|
|
|
+ result += linux_ptrace_create_warnings ();
|
2017-12-08 04:31:26 +00:00
|
|
|
+
|
2018-05-31 18:47:56 +00:00
|
|
|
return result;
|
2017-12-08 04:31:26 +00:00
|
|
|
}
|
|
|
|
|
2018-05-31 18:47:56 +00:00
|
|
|
@@ -583,6 +589,25 @@ linux_ptrace_init_warnings (void)
|
2017-12-08 04:31:26 +00:00
|
|
|
linux_ptrace_test_ret_to_nx ();
|
|
|
|
}
|
|
|
|
|
|
|
|
+/* Print all possible reasons we could fail to create a traced process. */
|
|
|
|
+
|
2018-05-31 18:47:56 +00:00
|
|
|
+std::string
|
|
|
|
+linux_ptrace_create_warnings ()
|
2017-12-08 04:31:26 +00:00
|
|
|
+{
|
2018-05-31 18:47:56 +00:00
|
|
|
+ std::string result;
|
|
|
|
+
|
2017-12-08 04:31:26 +00:00
|
|
|
+#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)
|
2018-05-31 18:47:56 +00:00
|
|
|
+ string_appendf (result,
|
|
|
|
+ _("the SELinux boolean 'deny_ptrace' is enabled, "
|
|
|
|
+ "you can disable this process attach protection by: "
|
|
|
|
+ "(gdb) shell sudo setsebool deny_ptrace=0\n"));
|
2017-12-08 04:31:26 +00:00
|
|
|
+#endif /* HAVE_LIBSELINUX */
|
2018-05-31 18:47:56 +00:00
|
|
|
+ return result;
|
2017-12-08 04:31:26 +00:00
|
|
|
+}
|
|
|
|
+
|
|
|
|
/* Extract extended ptrace event from wait status. */
|
|
|
|
|
|
|
|
int
|
|
|
|
diff --git a/gdb/nat/linux-ptrace.h b/gdb/nat/linux-ptrace.h
|
|
|
|
--- a/gdb/nat/linux-ptrace.h
|
|
|
|
+++ b/gdb/nat/linux-ptrace.h
|
2018-06-05 19:25:07 +00:00
|
|
|
@@ -184,6 +184,7 @@ extern std::string linux_ptrace_attach_fail_reason (pid_t pid);
|
2018-05-31 18:47:56 +00:00
|
|
|
extern std::string linux_ptrace_attach_fail_reason_string (ptid_t ptid, int err);
|
2017-12-08 04:31:26 +00:00
|
|
|
|
|
|
|
extern void linux_ptrace_init_warnings (void);
|
2018-05-31 18:47:56 +00:00
|
|
|
+extern std::string linux_ptrace_create_warnings ();
|
2017-12-08 04:31:26 +00:00
|
|
|
extern void linux_check_ptrace_features (void);
|
|
|
|
extern void linux_enable_event_reporting (pid_t pid, int attached);
|
|
|
|
extern void linux_disable_event_reporting (pid_t pid);
|