⬢ DragonFlyBSD Kernel Audit
DF-3226 / fix.diff
← back to finding ↓ download raw
--- a/sys/vfs/procfs/procfs_ctl.c
+++ b/sys/vfs/procfs/procfs_ctl.c
@@ -115,11 +115,15 @@
 		return EAGAIN;
 	/*
 	 * Authorization check: rely on normal debugging protection, except
-	 * allow processes to disengage debugging on a process onto which
-	 * they have previously attached, but no longer have permission to
-	 * debug.
+	 * allow the current tracer to disengage debugging on a process
+	 * onto which it has previously attached, but no longer has
+	 * permission to debug (mirrors PT_DETACH in sys_process.c, which
+	 * requires the requester to be the tracer).
 	 */
-	if (op != PROCFS_CTL_DETACH) {
+	if (op == PROCFS_CTL_DETACH) {
+		if ((p->p_flags & P_TRACED) && p->p_pptr != curp)
+			return (EPERM);
+	} else {
 		if (securelevel > 0 && p->p_pid == 1)
 			return (EPERM);