diff options
author | John Baldwin <jhb@FreeBSD.org> | 2023-06-07 19:26:57 +0000 |
---|---|---|
committer | John Baldwin <jhb@FreeBSD.org> | 2023-09-06 21:56:09 +0000 |
commit | 21ccba43f511cc4089899619b5a85e6d83a200dc (patch) | |
tree | 2eb3c33f3d8892768d2899ea164dd33e53d57362 | |
parent | b086848fc0862468cba5d736f60f2882b2119c30 (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
(cherry picked from commit 653738e895ba022be1179a95a85089e7bc66dbbe)
-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 157eba2b3fbc..e3148763b460 100644 --- a/sys/kern/kern_fork.c +++ b/sys/kern/kern_fork.c @@ -1195,7 +1195,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 6f53f1ae43b4..2eaeabb6a5f9 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 376d1aaa2187..ba64cfa4b5df 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -59,7 +59,7 @@ * in the range 5 to 9. */ #undef __FreeBSD_version -#define __FreeBSD_version 1302507 /* Master, propagated to newvers */ +#define __FreeBSD_version 1302508 /* Master, propagated to newvers */ /* * __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD, |