Hi All,
I am developing a mini-filter.In my PreCreate Operation,i got crash dump.
My Pseudo Code:
PreCreate()
{
HANDLE hFileHandle = NULL;
PFILE_OBJECT pobjFileObject = NULL;
OBJECT_ATTRIBUTES objectAttributes;
try
{
InitializeObjectAttributes(&objectAttributes,
&FileName,
OBJ_KERNEL_HANDLE,
NULL,
NULL);
status = FltCreateFile(gFilterHandle,
FltObjects->Instance,
&hFileHandle,
FILE_READ_DATA,
&objectAttributes,
&ioStatus,
(PLARGE_INTEGER) NULL,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ,
FILE_OPEN,
0L,
NULL,
0L,
0);
if(STATUS_SUCCESS != status)
{
leave;
}
status = ObReferenceObjectByHandle(hFileHandle,
STANDARD_RIGHTS_REQUIRED,
*IoFileObjectType,
KernelMode,
&pobjFileObject,
NULL);
if(STATUS_SUCCESS != status)
{
leave;
}
}
finally
{
if(hFileHandle)
{
//Here Crash occurs
FltClose(hFileHandle);
hFileHandle = NULL;
}
if(pobjFileObject)
{
ObDereferenceObject(pobjFileObject);
pobjFileObject = NULL;
}
}
}
The pobjFileObject parameter has different value in try block and when it leaves try block and goes to finally block it has some different value.
Why the value of pobjFileObject changes?
Following is the Crash Dump:
Bug Check 0x6: INVALID_PROCESS_DETACH_ATTEMPT
f5e10798 8080c77e 00000006 84980020 f5e107ec nt!KeBugCheck+0x14
f5e107b8 8091bef3 f5e107d0 f5e10808 f5e10884 nt!KeUnstackDetachProcess+0x10b
f5e107ec 80905562 00000294 00000000 f5e10808 nt!ObpCloseHandle+0xb5
f5e107fc 8082337b 80000294 f5e10924 8082138c nt!NtClose+0x1b
f5e107fc 8082138c 80000294 f5e10924 8082138c nt!KiFastCallEntry+0xf8
f5e10878 f72a9621 80000294 f72a95aa 8518dee4 nt!ZwClose+0x11
f5e10880 f72a95aa 8518dee4 8518dda0 851c92f0 testFilter!PreCreate+0x7e1
f5e10924 f734d4e8 851c934c f5e10944 f5e10960 testFilter!PreCreate+0x76a
WARNING: Stack unwind information not available. Following frames may be wrong.
f5e10984 f734ef48 00e109c8 851c92f0 851d2548 fltmgr+0x24e8
f5e10998 f735d0ad f5e109c8 f735b540 00000000 fltmgr+0x3f48
f5e109b0 f735d59d f5e109c8 851d23b8 851d2564 fltmgr+0x120ad
f5e109e4 80828c93 84d03e58 851d23b8 00000000 fltmgr+0x1259d
f5e109f8 f769e934 84bb3478 8507e0a8 84b6df08 nt!IofCallDriver+0x45
f5e10a5c 80828c93 84d33b98 00000000 851d23b8 TmPreFlt!TmpQueryFullName+0x5ba4
f5e10a70 80907bea f5e10c18 84d33018 00000000 nt!IofCallDriver+0x45
f5e10b58 80902f9d 84d33030 00000000 8494d008 nt!IopParseDevice+0xa35
f5e10bd8 80906a05 00000000 f5e10c18 00000040 nt!ObpLookupObjectName+0x5a9
f5e10c2c 8090612b 00000000 00000000 3f100001 nt!ObOpenObjectByName+0xea
f5e10ca8 8092b2b0 000f288c c1150000 000f27e0 nt!IopCreateFile+0x447
f5e10d04 8091bd20 000f288c c1150000 000f27e0 nt!IoCreateFile+0xa3
f5e10d44 8082337b 000f288c c1150000 000f27e0 nt!NtOpenFile+0x27
f5e10d44 7c82ed54 000f288c c1150000 000f27e0 nt!KiFastCallEntry+0xf8
000f2af8 501667af 0717d52c 000f2b28 00000000 ntdll!KiFastSystemCallRet
000f2d38 501668e8 010a4f58 0717d52c 000f2d70 msenv!DllCanUnloadNow+0x48e58
000f2d80 500e1cc1 010968e0 0717d52c 00000001 msenv!DllCanUnloadNow+0x48f91
000f2da4 500e1f03 00000001 0717d52c 00000000 msenv!DllGetClassObject+0x23ea9
000f2e14 50166ce4 00000002 010968e0 0717d52c msenv!DllGetClassObject+0x240eb
000f2e30 50166c67 009f2e68 00000002 010968e0 msenv!DllCanUnloadNow+0x4938d
000f2e88 78134bbe 259c64a4 00000001 0a659980 msenv!DllCanUnloadNow+0x49310
000f2e88 78134bbe 259c64a4 00000001 0a659980 MSVCR80!free+0xec
000f2e88 78134bbe 259c64a4 00000001 0a659980 MSVCR80!free+0xec
Thanks in Advance
Anand.