Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 27 Jul 2026 00:30:12 +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: 88409417be88 - stable/15 - kern_ptrace(): reduce code duplication
Message-ID:  <6a66a694.278f0.39e792bd@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=88409417be8847b94fa2702eb727d6102f620af2

commit 88409417be8847b94fa2702eb727d6102f620af2
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-07-19 01:14:39 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-07-27 00:28:44 +0000

    kern_ptrace(): reduce code duplication
    
    (cherry picked from commit 9b21a52495758294e3a50542a59bc47a0c184173)
---
 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 43cea67d1e1a..9ba8ec33e5dc 100644
--- a/sys/kern/sys_process.c
+++ b/sys/kern/sys_process.c
@@ -906,7 +906,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;
 
@@ -914,11 +914,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)
@@ -1084,14 +1095,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;
 
 	/*


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6a66a694.278f0.39e792bd>