]> 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, 29 Jan 2024 14:26:29 +0000 (09:26 -0500)
commitdcaf7895039d3f71fc4ab9da1697c126c7d6bf44
tree6412cfbaa5de5f95bd7480213625cc797141a11a
parent604b80f152f20c1efa6313f9a0a483956e867225
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

(cherry picked from commit a5ef95cd228e43bcc459a5c8a9911e57888ba5fd)
sys/kern/kern_condvar.c