Hello,
I am calling ZwOpenKey from PostOpCreate to read certain registry keys.
While it works fine most of the times, I ran into a deadlock situation in early boot sequence when registry hives are being loaded. The typical stack trace looks like following.
4.000168 86099380 0000100 Blocked nt!KiSwapContext+0x25
nt!KiSwapThread+0x83
nt!KeWaitForSingleObject+0x2e0
nt!ExpWaitForResource+0xd3
nt!ExAcquireResourceSharedLite+0xd9
nt!CmpLockRegistry+0x25
nt!CmpBuildHashStackAndLookupCache+0x43
nt!CmpParseKey+0x110
nt!ObpLookupObjectName+0x5b0
nt!ObOpenObjectByName+0xea
nt!NtOpenKey+0x1ad
nt!KiFastCallEntry+0xf8
nt!ZwOpenKey+0x11
nt!VfZwOpenKey+0x6d
…
…
…
fltmgr!FltvPostOperation+0x4d
fltmgr!FltpPerformPostCallbacks+0x1c5
fltmgr!FltpProcessIoCompletion+0x10
fltmgr!FltpPassThroughCompletion+0x89
fltmgr!FltpLegacyProcessingAfterPreCallbacksCompleted+0x269
fltmgr!FltpCreate+0x26a
nt!IovCallDriver+0x112
nt!IofCallDriver+0x13
nt!IopParseDevice+0xa35
nt!ObpLookupObjectName+0x5b0
nt!ObOpenObjectByName+0xea
nt!IopCreateFile+0x447
nt!IoCreateFile+0xa3
nt!NtCreateFile+0x30
nt!KiFastCallEntry+0xf8
nt!ZwCreateFile+0x11
nt!CmpOpenHiveFiles+0x117
The FILE_OBJECT in question in pointing to registry hive file viz. \windows\system32\config\system OR sam OR software etc.
It seems me that the registry lock is acquired by the time our PostOpCreate is called and when our filter attempts to call ZwOpenKey it blocks while acquiring the registry lock causing a deadlock.
Question for the experts:
- Is it possible to detect that the FILE_OBJECT in question is a registry hive?
- Is there a way to check if the registry lock is acquired without blocking?
- Is there any other way to solve this issue apart from not reading the registry at all from PostOpCreate.
Any advice would be much appreciated!
Thanks.
-Prasad