]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
condvar: Fix a user-after-free in _cv_wait() when ktrace is enabled
authorMark Johnston <markj@FreeBSD.org>
Mon, 15 Jan 2024 17:29:02 +0000 (12:29 -0500)
committerMark Johnston <markj@FreeBSD.org>
Mon, 15 Jan 2024 17:29:02 +0000 (12:29 -0500)
commita5ef95cd228e43bcc459a5c8a9911e57888ba5fd
treedb930eb1aedfc0e56307ff419dc70adf1631226c
parent61b0092be751b8241b65cc14e4167d431f1e5ad8
condvar: Fix a user-after-free in _cv_wait() when ktrace is enabled

When a thread wakes up after sleeping on a CV, it must not dereference
the CV structure, as it may already have been freed.  At least ZFS
relies on this invariant, see commit
c636f94bd2ff15be5b904939872b4bce31456c18 for example.

Thus, when logging context-switch events, copy the wmesg into a stack
buffer while it is still safe to do so, and log that after waking up.

While here, move the initial ktrcsw() call later, after assertions and
the SCHEDULER_STOPPED_TD() condition are checked.

Reported by: syzkaller
Reviewed by: kib
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D43450
sys/kern/kern_condvar.c