Hello all.
Crossposting from NTDEV (http://www.osronline.com/showthread.cfm?link=252446)
I have a simple file minifilter that tracks access to files. I need to associate a context with every opened file. It looks that stream context is what I look for.
In PostCreate I either get the context or allocate it. I don't call FltReleaseContext since the context may be used later on while the file is opened.
In PostWrite operation I call FltGetStreamContext paired with FltReleaseContext.
In PreClose I call FltGetStreamContext. Common sense says that there should be two calls to FltReleaseContext: one for PostCreate reference and one for PreClose.
PreClose routine causes BSoD:
1: kd> !analyze -v
*******************************************************************************
* *
* Bugcheck Analysis *
* *
*******************************************************************************
FLTMGR_FILE_SYSTEM (f5)
An unrecoverable failure occured inside the filter manager.
Arguments:
Arg1: 000000000000006d, The reason for the failure
Arg2: fffffa80035e8330
Arg3: fffffa80035e82d0
Arg4: 0000000000000000
Debugging Details:
OVERLAPPED_MODULE: Address regions for 'dump_LSI_SAS' and 'crashdmp.sys' overlap
DEFAULT_BUCKET_ID: WIN7_DRIVER_FAULT
BUGCHECK_STR: 0xF5
PROCESS_NAME: System
CURRENT_IRQL: 2
LAST_CONTROL_TRANSFER: from fffff800029b7d92 to fffff800028c8490
STACK_TEXT:
fffff880031e0828 fffff800029b7d92 : 000000000000006d fffffa8000cb0680
0000000000000065 fffff8000290c178 : nt!RtlpBreakWithStatusInstruction
fffff880031e0830 fffff800029b8b7e : fffffa8000000003 0000000000000000
fffff8000290c9d0 00000000000000f5 : nt!KiBugCheckDebugBreak+0x12
fffff880031e0890 fffff800028d0744 : fffffa8000000000 fffffa80035e82e8
fffffa80035e82d0 fffffa80035e82e8 : nt!KeBugCheck2+0x71e
fffff880031e0f60 fffff8800110633d : 00000000000000f5 000000000000006d
fffffa80035e8330 fffffa80035e82d0 : nt!KeBugCheckEx+0x104
fffff880031e0fa0 fffff88001001960 : fffffa80035e8350 0000000000000000
fffffa8001d5a2b0 0000000000000052 : fltmgr! ?? ::FNODOBFM::string'+0x1309 fffff880031e0fe0 fffff88001100067 : fffffa8002d2b240 fffff880031e1098 fffff880031e1070 fffffa8000680727 : Monitor!PreOpClose+0x70 [filemon.c @ 865] fffff880031e1020 fffff88001101329 : fffff880031e1100 00001f8000000002 fffffa80035e8d00 fffff8a000001800 : fltmgr!FltpPerformPreCallbacks+0x2f7 fffff880031e1120 fffff880010ff6c7 : fffffa8002d13010 fffffa8001d5a2b0 fffffa8001c1b8c0 0000000000000000 : fltmgr!FltpPassThrough+0x2d9 fffff880031e11a0 fffff80002bcc88e : fffffa80035e8de0 fffffa8001d20270 fffffa8000c9e9e0 fffffa8001d5a2b0 : fltmgr!FltpDispatch+0xb7 fffff880031e1200 fffff800028da514 : 00000000000000b0 fffffa8000c9e9e0 fffffa8000cbdde0 fffff800028cbe70 : nt!IopDeleteFile+0x11e fffff880031e1290 fffff80002bc7484 : fffffa8000c9e9e0 0000000000000000 fffffa8000cb0680 0000000000000000 : nt!ObfDereferenceObject+0xd4 fffff880031e12f0 fffff80002bc7a34 : 000000000000041c fffffa8000c9e9e0 fffff8a000001850 000000000000041c : nt!ObpCloseHandleTableEntry+0xc4 fffff880031e1380 fffff800028cf8d3 : fffffa8000cb0680 fffff880031e1450 0000000000000000 0000000000000001 : nt!ObpCloseHandle+0x94 fffff880031e13d0 fffff800028cbe70 : fffff880022b2f93 fffff8a001d9b318 0000000000000000 fffff8a001d9b318 : nt!KiSystemServiceCopyEnd+0x13 fffff880031e1568 fffff880022b2f93 : fffff8a001d9b318 0000000000000000 fffff8a001d9b318 fffff8a001d9dab8 : nt!KiServiceLinkage fffff880031e1570 fffff880022be161 : fffff880022aec01 0000000000000001 fffff88000000002 fffff880031e16a0 : luafv!LuafvFindTableNode+0x5c7 fffff880031e1680 fffff880022bfbbf : fffff880022ab340 0000000000000001 0000000000000001 0000000000000000 : luafv!LuafvReadFileTable+0x159 fffff880031e1750 fffff880022bf631 : fffff880022ab750 fffff880022ab9b0 fffffa80035e9000 000000000000000d : luafv!LuafvReadSettings+0x3d7 fffff880031e17f0 fffff80002cb5467 : fffffa80035e3be0 0000000000000000 0000000000000000 fffffa80035e9000 : luafv!DriverEntry+0x219 fffff880031e1860 fffff80002cb5865 : fffffa80035e0510 0000000000000000 0000000000000001 0000000000000001 : nt!IopLoadDriver+0xa07 fffff880031e1b30 fffff800028daa21 : fffff80000000000 ffffffff80000420 fffff80002cb5810 0000000000000000 : nt!IopLoadUnloadDriver+0x55 fffff880031e1b70 fffff80002b6dcce : eaa0eaea9ceaea9e fffffa8000cb0680 0000000000000080 fffffa8000c9e9e0 : nt!ExpWorkerThread+0x111 fffff880031e1c00 fffff800028c1fe6 : fffff880009ea180 fffffa8000cb0680 fffffa8000cb0b60 524b1659541a625f : nt!PspSystemThreadStartup+0x5a fffff880031e1c40 0000000000000000 : fffff880031e2000 fffff880031dc000 fffff880031dfa10 00000000`00000000 : nt!KiStartSystemThread+0x16
STACK_COMMAND: kb
FOLLOWUP_IP:
Monitor!PreOpClose+70 [filemon.c @ 865]
fffff880`01001960 b801000000 mov eax,1
FAULTING_SOURCE_LINE: filemon.c
FAULTING_SOURCE_FILE: filemon.c
FAULTING_SOURCE_LINE_NUMBER: 865
FAULTING_SOURCE_CODE:
861: FltReleaseContext(pStreamContext);
862: //FltReleaseContext(pStreamContext);
863: }
864:
865: return FLT_PREOP_SUCCESS_NO_CALLBACK;
866: }
867:
868: NTSTATUS FilterUnload(IN FLT_FILTER_UNLOAD_FLAGS Flags)
869: {
870: UNREFERENCED_PARAMETER(Flags);
SYMBOL_STACK_INDEX: 5
SYMBOL_NAME: Monitor!PreOpClose+70
FOLLOWUP_NAME: MachineOwner
MODULE_NAME: Monitor
IMAGE_NAME: Monitor.sys
DEBUG_FLR_IMAGE_TIMESTAMP: 52d4266d
FAILURE_BUCKET_ID: X64_0xF5_Monitor!PreOpClose+70
BUCKET_ID: X64_0xF5_Monitor!PreOpClose+70
Followup: MachineOwner
In the dump above I tried to dereference context only once.
What may be the problem here?
Thanks.