The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=9b21a52495758294e3a50542a59bc47a0c184173
commit 9b21a52495758294e3a50542a59bc47a0c184173 Author: Konstantin Belousov <[email protected]> AuthorDate: 2026-07-19 01:14:39 +0000 Commit: Konstantin Belousov <[email protected]> CommitDate: 2026-07-19 14:48:46 +0000 kern_ptrace(): reduce code duplication Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D58334 --- sys/kern/sys_process.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c index d3f8e4c81669..2ac0a33c3421 100644 --- a/sys/kern/sys_process.c +++ b/sys/kern/sys_process.c @@ -923,7 +923,7 @@ ptrace_unsuspend(struct proc *p) } static int -proc_can_ptrace(struct thread *td, struct proc *p) +proc_can_ptrace1(struct thread *td, struct proc *p) { int error; @@ -931,11 +931,22 @@ proc_can_ptrace(struct thread *td, struct proc *p) if ((p->p_flag & P_WEXIT) != 0) return (ESRCH); - if ((error = p_cansee(td, p)) != 0) return (error); if ((error = p_candebug(td, p)) != 0) return (error); + return (0); +} + +static int +proc_can_ptrace(struct thread *td, struct proc *p) +{ + int error; + + PROC_LOCK_ASSERT(p, MA_OWNED); + + if ((error = proc_can_ptrace1(td, p)) != 0) + return (error); /* not being traced... */ if ((p->p_flag & P_TRACED) == 0) @@ -1041,14 +1052,8 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data) } AUDIT_ARG_PROCESS(p); - if ((p->p_flag & P_WEXIT) != 0) { - error = ESRCH; - goto fail; - } - if ((error = p_cansee(td, p)) != 0) - goto fail; - - if ((error = p_candebug(td, p)) != 0) + error = proc_can_ptrace1(td, p); + if (error != 0) goto fail; /*
