Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 14 Feb 2025 15:56:46 GMT
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 36631977d8c9 - main - ktr: Use STAILQ_EMPTY_ATOMIC when checking for records in ktr_drain()
Message-ID:  <202502141556.51EFukh4046185@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=36631977d8c9264b7a54f039289918adea4d2a03

commit 36631977d8c9264b7a54f039289918adea4d2a03
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2025-02-14 15:49:27 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2025-02-14 15:52:29 +0000

    ktr: Use STAILQ_EMPTY_ATOMIC when checking for records in ktr_drain()
    
    This is an unlocked check, and after commit 34740937f7a4 the debug
    checks in STAILQ_EMPTY may spuriously fail here.  In particular, the per
    process queue is updated under the global ktrace mutex, not held in
    ktr_drain().  If a record is enqueued concurrently, the recording thread
    will schedule an AST to drain the queue again, so it should not be
    possible for a race to leave records in the queue indefinitely.
    
    Reviewed by:    kib, olce
    Reported by:    syzbot+d67eddd8c4923ee28bb7@syzkaller.appspotmail.com
    MFC after:      2 weeks
    Fixes:          34740937f7a4 ("queue: New debug macros for STAILQ")
    Differential Revision:  https://reviews.freebsd.org/D48899
---
 sys/kern/kern_ktrace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/kern/kern_ktrace.c b/sys/kern/kern_ktrace.c
index a67b773a154c..7a5846de9f6a 100644
--- a/sys/kern/kern_ktrace.c
+++ b/sys/kern/kern_ktrace.c
@@ -396,7 +396,7 @@ ktr_drain(struct thread *td)
 
 	STAILQ_INIT(&local_queue);
 
-	if (!STAILQ_EMPTY(&td->td_proc->p_ktr)) {
+	if (!STAILQ_EMPTY_ATOMIC(&td->td_proc->p_ktr)) {
 		mtx_lock(&ktrace_mtx);
 		STAILQ_CONCAT(&local_queue, &td->td_proc->p_ktr);
 		mtx_unlock(&ktrace_mtx);



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