1
0
mirror of https://github.com/veracrypt/VeraCrypt.git synced 2025-11-11 02:58:02 -06:00
Commit Graph

27 Commits

Author SHA1 Message Date
Mounir IDRASSI
7df2c2957f Windows driver fix: Decrement IoThreadPendingRequestCount on allocation failure in MainThreadProc
Added InterlockedDecrement in the error path when GetPoolBuffer fails for EncryptedIoRequest to ensure accurate tracking of pending IO requests and prevent potential resource leaks.
2025-09-08 11:40:33 +09:00
Mounir IDRASSI
f40f316dfb Windows driver: remove unneeded __try/__finally 2025-09-08 11:38:30 +09:00
Mounir IDRASSI
0e19cb9223 Windows driver: harden UpdateBuffer against integer overflow. Make completion backoff per request (no shared state) 2025-09-08 10:36:18 +09:00
Mounir IDRASSI
062b385a69 Windows driver: overhaul IRP completion path in EncryptedIoQueue, add dual completion threads, precise byte accounting & safer UpdateBuffer
Major changes:
- Added pooled + elastic work item model with retry/backoff (MAX_WI_RETRIES). removed semaphore usage.
- Introduced two completion threads to reduce contention and latency under heavy IO.
- Added BytesCompleted (per IRP) and ActualBytes (per fragment) for correct short read/write accounting. total read/write stats now reflect real transferred bytes instead of requested length.
- Moved decryption of read fragments into IO thread. completion threads now only finalize IRPs (reduces race window and simplifies flow).
- Deferred final IRP completion via FinalizeOriginalIrp to avoid inline IoCompleteRequest re-entrancy. added safe OOM inline fallback.
- Implemented work item pool drain & orderly shutdown (ActiveWorkItems + NoActiveWorkItemsEvent) with robust stop protocol.
- Replaced semaphore-based work item acquisition with spin lock + free list + event (WorkItemAvailableEvent). added exponential backoff for transient exhaustion.
- Added elastic (on-demand) work item allocation with pool vs dynamic origin tracking (FromPool).
- Added FreeCompletionWorkItemPool() for symmetric cleanup; ensured all threads are explicitly awakened during stop.
- Added second completion thread replacing single CompletionThread.
- Hardened UpdateBuffer: fixed parameter name typo, added bounds/overflow checks using IntSafe (ULongLongAdd), validated Count, guarded sector end computation.
- Fixed GPT/system region write protection logic to pass correct length instead of end offset.
- Ensured ASSERTs use fragment‑relative bounds (cast + length) and avoided mixed 64/32 comparisons.
- Added MAX_WI_RETRIES constant. added WiRetryCount field in EncryptedIoRequest.
- Ensured RemoveLock is released only after all queue/accounting updates (OnItemCompleted).
- Reset/read-ahead logic preserved. read-ahead trigger now based on actual completion & zero pending fragment count.
- General refactoring, clearer separation of concerns (TryAcquireCompletionWorkItem / FinalizeOriginalIrp / HandleCompleteOriginalIrp).

Safety / correctness improvements:
- Accurate short read handling (STATUS_END_OF_FILE with true byte count).
- Eliminated risk of double free or premature RemoveLock release on completion paths.
- Prevented potential overflow in sector end arithmetic.
- Reduced contention and potential deadlock scenarios present with previous semaphore wait path.
2025-09-07 23:58:35 +09:00
Mounir IDRASSI
b673901503 Move copyright and links to "AM Crypo", amcrypto.jp and veracrypt.jp 2025-05-11 16:02:20 +09:00
Mounir IDRASSI
1b35abb191 Increment version to 1.26.18. Update copyright date. Update Release Notes. Update Windows drivers. 2025-01-14 12:26:28 +01:00
Mounir IDRASSI
f3af65b007 Windows driver: Use IO_DISK_INCREMENT for event signaling in IRP completion routine
This provides a slight priority boost for waiting threads and maintains standard practice for disk device drivers.
2024-12-25 17:58:12 +01:00
Mounir IDRASSI
283059523d Windows Driver: make UpdateBuffer function more robust by adding security region size parameter 2024-12-25 16:09:10 +01:00
Mounir IDRASSI
453ff2880e Windows Driver: Make max work items count configurable. Increase default to 1024. Queue write IRPs.
- Made the maximum work items count configurable to allow flexibility based on system needs.
  - Increased the default value of max work items count to 1024 to better handle high-throughput scenarios.
  - Queue write IRPs in system worker thread to avoid potential deadlocks in write scenarios.
