Giter Club home page Giter Club logo

Comments (8)

Liryna avatar Liryna commented on June 20, 2024

Hi @fcyinxunpeng ,

RequestContext->Irp->MdlAddress be filled by the program of antivirus software?

It technically could but I believe it shouldn't provide one as the current IRP major is IRP_MJ_DIRECTORY_CONTROL
https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/ns-wdm-_irp

Pointer to an MDL describing a user buffer, if the driver is using direct I/O, and the IRP major function code is one of the following:

    IRP_MJ_READ

    The MDL describes an empty buffer that the device or driver fills in.

    IRP_MJ_WRITE

    The MDL describes a buffer that contains data for the device or driver.

    IRP_MJ_DEVICE_CONTROL or IRP_MJ_INTERNAL_DEVICE_CONTROL

    If the IOCTL code specifies the METHOD_IN_DIRECT transfer type, the MDL describes a buffer that contains data for the device or driver.

Normally we should allocate that MDL from the UserBuffer and own it but due to how the code is written, we try to use their.

dokany/sys/directory.c

Lines 105 to 114 in 69e3d88

// make a MDL for UserBuffer that can be used later on another thread context
if (RequestContext->Irp->MdlAddress == NULL) {
status = DokanAllocateMdl(
RequestContext,
RequestContext->IrpSp->Parameters.QueryDirectory.Length);
if (!NT_SUCCESS(status)) {
return status;
}
RequestContext->Flags = DOKAN_MDL_ALLOCATED;
}

We could change our code to override their value by removing this check and the same one in DokanAllocateMdl to ignore their (bogus?) value.

if (RequestContext->Irp->MdlAddress == NULL) {

from dokany.

fcyinxunpeng avatar fcyinxunpeng commented on June 20, 2024

Hi @Liryna ,
Thanks for your reply.
I removed this check and the same one in DokanAllocateMdl()

if (RequestContext->Irp->MdlAddress == NULL) {

if (RequestContext->Irp->MdlAddress == NULL) {

But it seems like it's not working because RequestContext->Irp->UserBuffer is always NULL, while RequestContext->Irp->MdlAddress is not NULL even when I don't have antivirus software installed.

If I zero memory in DokanQueryDirecory():

 if (RequestContext->Irp->MdlAddress == NULL) {
    ...
 }else{
    // test code
    buffer = MmGetSystemAddressForMdlNormalSafe(RequestContext->Irp->MdlAddress);
    RtlZeroMemory(buffer, bufferLen);  // won't crash at this line
}

Dokany2.sys doesn't crash at this line of code, so RequestContext->Irp->MdlAddress is valid at this moment.
Maybe then the antivirus software free the content of RequestContext->Irp->MdlAddress , even though dokany2.sys returns a STATUS_PENDING?

from dokany.

Liryna avatar Liryna commented on June 20, 2024

Thanks for testing!
Yeah that could be possible. Would you be able to contact Rising so they can look into this on their side ?

from dokany.

fcyinxunpeng avatar fcyinxunpeng commented on June 20, 2024

OK, I intend to ask for official help.
And I found that the MmGetSystemAddressForMdlNormalSafe function returns a user-space address instead of a kernel-space address when I use antivirus software scanning.

from dokany.

fcyinxunpeng avatar fcyinxunpeng commented on June 20, 2024

This is the official reply of rising:

The problem is that when traversing the directory, Rising Anti-Virus Software V17 passes in a user-mode address, causing a blue screen when the dokany driver writes to this address.
You can suggest to dokany that you add a method to determine whether the request mode is user mode, or after detecting the user mode address, use the writing method of the user mode address, such as __try __except and so on.

But I think the real reason is that the anti-virus software modified the address of MmGetSystemAddressForMdlNormalSafe() to point to user space, but this address is only valid in the current context. When dokany is executing DokanCompleteDirectoryControl(), this address is invalid.

from dokany.

Liryna avatar Liryna commented on June 20, 2024

Thanks @fcyinxunpeng ! I am not sure about their answer. I believe we do everything correctly. We try catch and lock the page when we receive the request

dokany/sys/dokan.c

Lines 590 to 600 in 69e3d88

RequestContext->Irp->MdlAddress =
IoAllocateMdl(RequestContext->Irp->UserBuffer, Length, FALSE, FALSE,
RequestContext->Irp);
if (RequestContext->Irp->MdlAddress == NULL) {
DOKAN_LOG_FINE_IRP(RequestContext, "IoAllocateMdl returned NULL");
return STATUS_INSUFFICIENT_RESOURCES;
}
__try {
MmProbeAndLockPages(RequestContext->Irp->MdlAddress,
RequestContext->Irp->RequestorMode, IoWriteAccess);

and only release when we no longer need it.
https://github.com/dokan-dev/dokany/blob/master/sys/directory.c#L323

I agree with you that they might not wait for our completion and do something with the buffer they gave us and things go wrong.

from dokany.

Liryna avatar Liryna commented on June 20, 2024

@fcyinxunpeng Were you able to get more info from Rising ?

from dokany.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.