Hi All,
We are facing a weird system crash with (Bug Check 0xF5: FLTMGR_FILE_SYSTEM with parameter 6D) after calling FltReleaseContext() in our mini filter driver. We have referred WDDK7 sample driver (miniFilter\cancelSafe) for writing the driver and referred following link to properly release instance context (https://msdn.microsoft.com/en-us/library/windows/hardware/ff552001(v=vs.85).aspx).
Sample Code:
typedef struct _INSTANCE_CONTEXT {
PFLT_INSTANCE Instance; // Instance for this context.
FLT_CALLBACK_DATA_QUEUE Cbdq;
KEVENT TeardownEvent;
} INSTANCE_CONTEXT, *PINSTANCE_CONTEXT;
NTSTATUS InstanceSetup (
__in PCFLT_RELATED_OBJECTS FltObjects,
__in FLT_INSTANCE_SETUP_FLAGS Flags,
__in DEVICE_TYPE VolumeDeviceType,
__in FLT_FILESYSTEM_TYPE VolumeFilesystemType
)
{
PINSTANCE_CONTEXT instanceContex; // pointer to instance context
NTSTATUS rc = FltAllocateContext( FltObjects->Filter, FLT_INSTANCE_CONTEXT, INSTANCE_CONTEXT_SIZE, NonPagedPool, (PFLT_CONTEXT *)instanceContex);
instanceContex->Instance = FltObjects->Instance;
…
//some code like FltCbdqInitialize, InitializeListHead etc.
…
// associate the context with this instance. Reference count increases to 2.
rc = FltSetInstanceContext(instanceContex->Instance, FLT_SET_CONTEXT_REPLACE_IF_EXISTS, instanceContex, NULL);
// and drop the reference count incremented by FltSetInstanceContext. Reference count decreases to 1.
FltReleaseContext(Instance);
…
//some processing
…
if (Error) // Error occurred during processing.
{
// and drop the reference count incremented by FltAllocateContext and delete the context. Reference count decreases to 1.
// BSOD point. Bug check F5, 6D
FltReleaseContext(Instance);
return STATUS_FLT_DO_NOT_ATTACH;
}
}
Also if we replace BSOD point with following code then issue get fixed and while debugging it shows proper release and deletion of the context
// and drop the reference count incremented by FltAllocateContext and delete the context
PFLT_INSTANCE oldContext = NULL;
status = FltDeleteInstanceContext( ip->instancep, //Instance
&oldContext ); //OldContext
if (oldContext != NULL)
{
FltReleaseContext(oldContext);
}
We have referred to the following msdn link which mentions that - to release the initial reference we need to remove the context from the object by calling - “FltDeleteContext”
Link: https://msdn.microsoft.com/en-us/library/windows/hardware/ff551957(v=vs.85).aspx
We can see two different approach used on WDDK sample, one is Using ?FltDeleteContext or ?FltDeleteInstanceContext? to handle an error situation(as shown above). This is being used in WDK sample - ?miniFilter\minispy\filter?.
Second is by not calling ?FltReleaseContext? in case of an error condition.
Queries:
-
Is calling FltDeleteContext/FltDeleteInstanceContext and then FltReleaseContext, the proper approach to release the last reference of the instance Context, in case of an error condition in the instance setup?
-
In case of an error condition if we do not call ?FltReleaseContext? (to release the last reference incremented FltAllocateContext), then, will cause be a memory leak?
Thanks,
Devashree