none
IoOpenDeviceRegistryKey in user thread context RRS feed

  • Question

  • I found a bug in a WDM driver of ours. The documentation of IoOpenDeviceRegistryKey says it must be called "in the context of a system thread", but the driver sometimes calls it from within a dispatch routine in a user thread. (Strangely, the documentation of WdfDeviceOpenRegistryKey mentions no such requirement.)

    How serious problems can this bug cause? On Windows 7 SP1, it looks like the resulting handle will be a kernel handle either way, the access check will have PreviousMode = KernelMode, and the ERESOURCE operations within IoOpenDeviceRegistryKey first disable normal kernel APCs so that user-mode code cannot suspend the thread. I don't see what would actually go wrong, then. I didn't check other versions of Windows, though.

    As a fix, would it be reasonable to call IoOpenDeviceRegistryKey just once in a system thread and then keep the handle in the device extension? I suppose it might prevent processes from deleting the key, which seems OK, and it would consume some memory, but not too much.

    Tuesday, September 30, 2014 11:12 AM

Answers

  • Most drivers, call IoOpenDeviceRegistryKey as part of AddDevice to get parameters, so it is not a surprising restriction.  There should be nothing wrong with saving the handle and accessing it later.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com

    Tuesday, September 30, 2014 11:45 AM

All replies

  • Most drivers, call IoOpenDeviceRegistryKey as part of AddDevice to get parameters, so it is not a surprising restriction.  There should be nothing wrong with saving the handle and accessing it later.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com

    Tuesday, September 30, 2014 11:45 AM
  • Thanks. Although we aren't porting the driver to WDF at this time, I still wonder about WdfDeviceOpenRegistryKey and WdfFdoInitOpenRegistryKey. I'd expect them to call IoOpenDeviceRegistryKey internally, so why don't they have the same system-thread requirement?

    Tuesday, September 30, 2014 1:03 PM
  • they do transitively. the docs for the KMDF functions just don't make the underlying docs for IoOpenDeviceRegistryKey. File a bug against the docs (use the send feedback link) and the documentation can reflect that the restriction is no longer applicable.

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Tuesday, September 30, 2014 5:12 PM