mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2025-11-11 19:08:26 -06:00
Windows Driver: Fix strange crashes caused by probably by APC queue issues from calls to IoBuildDeviceIoControlRequest and ZwCreate (cf https://www.osr.com/blog/2018/02/14/beware-iobuilddeviceiocontrolrequest/)
This commit is contained in:
@@ -886,6 +886,18 @@ void TCCloseVolume (PDEVICE_OBJECT DeviceObject, PEXTENSION Extension)
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
PDEVICE_OBJECT deviceObject; PEXTENSION Extension; ULONG ioControlCode; void *inputBuffer; int inputBufferSize; void *outputBuffer; int outputBufferSize;
|
||||
NTSTATUS Status;
|
||||
KEVENT WorkItemCompletedEvent;
|
||||
} TCSendHostDeviceIoControlRequestExWorkItemArgs;
|
||||
|
||||
static VOID TCSendHostDeviceIoControlRequestExWorkItemRoutine (PDEVICE_OBJECT rootDeviceObject, TCSendHostDeviceIoControlRequestExWorkItemArgs *arg)
|
||||
{
|
||||
arg->Status = TCSendHostDeviceIoControlRequestEx (arg->deviceObject, arg->Extension, arg->ioControlCode, arg->inputBuffer, arg->inputBufferSize, arg->outputBuffer, arg->outputBufferSize);
|
||||
KeSetEvent (&arg->WorkItemCompletedEvent, IO_NO_INCREMENT, FALSE);
|
||||
}
|
||||
|
||||
NTSTATUS TCSendHostDeviceIoControlRequestEx (PDEVICE_OBJECT DeviceObject,
|
||||
PEXTENSION Extension,
|
||||
@@ -901,6 +913,31 @@ NTSTATUS TCSendHostDeviceIoControlRequestEx (PDEVICE_OBJECT DeviceObject,
|
||||
|
||||
UNREFERENCED_PARAMETER(DeviceObject); /* Remove compiler warning */
|
||||
|
||||
if ((KeGetCurrentIrql() >= APC_LEVEL) || VC_KeAreAllApcsDisabled())
|
||||
{
|
||||
TCSendHostDeviceIoControlRequestExWorkItemArgs args;
|
||||
|
||||
PIO_WORKITEM workItem = IoAllocateWorkItem (RootDeviceObject);
|
||||
if (!workItem)
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
|
||||
args.deviceObject = DeviceObject;
|
||||
args.Extension = Extension;
|
||||
args.ioControlCode = IoControlCode;
|
||||
args.inputBuffer = InputBuffer;
|
||||
args.inputBufferSize = InputBufferSize;
|
||||
args.outputBuffer = OutputBuffer;
|
||||
args.outputBufferSize = OutputBufferSize;
|
||||
|
||||
KeInitializeEvent (&args.WorkItemCompletedEvent, SynchronizationEvent, FALSE);
|
||||
IoQueueWorkItem (workItem, TCSendHostDeviceIoControlRequestExWorkItemRoutine, DelayedWorkQueue, &args);
|
||||
|
||||
KeWaitForSingleObject (&args.WorkItemCompletedEvent, Executive, KernelMode, FALSE, NULL);
|
||||
IoFreeWorkItem (workItem);
|
||||
|
||||
return args.Status;
|
||||
}
|
||||
|
||||
KeClearEvent (&Extension->keVolumeEvent);
|
||||
|
||||
Irp = IoBuildDeviceIoControlRequest (IoControlCode,
|
||||
|
||||
Reference in New Issue
Block a user