I wrote a function to convert the drive letter. In this function, I use the ZwQuerySymbolicLink API which caused BSOD.
The error code 0xC4_f6 means “A driver references a user-mode handle as kernel mode”. But I can’t fig out what caused this bug.
Hope you guys can give me some advice. Any word will be appreciated.
Here is my function code:
`NTSTATUS QuerySymbolicLink(
IN PUNICODE_STRING SymbolicLinkName,
OUT PUNICODE_STRING LinkTarget
)
{
OBJECT_ATTRIBUTES objAttr;
NTSTATUS status;
HANDLE symHandle;
InitializeObjectAttributes(&objAttr, SymbolicLinkName,
OBJ_CASE_INSENSITIVE, 0, 0);
status = ZwOpenSymbolicLinkObject(&symHandle, GENERIC_READ, &objAttr);
if (!NT_SUCCESS(status))
{
DbgPrint("open the symbolinkobj failed ..\n");
ZwClose(symHandle);
return status;
}
if (!LinkTarget->Buffer)
{
ZwClose(symHandle);
return STATUS_INSUFFICIENT_RESOURCES;
}
RtlZeroMemory(LinkTarget->Buffer, LinkTarget->MaximumLength);
status = ZwQuerySymbolicLinkObject(symHandle, LinkTarget, NULL);
ZwClose(symHandle);
if (!NT_SUCCESS(status))
{
DbgPrint(" query the symbolinkObject failed ...\n");
}
return status;
And did you read the documentation for InitializeObjectAttributes? The part where it says that you must specify OBJ_KERNEL_HANDLE if you want a kernel handle?
@Tim_Roberts said:
And did you read the documentation for InitializeObjectAttributes? The part where it says that you must specify OBJ_KERNEL_HANDLE if you want a kernel handle?
Yes! Your method solved the problem. Thank you so much.
But I can’t understand where caused the handle into USER MODE.
And the same driver will not lead to BSOD if I change a virtual machine. It makes me confused.
I can’t understand where caused the handle into USER MODE.
APIs like ZwOpenSymbolicLinkObject are usually called by or on behalf of user-mode processes, so if you don’t specify that flag, it assumes that’s what you are doing.
@Tim_Roberts said:
APIs like ZwOpenSymbolicLinkObject are usually called by or on behalf of user-mode processes, so if you don’t specify that flag, it assumes that’s what you are doing.