ptrace: Clear TDB_BORN during PT_DETACH.

If a debugger detaches from a process that has a new thread that has
not yet executed, the new thread will raise a SIGTRAP signal to report
it's thread birth event even after the detach.  With the debugger
detached, this results in a SIGTRAP sent to the process and typically
a core dump.  Fix this by clearing TDB_BORN from any new threads
during detach.

Bump __FreeBSD_version for debuggers to notice when the fix is
present.

Reported by:	GDB's testsuite
Reviewed by:	kib, markj (previous version)
Differential Revision:	https://reviews.freebsd.org/D39856
This commit is contained in:
John Baldwin 2023-06-07 12:26:57 -07:00
parent aee3611fec
commit 653738e895
3 changed files with 3 additions and 3 deletions

View file

@ -1144,7 +1144,7 @@ fork_return(struct thread *td, struct trapframe *frame)
td->td_dbgflags &= ~TDB_STOPATFORK;
}
PROC_UNLOCK(p);
} else if (p->p_flag & P_TRACED || td->td_dbgflags & TDB_BORN) {
} else if (p->p_flag & P_TRACED) {
/*
* This is the start of a new thread in a traced
* process. Report a system call exit event.

View file

@ -1288,7 +1288,7 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data)
SIGSTOP);
}
td3->td_dbgflags &= ~(TDB_XSIG | TDB_FSTP |
TDB_SUSPEND);
TDB_SUSPEND | TDB_BORN);
}
if ((p->p_flag2 & P2_PTRACE_FSTP) != 0) {

View file

@ -76,7 +76,7 @@
* cannot include sys/param.h and should only be updated here.
*/
#undef __FreeBSD_version
#define __FreeBSD_version 1400089
#define __FreeBSD_version 1400090
/*
* __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,