diff options
author | John Baldwin <jhb@FreeBSD.org> | 2023-06-07 19:26:57 +0000 |
---|---|---|
committer | John Baldwin <jhb@FreeBSD.org> | 2023-06-07 19:28:36 +0000 |
commit | 653738e895ba022be1179a95a85089e7bc66dbbe (patch) | |
tree | 02cfbae1775eb66c0db6ebcd148c55ac5a7f9222 | |
parent | aee3611fecba4202c944803b43042ab701dac153 (diff) |
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
-rw-r--r-- | sys/kern/kern_fork.c | 2 | ||||
-rw-r--r-- | sys/kern/sys_process.c | 2 | ||||
-rw-r--r-- | sys/sys/param.h | 2 |
3 files changed, 3 insertions, 3 deletions
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c index f981747aaf70..944ecf494736 100644 --- a/sys/kern/kern_fork.c +++ b/sys/kern/kern_fork.c @@ -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. diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c index 47fdf91b87d5..41434da783c8 100644 --- a/sys/kern/sys_process.c +++ b/sys/kern/sys_process.c @@ -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) { diff --git a/sys/sys/param.h b/sys/sys/param.h index 5bdc3e2ebee4..d3577411e998 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -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, |