>>You can free buffer pointed by FileName.Buffer yourself using ExFreePool.
Its allocated by FltMgr, as a basic rule you are not suppose to alter it. if you have to change some thing you should change it inside parameter block as described in documentation.
“The contents of the FLT_RELATED_OBJECTS structure are set by the filter manager. Minifilter drivers cannot directly modify the contents of this structure. However, if a minifilter driver modifies the target instance or target file object for an I/O operation in the FLT_IO_PARAMETER_BLOCK structure for the operation, the filter manager modifies the value of the corresponding Instance or FileObject member of the FLT_RELATED_OBJECTS structure that is passed to lower minifilter drivers.”
Another thing which one should consider is that if the memory does not belongs to you or if the protocol(if any) stated by the owner do not mention that you are authorized to free it, you shouldn’t.
Although You can go to caller assembly and verify what it is calling to allocate and use its counter part to de-allocate but that can fail in future release, so better avoid this path. For example If we assume that FltMgr has allocated memory using ExAllocatePool that in later version it may use some lookaside list or some other mechnism, which we will break in case we free the memory.
>The I/O manager will free the memory allocated by you.
ExFreePool does not belongs to IoManager, its provided by Executive.
>Ensure you allocate memory using ExAllocatePool from Non Paged memory pool.
file objects are allocated using non-paged memory, but here OP is concerned about the name buffer, which can be allocated from paged pool, in fact FltMgr also allocates it from paged pool. I verified it my self and following are the steps taken.
kb
ChildEBP RetAddr Args to Child
f69abc28 f7743944 866a4624 f69abc48 f69abc78 scanner!ScannerPreDirectory [c:\winddk\6001.18001\src\filesys\minifilter\my_scanner\filter\scanner.c @ 1397]
f69abc88 f7745352 009abcd0 00000000 f69abcd0 fltMgr!FltpPerformPreCallbacks+0x2d4
f69abc9c f7745c15 f69abcd0 00000000 863c7858 fltMgr!FltpPassThroughInternal+0x32
f69abcb8 f7745ffb f69abc00 86564fb8 867cd280 fltMgr!FltpPassThrough+0x1df
f69abce8 804e19ee 865ce020 8662b9f8 80703410 fltMgr!FltpDispatch+0xf3
f69abcf8 8057184c f69abd64 0012f624 805844f6 nt!IopfCallDriver+0x31
dt _FLT_RELATED_OBJECTS 0xf69abc48
+0x000 Size : 0x18
+0x002 Reserved : 0
+0x004 Filter : 0x866cdea8 _FLT_FILTER
+0x008 Volume : 0x863c7858 _FLT_VOLUME
+0x00c Instance : 0x867162e8 _FLT_INSTANCE
+0x010 FileObject : 0x86616400 _FILE_OBJECT
+0x014 Transaction : (null)
1: kd> !pool 0x86616400
Pool page 86616400 region is Nonpaged pool
1: kd> dt _file_object 0x86616400
ntdll!_FILE_OBJECT
+0x000 Type : 5
+0x002 Size : 112
+0x004 DeviceObject : 0x8677d030 _DEVICE_OBJECT
+0x008 Vpb : 0x8677f7a0 _VPB
+0x00c FsContext : 0xe14f0d20
+0x010 FsContext2 : 0xe1847940
+0x014 SectionObjectPointer : (null)
+0x018 PrivateCacheMap : (null)
+0x01c FinalStatus : 0
+0x020 RelatedFileObject : (null)
+0x024 LockOperation : 0 ‘’
+0x025 DeletePending : 0 ‘’
+0x026 ReadAccess : 0x1 ‘’
+0x027 WriteAccess : 0 ‘’
+0x028 DeleteAccess : 0 ‘’
+0x029 SharedRead : 0x1 ‘’
+0x02a SharedWrite : 0x1 ‘’
+0x02b SharedDelete : 0 ‘’
+0x02c Flags : 0x40002
+0x030 FileName : _UNICODE_STRING “\Documents and Settings\All Users\Application Data\VMware\VMware Tools”
+0x038 CurrentByteOffset : _LARGE_INTEGER 0x0
+0x040 Waiters : 0
+0x044 Busy : 1
+0x048 LastLock : (null)
+0x04c Lock : _KEVENT
+0x05c Event : _KEVENT
+0x06c CompletionContext : (null)
1: kd> dt _UNICODE_STRING 0x86616400 + 0x30
“\Documents and Settings\All Users\Application Data\VMware\VMware Tools”
+0x000 Length : 0x8c
+0x002 MaximumLength : 0xf8
+0x004 Buffer : 0xe1577a68 “\Documents and Settings\All Users\Application Data\VMware\VMware Tools”
1: kd> !pool 0xe1577a68
Pool page e1577a68 region is Paged pool