ktr: Use STAILQ_EMPTY_ATOMIC when checking for records in ktr_drain()

This is an unlocked check, and after commit 34740937f7 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:		34740937f7 ("queue: New debug macros for STAILQ")
Differential Revision:	https://reviews.freebsd.org/D48899

(cherry picked from commit 36631977d8)
This commit is contained in:
Mark Johnston 2025-02-14 15:49:27 +00:00
parent 0599d2a1c5
commit ffb4d07771

View file

@ -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);