git: 4232f36eda60 - main - sshd: sync tracing disable with upstream

From: Ed Maste <emaste_at_FreeBSD.org>
Date: Mon, 07 Nov 2022 17:23:40 UTC
The branch main has been updated by emaste:

URL: https://cgit.FreeBSD.org/src/commit/?id=4232f36eda60406642fc6cfef605b6d38fc0a7c0

commit 4232f36eda60406642fc6cfef605b6d38fc0a7c0
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2022-11-07 17:17:15 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2022-11-07 17:23:00 +0000

    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 c2810f2d0b36..80488bf70104 100644
--- a/crypto/openssh/platform-tracing.c
+++ b/crypto/openssh/platform-tracing.c
@@ -32,6 +32,7 @@
 #include <stdarg.h>
 #include <stdio.h>
 #include <string.h>
+#include <unistd.h>
 
 #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