Page MenuHomeFreeBSD

Fix unsynchronized updates to kn_status.
ClosedPublic

Authored by markj on Nov 20 2018, 9:33 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Apr 26, 3:12 PM
Unknown Object (File)
Apr 12 2026, 5:50 AM
Unknown Object (File)
Apr 1 2026, 7:17 PM
Unknown Object (File)
Apr 1 2026, 5:46 AM
Unknown Object (File)
Apr 1 2026, 12:19 AM
Unknown Object (File)
Mar 30 2026, 5:09 PM
Unknown Object (File)
Mar 29 2026, 1:35 PM
Unknown Object (File)
Mar 29 2026, 12:37 PM
Subscribers

Details

Summary

kn_status is protected by the kqueue's lock, but we were updating it
without the kqueue lock held. For EVFILT_TIMER knotes, there is no
knlist lock, so the knote activation could occur during the kn_status
update following event registration. The activation should enqueue the
knote and set KN_QUEUED, but I have a test case where the KN_QUEUED flag
gets lost, leading to corruption of the queue.

Fix the problem by setting or clearing KN_DISABLED before dropping the
kqueue lock to call into the filter. KN_DISABLED is only used by the
core kevent code, so there is no side effect from setting it earlier.

Test Plan

I have a test program that can trigger the race and a resulting crash; Peter
added it to stress2.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable