aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2026-07-19 01:14:39 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2026-07-19 14:48:46 +0000
commit9b21a52495758294e3a50542a59bc47a0c184173 (patch)
tree8a117e33d8e69fc25f6b6a7d661af24e14710f9b
parent11edc985cd9c2e1dcceccb7e929c6921b4e20c9b (diff)
kern_ptrace(): reduce code duplication
Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D58334
-rw-r--r--sys/kern/sys_process.c25
1 files 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;
/*