Page MenuHomeFreeBSD

condvar: Fix a user-after-free in _cv_wait() when ktrace is enabled
ClosedPublic

Authored by markj on Jan 13 2024, 9:11 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Aug 2, 10:31 AM
Unknown Object (File)
Tue, Jul 29, 2:36 AM
Unknown Object (File)
Mon, Jul 28, 6:04 PM
Unknown Object (File)
Mon, Jul 28, 2:25 PM
Unknown Object (File)
Tue, Jul 22, 3:56 PM
Unknown Object (File)
Tue, Jul 22, 7:18 AM
Unknown Object (File)
Jun 25 2025, 7:54 AM
Unknown Object (File)
Jun 23 2025, 3:23 PM
Subscribers

Details

Summary

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.

Reported by: syzkaller

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

sys/kern/kern_condvar.c
216

This code has the same issue?

279

And this and several other functions below

markj marked 2 inline comments as done.

Update all of the _cv_wait* variants.

Move the initial ktrcsw() call later, after assertions and special cases are
checked.

kib added inline comments.
sys/kern/kern_condvar.c
144
This revision is now accepted and ready to land.Jan 13 2024, 9:47 PM