VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Driver/Driver.vcxproj
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2024-11-17 19:39:58 +0100
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2024-11-17 19:39:58 +0100
commit42fdbcf3ce37c33f777773a49d02dac6258c8dac (patch)
tree0eb909ef2b1f69a6819cda0a98dd81c809dd4786 /src/Driver/Driver.vcxproj
parent22c93dd64c7fd74fd917ed165bf8c29858ae29b9 (diff)
downloadVeraCrypt-42fdbcf3ce37c33f777773a49d02dac6258c8dac.tar.gz
VeraCrypt-42fdbcf3ce37c33f777773a49d02dac6258c8dac.zip
Windows Driver: Fix deadlock in EncryptedIoQueue due to re-entrant IRP completions
There was a deadlock issue in the driver caused by the CompletionThreadProc function in EncryptedIoQueue.c: https://sourceforge.net/p/veracrypt/discussion/general/thread/f6e7f623d0/?page=20&limit=25#8362 The driver uses a single thread (CompletionThreadProc) to process IRP completions. When IoCompleteRequest is called within this thread, it can result in new IRPs being generated (e.g., for pagefile operations) that are intercepted by the driver and queued back into the CompletionThreadQueue. Since CompletionThreadProc is the only thread processing this queue and is waiting on IoCompleteRequest, these new IRPs are not handled, leading to a system freeze. To resolve this issue, the following changes have been made: Deferred IRP Completion Using Pre-allocated Work Items: - Introduced a pool of pre-allocated work items (COMPLETE_IRP_WORK_ITEM) to handle IRP completions without causing additional resource allocations that could trigger new IRPs. - The CompletionThreadProc now queues IRP completions to these work items, which are processed in a different context using IoQueueWorkItem, preventing re-entrant IRPs from blocking the completion thread. Thread-Safe Work Item Pool Management: - Implemented a thread-safe mechanism using a semaphore (WorkItemSemaphore), spin lock (WorkItemLock), and a free list (FreeWorkItemsList) to manage the pool of work items. - Threads acquire and release work items safely, and if all work items are busy, threads wait until one becomes available. Reference Counting and Improved Stop Handling: - Added an ActiveWorkItems counter to track the number of active work items. - Modified EncryptedIoQueueStop to wait for all active work items to complete before proceeding with cleanup, ensuring a clean shutdown. These changes address the deadlock issue by preventing CompletionThreadProc from being blocked by re-entrant IRPs generated during IoCompleteRequest. By deferring IRP completion to a different context using pre-allocated work items and managing resources properly, we avoid the deadlock and ensure that all IRPs are processed correctly.
Diffstat (limited to 'src/Driver/Driver.vcxproj')
0 files changed, 0 insertions, 0 deletions