none
Handling IRP_MJ_READ and IRP_MJ_WRITE in NDIS miniport driver RRS feed

  • Question

  • Hi All,

    I am going through a sample NDIS miniport driver. For handling IO with user mode program, the driver supports some ioctls to register and deregister user mode buffer. The user mode buffer is memory mapped for direct I/O and NDIS miniport driver creates MDL and takes the system virtual address. The NDIS miniport driver handles only two ioctls, one for register buffer and other for unregister buffer, for other IOCTLs, it calls the original ioctl handler in the driver object that the NDIS miniport driver received in the DriverEntry (DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL]). 

    My question is, the NDIS miniport driver is aware of the user buffer as it mapped to MDL/system address space. When the NDIS miniport driver is not handling IRP_MJ_READ/WRITE request, and forwards to upper driver, how the upper driver can access the MDL/system address space in order to satisfy the user mode request.
    Monday, February 10, 2020 9:01 PM

All replies

  • Which sample is this from? As far as I know, the IOCTL_NDISUIO_XXX features were only supported on Windows CE, which has been long deprecated

     -Brian


    Azius Developer Training www.azius.com Windows device driver, internals, security, & forensics training and consulting. Blog at www.azius.com/blog

    Tuesday, February 11, 2020 7:30 PM
  • I am going through the Wintun driver from Wireguard. The TunDispatchDeviceControl function handles only two ioctls. The user application creating an interface and installing the driver. Then it calls the CreateFile using the interface and do read/write by passing the handles to ReadFile/WriteFile.  As read/write requests are not handled in the driver code and passed to the NdisDispatchDeviceControl. How the request is satisfied. The driver basically copies the network packet to the user mapped buffer.

    TunDispatchDeviceControl(DEVICE_OBJECT *DeviceObject, IRP *Irp)
    {

    IO_STACK_LOCATION *Stack = IoGetCurrentIrpStackLocation(Irp);
    if (Stack->Parameters.DeviceIoControl.IoControlCode != TUN_IOCTL_REGISTER_RINGS &&
    Stack->Parameters.DeviceIoControl.IoControlCode != TUN_IOCTL_FORCE_CLOSE_HANDLES)
    return NdisDispatchDeviceControl(DeviceObject, Irp);

    Ref : https://github.com/WireGuard/wintun/blob/master/wintun.c


    • Edited by Boomi.s Tuesday, February 11, 2020 9:38 PM
    Tuesday, February 11, 2020 9:36 PM
  • Sorry, I'm not going to analyze someone else's code without getting paid. This forum is for asking specific questions. Perhaps there are others in the forum who have more free time and are willing to dig into this

     -Brian


    Azius Developer Training www.azius.com Windows device driver, internals, security, & forensics training and consulting. Blog at www.azius.com/blog

    Tuesday, February 11, 2020 9:53 PM