aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2025-05-27 21:09:18 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2025-05-29 14:28:06 +0000
commit99976934274de6fa19f049a0b6eac10856710f96 (patch)
tree6e6d7863a0d45bf0ea91a84e8a61efd155bf3dc4
parentdef0c056d3380b91ca7422d0a8727c6a4c8f6dae (diff)
PT_CONTINUE: undo transparent attach consequences
PR: 287050 Reported and tested by: Paul Floyd <pjfloyd@wanadoo.fr> Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D50556
-rw-r--r--sys/kern/sys_process.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c
index 35112f6c29d1..8b382cb3048e 100644
--- a/sys/kern/sys_process.c
+++ b/sys/kern/sys_process.c
@@ -39,6 +39,7 @@
#include <sys/mman.h>
#include <sys/mutex.h>
#include <sys/reg.h>
+#include <sys/sleepqueue.h>
#include <sys/syscallsubr.h>
#include <sys/sysent.h>
#include <sys/sysproto.h>
@@ -1347,6 +1348,27 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data)
proc_wkilled(p);
/*
+ * If the PT_CONTINUE-like operation is attempted on
+ * the thread on sleepq, this is possible only after
+ * the transparent PT_ATTACH. In this case, if the
+ * caller modified the thread state, e.g. by writing
+ * register file or specifying the pc, make the thread
+ * xstopped by waking it up.
+ */
+ if ((td2->td_dbgflags & TDB_USERWR) != 0) {
+ if (pt_attach_transparent) {
+ thread_lock(td2);
+ if (TD_ON_SLEEPQ(td2) &&
+ (td2->td_flags & TDF_SINTR) != 0) {
+ sleepq_abort(td2, EINTR);
+ } else {
+ thread_unlock(td2);
+ }
+ }
+ td2->td_dbgflags &= ~TDB_USERWR;
+ }
+
+ /*
* Unsuspend all threads. To leave a thread
* suspended, use PT_SUSPEND to suspend it before
* continuing the process.