git: a6b7d5cddacd - main - kern_sig.c: add chicken bit for old way of SIGSTOP handling on PT_ATTACH

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Thu, 17 Apr 2025 20:45:06 UTC
The branch main has been updated by kib:

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

commit a6b7d5cddacd4aa14ee058195eedfe207a69029e
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2025-04-17 11:51:42 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2025-04-17 20:33:47 +0000

    kern_sig.c: add chicken bit for old way of SIGSTOP handling on PT_ATTACH
    
    Reviewed by:    markj
    Sponsored by:   The FreeBSD Foundation
    MFC after:      2 weeks
    Differential revision:  https://reviews.freebsd.org/D49678
---
 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 ba3b04ac6e22..91287b3c1f87 100644
--- a/sys/kern/kern_sig.c
+++ b/sys/kern/kern_sig.c
@@ -174,6 +174,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);
 
 /*
@@ -2365,7 +2370,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);
@@ -3354,7 +3360,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)) {