Hello. Apologies if this is in the archives, but I could not find a
definite answer.
I am writing an upper filter, which will perform operations on
METHOD_NEITHER IOCTLs as they come up the stack. So far, my pass through
filter works OK. But I do have some questions on dealing with
METHOD_NEITHER IOCTLs, in particular buffer locking/mapping. And since I’m
not the function driver, I must deal with these IOCTLs as they are.
I’m reading the paper “User-Mode Interactions: Guidelines for Kernel-Mode
Drivers”, but I still have some questions. I do understand that I must lock
the user buffer pages and map it on the way down, so that I can access it in
my completion routine, which could be arbitrary context and at
DISPATCH_LEVEL. I do create an MDL, call MmProbeAndLockPages, and then
MmGetSystemAddressForMdlSafe. I am using try/except where necessary. I can
access this locked and mapped buffer fine in my completion routine.
It’s cleanup which irks me a bit. Currently, I call MmUnmapLockedPages,
MmUnlockPages, and then IoFreeMdl. This is fine with driver verifier, and
the checked kernel/HAL. But I’m still wondering if this cleanup is OK. And
the previously cited white paper is, I admit, confusing me on a point (under
the section “Validation for Neither I/O Transfers”):
“Map the user-mode buffer into the kernel address space and lock the pages
into memory by calling MmProbeAndLockPages within a structured exception
handler.”
Now, as I understand it, MmProbeAndLockPages just locks down the pages, and
does not do any mapping. What am I missing?
Also:
“Unlock and unmap the buffer by calling MmUnlockPages after all kernel-mode
components have finished using it.”
I also though that MmUnlockPages does not do any unmapping. In fact, the
5112 DDK says that “The MmUnlockPages routine unlocks physical pages
described by a given MDL.”. Nothing about unmapping here. Don’t I need to
call MmUnmapLockedPages first, before calling MmUnlockPages?
RELATED question: how does the IO Manager clean up the MDL for
METHOD_Xxx_DIRECT? Just a call to MmUnlockPages?
Thanks for clearing up any confusion,
Philip Lukidis