aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2026-07-20 22:09:59 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2026-07-21 02:58:30 +0000
commiteca7b25c101a240472c4c274e725bc294284c827 (patch)
treeeaa6619f1e0ab95e5f6498b1a9d611b298844dae
parentdeddfa3db956ebed584a859010a10b6d9a4e2e5d (diff)
kern/sys_ptrace: do not skip P2_PTRACEREQ wait for PT_CLEARSTEP/PT_GET_CHILDREN
Reported and reviewed by: markj Fixes: d3b7bbee9275 ("ptrace(2): add PT_GET_CHILDREN") Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D58364
-rw-r--r--sys/kern/sys_process.c33
1 files changed, 16 insertions, 17 deletions
diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c
index fc81ac4ca6c8..73e6b64e900b 100644
--- a/sys/kern/sys_process.c
+++ b/sys/kern/sys_process.c
@@ -1075,7 +1075,7 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data)
#ifdef COMPAT_FREEBSD32
int wrap32 = 0, safe = 0;
#endif
- bool proctree_locked, p2_req_set;
+ bool need_can_ptrace, proctree_locked, p2_req_set;
curp = td->td_proc;
proctree_locked = false;
@@ -1162,6 +1162,7 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data)
/*
* Permissions check
*/
+ need_can_ptrace = true;
switch (req) {
case PT_TRACE_ME:
/*
@@ -1204,26 +1205,24 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data)
/* OK */
break;
- case PT_CLEARSTEP:
- /* Allow thread to clear single step for itself */
- if (td->td_tid == tid)
- break;
- goto default_check;
-
- case PT_GET_CHILDREN:
- if (p == curp)
- break;
- goto default_check;
-
-default_check:
default:
/*
+ * Allow thread to clear single step for itself.
+ * PT_GET_CHILDREN on itself does not need P_TRACED.
+ */
+ if ((req == PT_CLEARSTEP && td->td_tid == tid) ||
+ (req == PT_GET_CHILDREN && p == curp))
+ need_can_ptrace = false;
+
+ /*
* Check for ptrace eligibility before waiting for
* holds to drain.
*/
- error = proc_can_ptrace(td, p);
- if (error != 0)
- goto fail;
+ if (need_can_ptrace) {
+ error = proc_can_ptrace(td, p);
+ if (error != 0)
+ goto fail;
+ }
/*
* Block parallel ptrace requests. Most important, do
@@ -1241,7 +1240,7 @@ default_check:
}
if (error == 0 && td2->td_proc != p)
error = ESRCH;
- if (error == 0)
+ if (error == 0 && need_can_ptrace)
error = proc_can_ptrace(td, p);
if (error != 0)
goto fail;