Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 3 May 2025 15:20:03 GMT
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: a86e21e2caaa - stable/14 - ptrace(): p_xthread could be NULL for P_STOPPED_TRACE
Message-ID:  <202505031520.543FK3xd048230@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by kib:

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

commit a86e21e2caaa9796308282a235bdb42bd3c71292
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2025-04-20 23:19:35 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2025-05-03 15:19:41 +0000

    ptrace(): p_xthread could be NULL for P_STOPPED_TRACE
    
    (cherry picked from commit b63281884e0e1530de999723532f2d536cb32477)
---
 sys/kern/sys_process.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c
index 497084f83563..d4c0737a4769 100644
--- a/sys/kern/sys_process.c
+++ b/sys/kern/sys_process.c
@@ -936,12 +936,10 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data)
 	}
 
 	if (tid == 0) {
-		if ((p->p_flag & P_STOPPED_TRACE) != 0) {
-			KASSERT(p->p_xthread != NULL, ("NULL p_xthread"));
+		if ((p->p_flag & P_STOPPED_TRACE) != 0)
 			td2 = p->p_xthread;
-		} else {
+		if (td2 == NULL)
 			td2 = FIRST_THREAD_IN_PROC(p);
-		}
 		tid = td2->td_tid;
 	}
 
@@ -1328,16 +1326,19 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data)
 
 		/*
 		 * Clear the pending event for the thread that just
-		 * reported its event (p_xthread).  This may not be
-		 * the thread passed to PT_CONTINUE, PT_STEP, etc. if
-		 * the debugger is resuming a different thread.
+		 * reported its event (p_xthread), if any.  This may
+		 * not be the thread passed to PT_CONTINUE, PT_STEP,
+		 * etc. if the debugger is resuming a different
+		 * thread.  There might be no reporting thread if
+		 * the process was just attached.
 		 *
 		 * Deliver any pending signal via the reporting thread.
 		 */
-		MPASS(p->p_xthread != NULL);
-		p->p_xthread->td_dbgflags &= ~TDB_XSIG;
-		p->p_xthread->td_xsig = data;
-		p->p_xthread = NULL;
+		if (p->p_xthread != NULL) {
+			p->p_xthread->td_dbgflags &= ~TDB_XSIG;
+			p->p_xthread->td_xsig = data;
+			p->p_xthread = NULL;
+		}
 		p->p_xsig = data;
 
 		/*



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202505031520.543FK3xd048230>