Draft
cm: Fix KCB pushlock leaks in CmpLookInCache and CmpDoOpen#8
Conversation
Two related bugs in the CM registry parser that can cause KCB pushlock deadlocks under SMP: 1. CmpLookInCache: when a key is found in the cache and CmpReferenceKeyControlBlock fails for the newly-found KCB, the function returned STATUS_UNSUCCESSFUL without calling CmpUnLockKcbArray(LockedKcbs). Every subsequent attempt to acquire that pushlock (shared or exclusive) would block permanently, causing the deadlocks observed on the SMP branch. Fix: reference the new KCB *before* dropping the old one so that on failure we can cleanly unlock the array and release the temporary reference, leaving the caller with a consistent state. 2. CmpDoOpen (CMP_OPEN_KCB_NO_CREATE, symlink-found path): after CmpUnLockKcbArray / CmpAcquireKcbLockExclusiveByIndex the lock held on the cached KCB is exclusive, but IsLockShared was left TRUE. The wrong flag was then passed to EnlistKeyBodyWithKCB which, when the KeyBodyArray is full, would release the wrong lock (the RealKcb's lock, which was never acquired) and acquire exclusive on an already-exclusively-held KCB. Fix: set IsLockShared = FALSE after upgrading to the exclusive lock.
Copilot
AI
changed the title
cm: Fix KCB lock leaks in CmpLookInCache and CmpDoOpen
cm: Fix KCB pushlock leaks in CmpLookInCache and CmpDoOpen
Aug 3, 2026
Copilot created this pull request from a session on behalf of
tkreuzer
August 3, 2026 11:42
View session
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SMP stress testing revealed regular deadlocks where KCB pushlocks had permanent waiters with no active holder — leaked lock acquisitions that block all subsequent acquirers indefinitely.
Bug 1 —
CmpLookInCache: lock leak on reference failureWhen a key is found in the cache and
CmpReferenceKeyControlBlock(CurrentKcb)fails, the function returnedSTATUS_UNSUCCESSFULwithout releasing the locks acquired byCmpBuildAndLockKcbArray. Those pushlock slots leaked permanently.The fix also corrects a secondary ordering issue: the old code dereferenced
*Kcband assigned*Kcb = CurrentKcbbefore the reference attempt, leaving the caller's pointer in an inconsistent state on failure.Bug 2 —
CmpDoOpen: staleIsLockSharedin symlink-found pathIn
CmpDoOpenwithCMP_OPEN_KCB_NO_CREATE, whenCM_KCB_SYM_LINK_FOUNDis set and the real KCB is live, the code upgrades from shared to exclusive lock but leftIsLockShared = TRUE. This flag is later passed toEnlistKeyBodyWithKCBasCMP_ENLIST_KCB_LOCKED_SHARED. When theKeyBodyArrayis full, that function callsCmpReleaseKcbLock(KeyBody->KeyControlBlock)— releasing a lock onRealKcbthat was never acquired, and then re-acquiring exclusive on an index already held exclusively.Fix: add
IsLockShared = FALSEafter the exclusive re-lock.