sending data upwards in a TDI filter driver

Hello all,

I have a TDI filter driver which crashes seldomly on one sistem when I send some data to the upper driver. My algorithm for sending the data is as follows:

  • I obtain the connection’s receive handler and context
  • I prepare the parameters for the receive handler
  • I release the connection lock (I do that because I noticed that in the disconnect handler sometimes the upper driver issues a disconnect IRP and to avoid a deadlock I always release the lock when sending IRPs down or calling connection handlers)
  • I call the receive handler
  • I reacquire the lock
  • if the return status of the handler is STATUS_DATA_NOT_ACCEPTED, I leave the data alone and wait for a TDI_RECEIVE IRP (if it didn’t already came)
  • otherwise I process the data further

The crash happens after I reacquire the lock and try to process the data. It is like TDI_RECEIVE IRP came allthough the receive handler returned STATUS_SUCCESS

My questions are:
1 - if the receive handler returned STATUS_DATA_NOT_ACCEPTED, the TDI_RECEIVE IRP will always come in another thread? (I’m thinking that the upper driver can send a TDI_RECEIVE before returning STATUS_DATA_NOT_ACCEPTED)
2 - It is safe to call the receive handler while holding a lock?
3 - If not, what is the best way to synchronize the receive handler and TDI_RECEIVE?

Thank you.