Using private IOCTL codes to communicate with a minifilter driver

Certain APIs can only be invoked in a minifilter I/O processing callback context. This can happen for example because these APIs send I/O below the specific FLT_INSTANCE used as a parameter. When the FILE_OBJECT comes from a non-minifilter component (Such as other kernel callbacks etc) it’s not safe to skip filters and send I/O below our minifilter instance. The problem is, In certain cases we need to be able to use these APIs outside of the minifilter callbacks.

One suggested solution to handle these kind of cases is to send an internal IOCTL on this FILE_OBJECT and handle PRE IRP_MJ_INTERNAL_DEVICE_CONTROL in our minifilter. If the IOCTL code fits to some magic code of ours, we assume it’s our request and now we can use these APIs because we run in the context of an I/O request (PreInternalDeviceControl). Obviously the problem with this suggested solution is that some other driver can use this same IOCTL code for it’s own purpose… In other words, It does not pass the ‘Our filter is stacked on top of itself’ test. We can mitigate this by putting a random GUID at the beginning of the request struct (So we will know that our driver generated the IRP) but it’s still not an elegant solution…

Is there any other way to solve this issue more elegantly? Is the suggested solution (Having some kind of non-public IOCTL code + putting a GUID signature field at the beginning of the input buffer) ok?

Thanks in advance,
Ori