none
TARGET_DEVICE_REMOVAL_NOTIFICATION structure versioning RRS feed

  • Question

  • We have a WDM driver that calls IoRegisterPlugPlayNotification with EventCategoryTargetDeviceChange. Windows will eventually call our callback routine with a TARGET_DEVICE_REMOVAL_NOTIFICATION structure. Should the callback routine validate the Version and Size members of this structure in some way?

    The documentation of TARGET_DEVICE_REMOVAL_NOTIFICATION says that Version is currently set to 1. If Microsoft later defines version 2 of this structure, can the callback routine assume that the members originally defined in version 1 still have the same offsets? If it cannot assume that, it will have to reject unsupported versions.

    I originally thought that Microsoft might use the Size member for backward-compatible extensions and the Version member for incompatible changes. However, in the similar structure DEVICE_INTERFACE_CHANGE_NOTIFICATION, the value of Size can vary for reasons that are not related to versioning. For that reason, I now think backward-compatible extensions will increment Version, and incompatible changes will involve a new GUID or a new registration routine, so the callback routine should not validate Version. It could still check that Size is large enough, but not even that is really necessary, because the PnP Manager will not send undersized notifications. Is this correct?

    Friday, May 30, 2014 11:32 AM

Answers

  • Validating the version and size fields certainly won't cause any harm, and in the unlikely event that the structure is revised then your driver will probably continue to work. It's been 15+ years since that structure was defined, so it is unlikely to change anytime soon.

     -Brian


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

    Friday, May 30, 2014 7:49 PM
    Moderator

All replies

  • Validating the version and size fields certainly won't cause any harm, and in the unlikely event that the structure is revised then your driver will probably continue to work. It's been 15+ years since that structure was defined, so it is unlikely to change anytime soon.

     -Brian


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

    Friday, May 30, 2014 7:49 PM
    Moderator
  • Thanks. In the end, I decided not to make the callback check the Version member, for the following reasons:

    • There must be numerous third-party drivers that don't check Version, because WDK samples don't check it and WDK tools don't test such checks. Microsoft will not want to break binary compatibility with those drivers.
    • If Microsoft ever extends the notification structures in a backward-compatible way, it seems likely that they'll increment Version at that time.
    Monday, June 2, 2014 4:01 PM