Re: [patch 3/3] attach-fail-reasons: SELinux deny_ptrace

Mark Kettenis
2012-03-06T08:35:50Z

> Date: Tue, 6 Mar 2012 07:17:39 +0100
> From: Jan Kratochvil <jan.kratochvil@redhat.com>
>
> 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.

A few comments inline below...

> --- a/gdb/gdbserver/linux-low.c
> +++ b/gdb/gdbserver/linux-low.c
> @@ -550,6 +550,25 @@ add_lwp (ptid_t ptid)
> return lwp;
> }
>
> +/* Execute PTRACE_TRACEME with error checking. */
> +
> +static void
> +linux_traceme (const char *program)
> +{
> + int save_errno;
> +
> + errno = 0;
> + if (ptrace (PTRACE_TRACEME, 0, NULL, NULL) == 0)
> + return;

Setting errno to zero here is pointless isn't it?

> + save_errno = errno;
> + linux_ptrace_create_warnings ();
> + fprintf (stderr, _("Cannot trace created process %s: %s.\n"), program,
> + strerror (save_errno));
> + fflush (stderr);
> + _exit (0177);
> +}

> --- a/gdb/inf-ptrace.c
> +++ b/gdb/inf-ptrace.c
> @@ -105,7 +105,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"),

"Cannot trace process: %s"?

> + safe_strerror (errno));
> + gdb_flush (gdb_stderr);
> + _exit (0177);
> + }
> }