none
DeviceIoControl() returns ERROR_NO_ACCESS RRS feed

  • Question

  • Hi

    I am trying to send a data using Ioctl call to my driver. this is my code

    #ifdef WIN32

    IOCTL_SET_PID_FN = 0x900

    #endif

    #ifdef WIN32
    // Device type - user defined
    #define DEV_TYPE 40000#define IOCTL_SET_PID_CMD \
        CTL_CODE( DEV_TYPE, IOCTL_SET_PID_FN, METHOD_BUFFERED , FILE_ANY_ACCESS  )
    #endif

    ULONG bytesReturned = 0;
    int pid = GetCurrentProcessId();

    mIoctlDeviceHandle = CreateFile(mDevNode,
    GENERIC_READ | GENERIC_WRITE,
    0,
    NULL,
    OPEN_EXISTING,
    FILE_ATTRIBUTE_NORMAL,
    NULL) ;

    if(mIoctlDeviceHandle == INVALID_HANDLE_VALUE)
    {
    errCode = GetLastError();
    }

    int rc  = (int)DeviceIoControl(
    mIoctlDeviceHandle,
    IOCTL_SET_PID_CMD,
    (int *)(pid), //input buffer
    sizeof(int),
    (int *)(pid), //output buffer
    (DWORD) MAX_BUFF_SIZE,
    &bytesReturned,
    NULL);


    if(!rc)
    {
    cout<<"Module ioctl failed  rc= "<< rc << "errno ="<< GetLastError();
    }

    Here in this code, DeviceIoControl() always returns 998 (ERROR_NO_ACCESS). I tried to run it with admin rights but same result. What could be the issue here? Also i am using win32 system only but #ifdef __WIN32__ returns false but #ifdef WIN32 returns true. Which one is correct to identify a windows system.?

    Thanks



    Manigandasuresh

    Thursday, March 14, 2013 11:52 AM

Answers

  • Pavels comments made me look at your code closer.  You are passing the value of Pid not its address to the DeviceIoControl call.  For most systems this will be in a page where you certainly have no access so the system won't be copying the buffer at that address.

    Take the address of Pid and fix the output buffer size to be the size of Pid if you don't want more problems.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr

    Thursday, March 14, 2013 4:30 PM

All replies

  • Well assuming you are checking errCode and mIoctlDeviceHandle so you are sure you have a valid handle, then this is something your driver is doing.  I suspect you are not getting a valid handle from the CreateFile since that is an easy way to messup.  Is you code running as administrator?  If not you need to set the security of the device with an SDDL string to allow general users to access it.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr

    Thursday, March 14, 2013 11:58 AM
  • I suspect you CreateFile is failing. Are you running this as Administrator?  If not you need to set the SDDL string for the device create to allow access from any user.  

    If you are getting a correct result froim CreateFile (I see the getting errCode but no test to stop the IOCTL), then your driver is probably returning STATUS_ACCESS_DENIED.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr

    Thursday, March 14, 2013 12:01 PM
  • I checked and CreateFile is returning a valid handle but i didn't receive any ioctl call in driver side.

    Manigandasuresh

    Thursday, March 14, 2013 1:16 PM
  • Pavels comments made me look at your code closer.  You are passing the value of Pid not its address to the DeviceIoControl call.  For most systems this will be in a page where you certainly have no access so the system won't be copying the buffer at that address.

    Take the address of Pid and fix the output buffer size to be the size of Pid if you don't want more problems.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr

    Thursday, March 14, 2013 4:30 PM