Date: Mon, 27 Jul 2026 00:30:08 +0000 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: 1e5d774279e1 - stable/15 - kern/sys_ptrace: do not skip P2_PTRACEREQ wait for PT_CLEARSTEP/PT_GET_CHILDREN Message-ID: <6a66a690.27e47.4ad73368@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch stable/15 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=1e5d774279e193eba2fb36386b637f994eba038f commit 1e5d774279e193eba2fb36386b637f994eba038f Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2026-07-20 22:09:59 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2026-07-27 00:28:43 +0000 kern/sys_ptrace: do not skip P2_PTRACEREQ wait for PT_CLEARSTEP/PT_GET_CHILDREN (cherry picked from commit eca7b25c101a240472c4c274e725bc294284c827) --- sys/kern/sys_process.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c index b5cba235de47..43cea67d1e1a 100644 --- a/sys/kern/sys_process.c +++ b/sys/kern/sys_process.c @@ -1031,7 +1031,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; @@ -1124,6 +1124,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: /* @@ -1166,26 +1167,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 @@ -1203,7 +1202,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;home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6a66a690.27e47.4ad73368>
