Disable tracing on FreeBSD using procctl. (OpenSSH Portable 8.8)

Ed Maste emaste at freebsd.org
Mon Nov 7 08:25:43 AEDT 2022


On Sun, 6 Nov 2022 at 15:14, Darren Tucker <dtucker at dtucker.net> wrote:
>
> I had something similar but a bit more compact and commented.  Does this
> also work?
>
> diff --git a/platform-tracing.c b/platform-tracing.c
> index c2810f2d..a8ce078b 100644
> --- a/platform-tracing.c
> +++ b/platform-tracing.c
> @@ -32,6 +32,7 @@
>  #include <stdarg.h>
>  #include <stdio.h>
>  #include <string.h>
> +#include <unistd.h>
>
>  #include "log.h"
>
> @@ -39,10 +40,16 @@ void
>  platform_disable_tracing(int strict)
>  {
>  #if defined(HAVE_PROCCTL) && defined(PROC_TRACE_CTL)
> -       /* On FreeBSD, we should make this process untraceable */
> +       /*
> +        * On FreeBSD, we should make this process untraceable.
> +        * pid=0 means "this process" and but some older kernels do not
> +        * understand that, so retry with our own pid before failing.
> +        */
>         int disable_trace = PROC_TRACE_CTL_DISABLE;
>
> -       if (procctl(P_PID, 0, PROC_TRACE_CTL, &disable_trace) && strict)
> +       if (procctl(P_PID, 0, PROC_TRACE_CTL, &disable_trace) == -1 &&
> +           procctl(P_PID, getpid(), PROC_TRACE_CTL, &disable_trace) == -1 &&
> +           strict)
>                 fatal("unable to make the process untraceable: %s",
>                     strerror(errno));
>  #endif

Looks good to me, even if I think the multi-stage short-circuit is a
little less clear.


More information about the openssh-unix-dev mailing list