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)
Wed, Aug 5, 3:49 AM
Unknown Object (File)
Wed, Aug 5, 3:49 AM
Unknown Object (File)
Tue, Aug 4, 6:28 AM
Unknown Object (File)
Tue, Aug 4, 4:40 AM
Unknown Object (File)
Tue, Aug 4, 1:56 AM
Unknown Object (File)
Mon, Aug 3, 7:45 AM
Unknown Object (File)
Jul 1 2026, 7:44 AM
Unknown Object (File)
Jun 27 2026, 7:48 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