I have a question about desired access flags in a mini-filter pre-create
callback.
The objective here is to accurately detect read, write and delete
opearations. At the moment, I can’t tell the difference between reading
an existing file and deleting a nonexistant file. I’m also pretty sure
that my read vs. write detection is wrong - I’m using the disposition flags.
The help for ZwCreateFile pretty clearly spells out what’s what but I’m
having a heck of a time associating the various flag bits I get with the
different operations. Rooting around in the header files is really
confusing.
In the filter, I’m using:
FLT_PREOP_CALLBACK_STATUS PreCreateCallback (
PFLT_CALLBACK_DATA Data, …
PFLT_IO_PARAMETER_BLOCK IopbPtr = Data->Iopb;
PFLT_PARAMETERS ParameterPtr = &IopbPtr->Parameters;
PIO_SECURITY_CONTEXT SecurityContextPtr =
ParameterPtr->Create.SecurityContext;
ACCESS_MASK DesiredAccess = SecurityContextPtr->DesiredAccess;
The ACCESS_MASK seems to be what I want but I’ll be darned if I can
associate it, the specified fields/symbols and the bits I’m getting below.
Any comments on the proper way to interpret the ‘DesiredAccess’ value
are appreciated. (or whatever it takes to neet the goal above.)
Regards,
Mickey.
A chunk of a log file with // comments added…
//
// my test app wants to delete any old files. (the files do not exist in
this case)
//
[3520] Calling “DeleteFile (Z:\S.eee)” <<<< 1st WIN32 function
executed
//
// driver gets IRP_MJ_CREATE
//
File name = \Device\HarddiskVolume5\S.eee
DesiredAccess = 0x00000080
//
// TestFileOpen() = my routine to open, get attributes. sets flags
‘exists’ & ‘is directory’
//
TestFileOpen() reports file does not exist
//
// my user space reporting app (plays no significant part in this question)
//
[244] filesystem: “s.exe” “openforread” “z:\s.eee”
//
// driver gets 2nd IRP_MJ_CREATE for same WIN32 operation w/ different
access flags
//
File name = \Device\HarddiskVolume5\S.eee
DesiredAccess = 0x00010080
TestFileOpen() reports file does not exist
[244] filesystem: “s.exe” “openforread” “z:\s.eee”
//
// test app tries to delete 2nd old file, gets same result
//
[3520] Calling “DeleteFile (Z:\S.fff)” <<<< 2nd WIN32 function
executed
File name = \Device\HarddiskVolume5\S.fff
DesiredAccess = 0x00000080
TestFileOpen reports file exists
[244] filesystem: “s.exe” “openforread” “z:\s.fff”
File name = \Device\HarddiskVolume5\S.fff
DesiredAccess = 0x00010080
TestFileOpen reports file exists
[244] filesystem: “s.exe” “openforread” “z:\s.fff”
//
// test app starts by creating 1st file
//
[3520] Calling “CreateFile (Z:\S.eee, GENERIC_WRITE, 0, 0,CREATE_ALWAYS,
0, 0)” <<<< 3rd WIN32 function executed
//
// driver gets same IRP_MJ_CREATE
//
File name = \Device\HarddiskVolume5\S.eee
DesiredAccess = 0x00000080
TestFileOpen() reports file does not exist
//
// then an IRP_MJ_CREATE to open for write
//
File name = \Device\HarddiskVolume5\S.eee
DesiredAccess = 0x00120196
TestFileOpen() reports file does not exist
//
// then driver gets IRP_MJ_CREATE for a directory
//
Dir name = \Device\HarddiskVolume5\
DesiredAccess = 0x00100000
TestFileOpen() reports directory exists