Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 13 Jun 2021 01:45:01 GMT
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: 31df316c108b - stable/13 - ktrace: do not stop tracing other processes if our cannot write to this vnode
Message-ID:  <202106130145.15D1j1GS051832@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=31df316c108b073478f3b04eef422abd8011018b

commit 31df316c108b073478f3b04eef422abd8011018b
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2021-05-15 00:10:05 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2021-06-13 01:22:33 +0000

    ktrace: do not stop tracing other processes if our cannot write to this vnode
    
    (cherry picked from commit a6144f713cee8f522150b1398b225eedbf4cfef1)
---
 sys/kern/kern_ktrace.c | 53 ++++++++++++++++++--------------------------------
 1 file changed, 19 insertions(+), 34 deletions(-)

diff --git a/sys/kern/kern_ktrace.c b/sys/kern/kern_ktrace.c
index d0f7e0067064..26fba786e1e9 100644
--- a/sys/kern/kern_ktrace.c
+++ b/sys/kern/kern_ktrace.c
@@ -1192,7 +1192,7 @@ ktr_writerequest(struct thread *td, struct ktr_request *req)
 	struct uio auio;
 	struct iovec aiov[3];
 	struct mount *mp;
-	int datalen, buflen, vrele_count;
+	int datalen, buflen;
 	int error;
 
 	/*
@@ -1266,44 +1266,29 @@ ktr_writerequest(struct thread *td, struct ktr_request *req)
 	}
 
 	/*
-	 * If error encountered, give up tracing on this vnode.  We defer
-	 * all the vrele()'s on the vnode until after we are finished walking
-	 * the various lists to avoid needlessly holding locks.
-	 * NB: at this point we still hold the vnode reference that must
-	 * not go away as we need the valid vnode to compare with. Thus let
-	 * vrele_count start at 1 and the reference will be freed
-	 * by the loop at the end after our last use of vp.
-	 */
-	log(LOG_NOTICE, "ktrace write failed, errno %d, tracing stopped\n",
-	    error);
-	vrele_count = 1;
-	/*
-	 * First, clear this vnode from being used by any processes in the
-	 * system.
-	 * XXX - If one process gets an EPERM writing to the vnode, should
-	 * we really do this?  Other processes might have suitable
-	 * credentials for the operation.
+	 * If error encountered, give up tracing on this vnode on this
+	 * process.  Other processes might still be suitable for
+	 * writes to this vnode.
 	 */
+	p = td->td_proc;
+	log(LOG_NOTICE,
+	    "ktrace write failed, errno %d, tracing stopped for pid %d\n",
+	    error, p->p_pid);
 	cred = NULL;
 	sx_slock(&allproc_lock);
-	FOREACH_PROC_IN_SYSTEM(p) {
-		PROC_LOCK(p);
-		if (p->p_tracevp == vp) {
-			mtx_lock(&ktrace_mtx);
-			ktr_freeproc(p, &cred, NULL);
-			mtx_unlock(&ktrace_mtx);
-			vrele_count++;
-		}
-		PROC_UNLOCK(p);
-		if (cred != NULL) {
-			crfree(cred);
-			cred = NULL;
-		}
+	PROC_LOCK(p);
+	mtx_lock(&ktrace_mtx);
+	if (p->p_tracevp == vp)
+		ktr_freeproc(p, &cred, NULL);
+	mtx_unlock(&ktrace_mtx);
+	PROC_UNLOCK(p);
+	if (cred != NULL) {
+		crfree(cred);
+		cred = NULL;
 	}
 	sx_sunlock(&allproc_lock);
-
-	while (vrele_count-- > 0)
-		vrele(vp);
+	vrele(vp);
+	vrele(vp);
 }
 
 /*



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202106130145.15D1j1GS051832>