From 4232f36eda60406642fc6cfef605b6d38fc0a7c0 Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Mon, 7 Nov 2022 12:17:15 -0500 Subject: [PATCH] sshd: sync tracing disable with upstream Old versions of FreeBSD do not support using id 0 to refer to the current pid for procctl, so pass getpid() explicitly. Although this is not required in current FreeBSD branches I am merging it to reduce differences with upstream. Obtained from: OpenSSH commit 0f7e1eba5525 --- crypto/openssh/platform-tracing.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/crypto/openssh/platform-tracing.c b/crypto/openssh/platform-tracing.c index c2810f2d0b3..80488bf7010 100644 --- a/crypto/openssh/platform-tracing.c +++ b/crypto/openssh/platform-tracing.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "log.h" @@ -42,7 +43,16 @@ platform_disable_tracing(int strict) /* On FreeBSD, we should make this process untraceable */ int disable_trace = PROC_TRACE_CTL_DISABLE; - if (procctl(P_PID, 0, PROC_TRACE_CTL, &disable_trace) && strict) + /* + * 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. + */ + if (procctl(P_PID, 0, PROC_TRACE_CTL, &disable_trace) == 0) + return; + if (procctl(P_PID, getpid(), PROC_TRACE_CTL, &disable_trace) == 0) + return; + if (strict) fatal("unable to make the process untraceable: %s", strerror(errno)); #endif