I’m trying to create a directory from kernel-mode on a UNC path. The
situation is that my system service impersonates a logged-on user, and
then makes an IOCTL call into my driver, which tries to create the
directory using ZwCreateFile.
The problem is I always get STATUS_ACCESS_DENIED when doing so. First I
assumed it was a problem with the impersonation, so I inserted some test
code into the service right before the IOCTL to attempt to create the
directory using the Win32 API CreateDirectory. Well, this worked. This
led me to believe that somehow I was passing the wrong parameters to
ZwCreateFile.
I went ahead and reverse-engineered CreateDirectory, and all it was
doing was a simple ZwCreateFile just like my driver. I pulled out the
EXACT values for all arguments (flags, attributes, whatnot) and
duplicated these in my driver. Surely it must work now. (Note that it
works fine for non-UNC paths).
Nope, still STATUS_ACCESS_DENIED. Apparently the system is treating the
request differently in a non-trivial way (i.e. not simply as an
indicator that memory addresses should be verified differently, etc.)
simply because the create was initiated from user-mode, not kernel-mode.
Why? I though the thread token carries over the user-mode/kernel-mode
barrier. I’m about to dissect the IRPs being generated for differences,
and compare the security context of the threads, but it seems
counterintuitive to say the least.
- Nicholas Ryan