VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkavsrf <kavsrf@gmail.com>2016-12-10 15:07:56 +0300
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2016-12-26 00:00:02 +0100
commitac53e293d4c6ac06e1376c28cb8b96efb844bc75 (patch)
treed7b96fec6fa12b073ff1262023578c64b477097b /src
parentcd6df44d6f0e31bb81595f69691443cf1e4b21cf (diff)
downloadVeraCrypt-ac53e293d4c6ac06e1376c28cb8b96efb844bc75.tar.gz
VeraCrypt-ac53e293d4c6ac06e1376c28cb8b96efb844bc75.zip
comments and better cleanup
Signed-off-by: kavsrf <kavsrf@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/Driver/DriveFilter.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/src/Driver/DriveFilter.c b/src/Driver/DriveFilter.c
index b8aad224..47a592dd 100644
--- a/src/Driver/DriveFilter.c
+++ b/src/Driver/DriveFilter.c
@@ -135,6 +135,7 @@ NTSTATUS LoadBootArguments ()
135 burn (BootLoaderFingerprint, sizeof (BootLoaderFingerprint)); 135 burn (BootLoaderFingerprint, sizeof (BootLoaderFingerprint));
136 MmUnmapIoSpace (mappedBootArgs, sizeof (BootArguments)); 136 MmUnmapIoSpace (mappedBootArgs, sizeof (BootArguments));
137 137
138 // Extra parameters? (pkcs5, hash)
138 if (BootArgs.CryptoInfoLength > 0) 139 if (BootArgs.CryptoInfoLength > 0)
139 { 140 {
140 PHYSICAL_ADDRESS cryptoInfoAddress; 141 PHYSICAL_ADDRESS cryptoInfoAddress;
@@ -146,11 +147,12 @@ NTSTATUS LoadBootArguments ()
146 { 147 {
147 /* Get the parameters used for booting to speed up driver startup and avoid testing irrelevant PRFs */ 148 /* Get the parameters used for booting to speed up driver startup and avoid testing irrelevant PRFs */
148 BOOT_CRYPTO_HEADER* pBootCryptoInfo = (BOOT_CRYPTO_HEADER*) mappedCryptoInfo; 149 BOOT_CRYPTO_HEADER* pBootCryptoInfo = (BOOT_CRYPTO_HEADER*) mappedCryptoInfo;
149 BootPkcs5 = pBootCryptoInfo->pkcs5; 150 BootPkcs5 = pBootCryptoInfo->pkcs5; // save hash to speed up boot.
150 151
151 BootSecRegionData = NULL; 152 BootSecRegionData = NULL;
152 BootSecRegionSize = 0; 153 BootSecRegionSize = 0;
153 154
155 // SecRegion data?
154 if(BootArgs.CryptoInfoLength > (sizeof(BOOT_CRYPTO_HEADER) + sizeof(SECREGION_BOOT_PARAMS)) ) { 156 if(BootArgs.CryptoInfoLength > (sizeof(BOOT_CRYPTO_HEADER) + sizeof(SECREGION_BOOT_PARAMS)) ) {
155 uint32 crc; 157 uint32 crc;
156 PHYSICAL_ADDRESS SecRegionAddress; 158 PHYSICAL_ADDRESS SecRegionAddress;
@@ -159,25 +161,27 @@ NTSTATUS LoadBootArguments ()
159 161
160 SecRegionAddress.QuadPart = SecRegionParams->Ptr; 162 SecRegionAddress.QuadPart = SecRegionParams->Ptr;
161 Dump ("SecRegion memory 0x%x %d\n", SecRegionAddress.LowPart, SecRegionParams->Size); 163 Dump ("SecRegion memory 0x%x %d\n", SecRegionAddress.LowPart, SecRegionParams->Size);
162 164 // SecRegion correct?
163 if( (SecRegionParams->Ptr != 0) && (SecRegionParams->Size > 0)) { 165 if( (SecRegionParams->Ptr != 0) && (SecRegionParams->Size > 0)) {
164 crc = GetCrc32((byte*)SecRegionParams, 12); 166 crc = GetCrc32((byte*)SecRegionParams, 12);
165 if(crc == SecRegionParams->Crc) { 167 if(crc == SecRegionParams->Crc) {
166 Dump ("SecRegion crc ok\n"); 168 Dump ("SecRegion crc ok\n");
167 secRegionData = MmMapIoSpace (SecRegionAddress, SecRegionParams->Size, MmCached); 169 secRegionData = MmMapIoSpace (SecRegionAddress, SecRegionParams->Size, MmCached);
168 BootSecRegionData = TCalloc (SecRegionParams->Size); 170 if(secRegionData) {
169 if(BootSecRegionData != NULL) { 171 BootSecRegionData = TCalloc (SecRegionParams->Size);
170 BootSecRegionSize = SecRegionParams->Size; 172 if(BootSecRegionData != NULL) {
171 memcpy(BootSecRegionData, secRegionData, SecRegionParams->Size); 173 BootSecRegionSize = SecRegionParams->Size;
174 memcpy(BootSecRegionData, secRegionData, SecRegionParams->Size);
175 }
176 burn (secRegionData, SecRegionParams->Size);
177 MmUnmapIoSpace (secRegionData, SecRegionParams->Size);
172 } 178 }
173 burn (secRegionData, SecRegionParams->Size);
174 MmUnmapIoSpace (secRegionData, SecRegionParams->Size);
175 } 179 }
176 // Erase boot loader scheduled keys
177 burn (mappedCryptoInfo, BootArgs.CryptoInfoLength);
178 MmUnmapIoSpace (mappedCryptoInfo, BootArgs.CryptoInfoLength);
179 } 180 }
180 } 181 }
182 // Erase boot loader scheduled keys
183 burn (mappedCryptoInfo, BootArgs.CryptoInfoLength);
184 MmUnmapIoSpace (mappedCryptoInfo, BootArgs.CryptoInfoLength);
181 } 185 }
182 } 186 }
183 status = STATUS_SUCCESS; 187 status = STATUS_SUCCESS;
@@ -371,6 +375,7 @@ static NTSTATUS MountDrive (DriveFilterExtension *Extension, Password *password,
371 Dump ("MountDrive pdo=%p\n", Extension->Pdo); 375 Dump ("MountDrive pdo=%p\n", Extension->Pdo);
372 ASSERT (KeGetCurrentIrql() == PASSIVE_LEVEL); 376 ASSERT (KeGetCurrentIrql() == PASSIVE_LEVEL);
373 377
378 // Check disk MBR id and GPT ID if BootSecRegion is available to detect boot drive
374 if (BootSecRegionData != NULL && BootSecRegionSize >= 1024) { 379 if (BootSecRegionData != NULL && BootSecRegionSize >= 1024) {
375 byte mbr[TC_SECTOR_SIZE_BIOS]; 380 byte mbr[TC_SECTOR_SIZE_BIOS];
376 DCS_DISK_ENTRY_LIST* DeList = (DCS_DISK_ENTRY_LIST*)(BootSecRegionData + 512); 381 DCS_DISK_ENTRY_LIST* DeList = (DCS_DISK_ENTRY_LIST*)(BootSecRegionData + 512);
@@ -388,8 +393,10 @@ static NTSTATUS MountDrive (DriveFilterExtension *Extension, Password *password,
388 header = TCalloc (TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE); 393 header = TCalloc (TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE);
389 if (!header) 394 if (!header)
390 return STATUS_INSUFFICIENT_RESOURCES; 395 return STATUS_INSUFFICIENT_RESOURCES;
396 // Copy header from SecRegion instead of read from disk
391 memcpy(header, BootSecRegionData, 512); 397 memcpy(header, BootSecRegionData, 512);
392 // Set extra data for the disk 398
399 // Set SecRegion data for the disk (sectors to substitute to hide GPT table)
393 Extension->Queue.SecRegionData = BootSecRegionData; 400 Extension->Queue.SecRegionData = BootSecRegionData;
394 Extension->Queue.SecRegionSize = BootSecRegionSize; 401 Extension->Queue.SecRegionSize = BootSecRegionSize;
395 } else { 402 } else {
@@ -538,6 +545,7 @@ static NTSTATUS MountDrive (DriveFilterExtension *Extension, Password *password,
538 BootDriveFound = Extension->BootDrive = Extension->DriveMounted = Extension->VolumeHeaderPresent = TRUE; 545 BootDriveFound = Extension->BootDrive = Extension->DriveMounted = Extension->VolumeHeaderPresent = TRUE;
539 BootDriveFilterExtension->MagicNumber = TC_BOOT_DRIVE_FILTER_EXTENSION_MAGIC_NUMBER; 546 BootDriveFilterExtension->MagicNumber = TC_BOOT_DRIVE_FILTER_EXTENSION_MAGIC_NUMBER;
540 547
548 // Try to load password cached if saved in SecRegion
541 if (BootSecRegionData != NULL && BootSecRegionSize > 1024) { 549 if (BootSecRegionData != NULL && BootSecRegionSize > 1024) {
542 DCS_DISK_ENTRY_LIST* DeList = (DCS_DISK_ENTRY_LIST*)(BootSecRegionData + 512); 550 DCS_DISK_ENTRY_LIST* DeList = (DCS_DISK_ENTRY_LIST*)(BootSecRegionData + 512);
543 uint32 crc; 551 uint32 crc;