Hi @Joseph Kiyengui ,
Thank you for the detailed write-up. I went through the relevant documentation and also ran a set of tests on Windows 11 25H2 (build 26200), on a local NTFS volume, calling NtCreateFile directly with handle-relative names. I'll go through your questions in order.
On whether FILE_DIRECTORY_FILE | FILE_OPEN_REPARSE_POINT is a supported combination: based on the NtCreateFile (winternl.h) documentation, I would not rely on it. The description of FILE_DIRECTORY_FILE states that "With this flag, the CreateDisposition parameter must be set to FILE_CREATE, FILE_OPEN, or FILE_OPEN_IF. With this flag, other compatible CreateOptions flags include only the following: FILE_SYNCHRONOUS_IO_ALERT, FILE_SYNCHRONOUS_IO_NONALERT, FILE_WRITE_THROUGH, FILE_OPEN_FOR_BACKUP_INTENT, and FILE_OPEN_BY_FILE_ID." The WDK version of NtCreateFile has the same list. FILE_OPEN_REPARSE_POINT is not on it. In my tests the combination was accepted, both with FILE_CREATE and with FILE_OPEN, but I would treat that as observed behavior rather than a documented contract. More importantly, it doesn't give you the protection you're looking for. The flag is described as "Open a file with a reparse point and bypass normal reparse point processing for the file", so it only applies to the final component being opened. When I created jx\newdir relative to the parent handle with FILE_OPEN_REPARSE_POINT set, where jx was a junction (and in a second test a directory symbolic link) pointing outside the trusted parent, the directory was still created at the link target. With FILE_CREATE, the final component doesn't exist yet, so the flag has nothing to apply to.
For a documented way to avoid reparse-point traversal, I would look at the OBJ_DONT_REPARSE attribute in OBJECT_ATTRIBUTES. The documentation describes it as follows: "If this flag is set, no reparse points will be followed when parsing the name of the associated object. If any reparses are encountered the attempt will fail and return an STATUS_REPARSE_POINT_ENCOUNTERED result. This can be used to determine if there are any reparse points in the object's path, in security scenarios." In my tests, the same jx\newdir create with OBJ_DONT_REPARSE failed with STATUS_REPARSE_POINT_ENCOUNTERED (0xC000050B) for both a junction and a directory symbolic link, and nothing was created. A plain single-component create in the trusted parent succeeded normally.
The sequence I would suggest is this. Open the trusted parent with FILE_OPEN, FILE_DIRECTORY_FILE and OBJ_DONT_REPARSE. Create the first child with a single-component name relative to that handle, using FILE_CREATE, FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT, OBJ_DONT_REPARSE, and your explicit security descriptor in OBJECT_ATTRIBUTES.SecurityDescriptor. Then create the second child relative to the handle returned for the first child, rather than passing a two-component relative path. A minimal example of one step:
UNICODE_STRING name;
RtlInitUnicodeString(&name, L"child1");
OBJECT_ATTRIBUTES oa;
InitializeObjectAttributes(&oa, &name, OBJ_CASE_INSENSITIVE | OBJ_DONT_REPARSE, hParent, pSecurityDescriptor);
IO_STATUS_BLOCK iosb;
HANDLE hChild = NULL;
NTSTATUS status = NtCreateFile(&hChild,
FILE_LIST_DIRECTORY | FILE_ADD_SUBDIRECTORY | FILE_TRAVERSE | FILE_READ_ATTRIBUTES | READ_CONTROL | SYNCHRONIZE,
&oa, &iosb, NULL, FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ | FILE_SHARE_WRITE, // no FILE_SHARE_DELETE
FILE_CREATE,
FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT,
NULL, 0);
if (!NT_SUCCESS(status) || iosb.Information != FILE_CREATED) {
// fail closed
}
About OBJECT_ATTRIBUTES.RootDirectory: the documentation only states that "If this value is non-NULL, the ObjectName member specifies a file name relative to this directory." I could not find a documented guarantee about behavior under concurrent rename or replacement, so please take the following as test observations only. I opened a parent directory with FILE_SHARE_DELETE, renamed it, and then created a junction under the original name pointing elsewhere. A subsequent create through the original handle still landed in the renamed directory, not at the junction target. So in my tests the handle stayed bound to the directory object rather than to its path. When the parent was opened without FILE_SHARE_DELETE, the rename attempt failed with a sharing violation. For that reason I would suggest opening the parent and each intermediate directory without FILE_SHARE_DELETE for the duration of the workflow, which prevents those directories from being renamed or deleted while you hold the handles.
On FILE_CREATE, the documentation is explicit: "If the file already exists, fail the request and do not create or open the given file." In my tests, an existing directory, an existing file, a junction and a directory symbolic link with the target name all returned STATUS_OBJECT_NAME_COLLISION, including when FILE_OPEN_REPARSE_POINT was set. With OBJ_DONT_REPARSE, the existing junction case returned STATUS_REPARSE_POINT_ENCOUNTERED instead. As an additional check, I would confirm that IoStatusBlock.Information is FILE_CREATED and then validate the new handle as described next.
For post-creation verification, all of the following work on the handle you already hold, without re-resolving any path:
- GetFileInformationByHandleEx with
FileIdInforeturns a FILE_ID_INFO. As documented, "The file identifier and the volume serial number uniquely identify a file on a single computer." You can compare the volume serial number with the parent's to confirm the new directory is on the same volume. -
FileAttributeTagInforeturns a FILE_ATTRIBUTE_TAG_INFO, which lets you confirm the object is a directory with no reparse tag. - GetFinalPathNameByHandleW gives the final path.
VOLUME_NAME_GUIDorVOLUME_NAME_NTgive a volume-qualified form. - GetSecurityInfo or NtQuerySecurityObject let you read back the security descriptor.
- If you prefer to stay on the native side, NtQueryInformationFile with
FileIdInformation,FileAttributeTagInformationorFileStatInformation(see FILE_STAT_INFORMATION) provides the same data.
In my tests, the owner and protected DACL I passed in were read back exactly as specified, and the file ID, volume serial number and final path all matched the expected location.
There are a few limitations I would keep in mind. First, OBJ_DONT_REPARSE applies to the whole name being parsed, so it may also reject some full-path forms. When I opened the parent by full path with this flag, \??\C:\... and \Device\HarddiskVolumeN\... succeeded, but a \??\Volume{GUID}\... path failed with STATUS_REPARSE_POINT_ENCOUNTERED. Because of this, I would recommend testing the exact path form you use to open the trusted root. Second, the Reparse Points documentation notes that mounted folders are also implemented as reparse points and that "There is a limit of 63 reparse points on any given path." Third, as an additional process-level mitigation, you may want to look at PROCESS_MITIGATION_REDIRECTION_TRUST_POLICY (RedirectionGuard), which can be enabled through SetProcessMitigationPolicy to "prevent the process from following filesystem junctions created by non-admin users". Finally, my results come from a single machine with a local NTFS volume. Third-party file system filters, such as antivirus or EDR software, and remote file systems such as SMB may behave differently, so it would be worth validating the workflow in your target environment.
I should also be clear about what I can provide here. On this forum, I can only work from the public documentation and from my own testing. I don't have access to the Windows source code or to internal design specifications, so I'm not in a position to give an authoritative confirmation of the API contract beyond what is publicly documented. Two of your points fall into that gap: whether the FILE_DIRECTORY_FILE | FILE_OPEN_REPARSE_POINT combination is officially supported, and what guarantees apply under concurrent modification. If you need a formal answer on those, I would recommend opening a support case with Microsoft through the Windows Developer Support page. Under Technical support for app platforms, you can choose Windows SDK for Windows 11. Please note that this is paid, incident-based support and requires a Microsoft support contract. A support engineer there can engage the appropriate Windows file system specialists and give you an official position for your security review.
I hope this helps. Please let me know if you have any further questions. If my response was helpful, I'd really appreciate it if you could follow this guide so that others with the same question can benefit.
Thank you.