Hello,
In my TDI filter driver (tdiflt.sys) I am replacing the connect event handler and context with my own when I receive IRP_MJ_INTERNAL_DEVICE_CONTROL/TDI_SET_EVENT_HANDLER. My goal is to be able to do some pre an post processing on incoming connections.
When my connect event handler is called, I call the original connect handler and then on the acceptIrp received from the original connect handler, I do something like below.
irp = *acceptIrp;
if (irp->CurrentLocation <= 1) {
goto contextfree;
}
IoCopyCurrentIrpStackLocationToNext(irp);
IoSetCompletionRoutine(irp,
TdiIrpComplete,
tdiIrpContext,
TRUE,
TRUE,
TRUE);
IoSetNextIrpStackLocation(irp);
From TdiIrpComplete, I call IoCompleteRequest(tdiIrpContext->tdiIrp, IO_NO_INCREMENT);
This all usually works fine. However, sporadically I get crash in netbt.sys when I call IoCompleteRequest.
95f9bc04 82a95222 badb0d00 00000004 00000000 nt!KiTrap0E+0x2cf
95f9bc74 87dd6e7e 865340c3 86534008 00000000 nt!KefAcquireSpinLockAtDpcLevel+0x2
95f9bc94 82a95933 00000000 86534008 00c9f1d0 netbt!AcceptCompletionRoutine+0x35
95f9bcdc 8813c02d 87a858a8 8656d428 95f9bd00 nt!IopfCompleteRequest+0x128
95f9bcec 82c31466 8656d428 988fa008 85f9a8a8 tdiflt!TdiIrpComplete+0x25
95f9bd00 82a9aaab 87a858a8 00000000 85f9a8a8 nt!IopProcessWorkItem+0x23
95f9bd50 82c25f64 80000001 bd13a8c9 00000000 nt!ExpWorkerThread+0x10d
95f9bd90 82ace219 82a9a99e 80000001 00000000 nt!PspSystemThreadStartup+0x9e
00000000 00000000 00000000 00000000 00000000 nt!KiThreadStartup+0x19
Any idea what can cause this? It seems that netdt completion routine is passed wrong context and it’s attempting to deference it and crashing?
Searching various samples available on google, I found few alternate ways to do this
- Replace the completionRoutine and context in the acceptIrp with my own and then calling the original completion routine from my completion routine.
- Create a new accept IRP and set the stack location.
So basically two questions.
- Thoughts on why the method I am using lead to crash in netbt.
- Are other approaches mentioned above are better than the one I am using.
Would appreciate thoughts from experts.
Thanks.
-Prasad