2024-11-23 17:44:48 +01:00
Mounir IDRASSI
5a85c54c6e Windows Driver: Optimize spinlock usage in CompleteIrpWorkItemRoutine
Reduce the critical section protected by spinlock to only cover the list manipulation operation. Move the ActiveWorkItems counter decrement outside the spinlock using InterlockedDecrement, and separate event signaling from the locked section.
This change minimizes time spent at raised IRQL (DISPATCH_LEVEL) and reduces potential for lock contention.
2024-11-22 15:19:10 +01:00
Mounir IDRASSI
42fdbcf3ce 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.
2024-11-17 19:39:58 +01:00
Mounir IDRASSI
cb97351250 Windows: Remove support for 32-bit driver code. Set build target as Windows 10. Simplify code and fix all warnings in driver. 2024-11-13 02:08:51 +01:00
Mounir IDRASSI
455a4f2176 Avoid conflict with C++17 features std::byte by using uint8 type instead of byte 2024-06-12 12:30:04 +02:00
Mounir IDRASSI
f84d235cf1 Windows: Implement support for mounting partially encrypted system partitions
For now, we force ReadOnly mounting for such partitions.
2023-08-13 22:50:37 +02:00
Mounir IDRASSI
5640de3584 Windows Driver: Add registry settings to control driver internal encryption queue Under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\veracrypt: - VeraCryptEncryptionFragmentSize (REG_DWORD): size of encryption data fragment in KiB. Default is 256. - VeraCryptEncryptionIoRequestCount (REG_DWORD): maximum number of parallel I/O requests. Default is 16. - VeraCryptEncryptionItemCount (REG_DWORD): maximum number of encryption queue items processed in parallel. Default is 8. 2021-12-20 00:18:58 +01:00
Mounir IDRASSI
3281b276b6 Windows: Fix various warnings 2021-01-02 01:16:40 +01:00
Mounir IDRASSI
652e989d23 Windows Security: Add new entry point in driver that allows emergency clearing of all encryption keys from memory. This entry point requires administrative privileges and it will caused BSDO when system encryption is active. It can be useful for example to applications that monitors physical access to the machine and which need to erase sensitive key material from RAM when unauthorized access is detected. 2019-01-09 00:30:12 +01:00
Mounir IDRASSI
0ebc26e125 Update IDRIX copyright year 2017-06-23 22:15:59 +02:00
Mounir IDRASSI
458bb091bb Windows Driver Security: Use enhanced protection of NX pool under Windows 8 and later. 2017-06-10 18:44:49 +02:00
kavsrf
cd6df44d6f Driver with support of hidden OS
Signed-off-by: kavsrf <kavsrf@gmail.com>
2016-12-26 00:00:02 +01:00
David Foerster
11716ed2da Remove trailing whitespace 2016-05-10 22:18:34 +02:00
David Foerster
fc37cc4a02 Normalize all line terminators 2016-05-10 20:20:14 +02:00
Mounir IDRASSI
bda7a1d0bd Copyright: update dates to include 2016. 2016-01-20 00:53:24 +01:00
Mounir IDRASSI
041024fbb9 Update license information to reflect the use of a dual license Apache 2.0 and TrueCrypt 3.0. 2015-08-06 00:04:25 +02:00
Mounir IDRASSI
7c501359b3 Windows vulnerability fix: correct some integer overflow issues using the IntSafe library. Detected by the Open Crypto Audit project 2014-11-08 23:23:10 +01:00
Mounir IDRASSI
3137d36d9a Static Code Analysis : Use Safe string functions inside VeraCrypt Device Driver to avoid potential security issues. Add many checks for NULL pointers to handle low memory use cases. 2014-11-08 23:21:04 +01:00
Mounir IDRASSI
c606f0866c Add original TrueCrypt 7.1a sources 2014-11-08 23:18:07 +01:00