git: 2b11b13b04bd - stable/14 - kern_sig.c: add chicken bit for old way of SIGSTOP handling on PT_ATTACH

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Sat, 03 May 2025 15:20:01 UTC
The branch stable/14 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=2b11b13b04bd4b5a0519850d35b334fe420502ca

commit 2b11b13b04bd4b5a0519850d35b334fe420502ca
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2025-04-17 11:51:42 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2025-05-03 15:19:41 +0000

    kern_sig.c: add chicken bit for old way of SIGSTOP handling on PT_ATTACH
    
    (cherry picked from commit a6b7d5cddacd4aa14ee058195eedfe207a69029e)
---
 sys/kern/kern_sig.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c
index 4df052629828..06da39b8cb33 100644
--- a/sys/kern/kern_sig.c
+++ b/sys/kern/kern_sig.c
@@ -176,6 +176,11 @@ SYSCTL_BOOL(_kern, OID_AUTO, sig_discard_ign, CTLFLAG_RWTUN,
     "Discard ignored signals on delivery, otherwise queue them to "
     "the target queue");
 
+static bool pt_attach_transparent = true;
+SYSCTL_BOOL(_debug, OID_AUTO, ptrace_attach_transparent, CTLFLAG_RWTUN,
+    &pt_attach_transparent, 0,
+    "Hide wakes from PT_ATTACH on interruptible sleeps");
+
 SYSINIT(signal, SI_SUB_P1003_1B, SI_ORDER_FIRST+3, sigqueue_start, NULL);
 
 /*
@@ -2361,7 +2366,8 @@ tdsendsignal(struct proc *p, struct thread *td, int sig, ksiginfo_t *ksi)
 	if (prop & SIGPROP_CONT)
 		sigqueue_delete_stopmask_proc(p);
 	else if (prop & SIGPROP_STOP) {
-		if ((p->p_flag & P_TRACED) != 0 &&
+		if (pt_attach_transparent &&
+		    (p->p_flag & P_TRACED) != 0 &&
 		    (p->p_flag2 & P2_PTRACE_FSTP) != 0) {
 			td->td_dbgflags |= TDB_FSTP;
 			PROC_SLOCK(p);
@@ -3364,7 +3370,7 @@ issignal(struct thread *td)
 			}
 		}
 
-		if (false &&
+		if (!pt_attach_transparent &&
 		    (p->p_flag & (P_TRACED | P_PPTRACE)) == P_TRACED &&
 		    (p->p_flag2 & P2_PTRACE_FSTP) != 0 &&
 		    SIGISMEMBER(sigpending, SIGSTOP)) {