diff options
author | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2016-12-13 09:40:47 +0100 |
---|---|---|
committer | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2016-12-26 00:00:03 +0100 |
commit | 9b0669da2980f53d5f1c3d3017bd182a9d367281 (patch) | |
tree | 160befaae07053740e95ae6844b85ff0a94bdb7f /src | |
parent | ac53e293d4c6ac06e1376c28cb8b96efb844bc75 (diff) | |
download | VeraCrypt-9b0669da2980f53d5f1c3d3017bd182a9d367281.tar.gz VeraCrypt-9b0669da2980f53d5f1c3d3017bd182a9d367281.zip |
Windows driver: fix reading of boot PRF after latest EFI hidden OS changes. Better memory cleanup and changes for code clarity.
Diffstat (limited to 'src')
-rw-r--r-- | src/Driver/DriveFilter.c | 69 |
1 files changed, 32 insertions, 37 deletions
diff --git a/src/Driver/DriveFilter.c b/src/Driver/DriveFilter.c index 47a592dd..8195fe35 100644 --- a/src/Driver/DriveFilter.c +++ b/src/Driver/DriveFilter.c | |||
@@ -35,7 +35,7 @@ BOOL BootArgsValid = FALSE; | |||
35 | BootArguments BootArgs; | 35 | BootArguments BootArgs; |
36 | byte* BootSecRegionData = NULL; | 36 | byte* BootSecRegionData = NULL; |
37 | uint32 BootSecRegionSize = 0; | 37 | uint32 BootSecRegionSize = 0; |
38 | uint32 BootPkcs5; | 38 | uint32 BootPkcs5 = 0; |
39 | 39 | ||
40 | static uint64 BootLoaderArgsPtr; | 40 | static uint64 BootLoaderArgsPtr; |
41 | static BOOL BootDriveSignatureValid = FALSE; | 41 | static BOOL BootDriveSignatureValid = FALSE; |
@@ -107,6 +107,9 @@ NTSTATUS LoadBootArguments () | |||
107 | && bootArguments->BootArgumentsCrc32 != GetCrc32 ((byte *) bootArguments, (int) ((byte *) &bootArguments->BootArgumentsCrc32 - (byte *) bootArguments))) | 107 | && bootArguments->BootArgumentsCrc32 != GetCrc32 ((byte *) bootArguments, (int) ((byte *) &bootArguments->BootArgumentsCrc32 - (byte *) bootArguments))) |
108 | { | 108 | { |
109 | Dump ("BootArguments CRC incorrect\n"); | 109 | Dump ("BootArguments CRC incorrect\n"); |
110 | burn (mappedBootArgs, sizeof (BootArguments)); | ||
111 | MmUnmapIoSpace (mappedBootArgs, sizeof (BootArguments)); | ||
112 | mappedBootArgs = NULL; | ||
110 | TC_BUG_CHECK (STATUS_CRC_ERROR); | 113 | TC_BUG_CHECK (STATUS_CRC_ERROR); |
111 | } | 114 | } |
112 | 115 | ||
@@ -134,6 +137,7 @@ NTSTATUS LoadBootArguments () | |||
134 | // clear fingerprint | 137 | // clear fingerprint |
135 | burn (BootLoaderFingerprint, sizeof (BootLoaderFingerprint)); | 138 | burn (BootLoaderFingerprint, sizeof (BootLoaderFingerprint)); |
136 | MmUnmapIoSpace (mappedBootArgs, sizeof (BootArguments)); | 139 | MmUnmapIoSpace (mappedBootArgs, sizeof (BootArguments)); |
140 | mappedBootArgs = NULL; | ||
137 | 141 | ||
138 | // Extra parameters? (pkcs5, hash) | 142 | // Extra parameters? (pkcs5, hash) |
139 | if (BootArgs.CryptoInfoLength > 0) | 143 | if (BootArgs.CryptoInfoLength > 0) |
@@ -182,11 +186,26 @@ NTSTATUS LoadBootArguments () | |||
182 | // Erase boot loader scheduled keys | 186 | // Erase boot loader scheduled keys |
183 | burn (mappedCryptoInfo, BootArgs.CryptoInfoLength); | 187 | burn (mappedCryptoInfo, BootArgs.CryptoInfoLength); |
184 | MmUnmapIoSpace (mappedCryptoInfo, BootArgs.CryptoInfoLength); | 188 | MmUnmapIoSpace (mappedCryptoInfo, BootArgs.CryptoInfoLength); |
189 | BootArgs.CryptoInfoLength = 0; | ||
190 | } | ||
191 | else | ||
192 | { | ||
193 | BootArgs.CryptoInfoLength = 0; | ||
185 | } | 194 | } |
186 | } | 195 | } |
187 | status = STATUS_SUCCESS; | 196 | status = STATUS_SUCCESS; |
188 | } | 197 | } |
189 | } else { | 198 | else |
199 | { | ||
200 | Dump ("BootArguments contains a password larger than maximum limit\n"); | ||
201 | burn (mappedBootArgs, sizeof (BootArguments)); | ||
202 | MmUnmapIoSpace (mappedBootArgs, sizeof (BootArguments)); | ||
203 | mappedBootArgs = NULL; | ||
204 | TC_BUG_CHECK (STATUS_FAIL_CHECK); | ||
205 | } | ||
206 | } | ||
207 | |||
208 | if (mappedBootArgs) { | ||
190 | MmUnmapIoSpace (mappedBootArgs, sizeof (BootArguments)); | 209 | MmUnmapIoSpace (mappedBootArgs, sizeof (BootArguments)); |
191 | } | 210 | } |
192 | } | 211 | } |
@@ -368,7 +387,6 @@ static NTSTATUS MountDrive (DriveFilterExtension *Extension, Password *password, | |||
368 | LARGE_INTEGER offset; | 387 | LARGE_INTEGER offset; |
369 | char *header; | 388 | char *header; |
370 | int pkcs5_prf = 0, pim = 0; | 389 | int pkcs5_prf = 0, pim = 0; |
371 | byte *mappedCryptoInfo = NULL; | ||
372 | PARTITION_INFORMATION_EX pi; | 390 | PARTITION_INFORMATION_EX pi; |
373 | BOOL bIsGPT = FALSE; | 391 | BOOL bIsGPT = FALSE; |
374 | 392 | ||
@@ -454,23 +472,12 @@ static NTSTATUS MountDrive (DriveFilterExtension *Extension, Password *password, | |||
454 | bIsGPT = (pi.PartitionStyle == PARTITION_STYLE_GPT)? TRUE : FALSE; | 472 | bIsGPT = (pi.PartitionStyle == PARTITION_STYLE_GPT)? TRUE : FALSE; |
455 | } | 473 | } |
456 | 474 | ||
457 | if (BootArgs.CryptoInfoLength > 0) | 475 | if (BootPkcs5 > 0) |
458 | { | 476 | { |
459 | PHYSICAL_ADDRESS cryptoInfoAddress; | 477 | /* Get the parameters used for booting to speed up driver startup and avoid testing irrelevant PRFs */ |
460 | 478 | Hash* pHash = HashGet(BootPkcs5); | |
461 | cryptoInfoAddress.QuadPart = BootLoaderArgsPtr + BootArgs.CryptoInfoOffset; | 479 | if (pHash && (bIsGPT || pHash->SystemEncryption)) |
462 | #ifdef DEBUG | 480 | pkcs5_prf = BootPkcs5; |
463 | Dump ("Wiping memory %x %d\n", cryptoInfoAddress.LowPart, BootArgs.CryptoInfoLength); | ||
464 | #endif | ||
465 | mappedCryptoInfo = MmMapIoSpace (cryptoInfoAddress, BootArgs.CryptoInfoLength, MmCached); | ||
466 | if (mappedCryptoInfo) | ||
467 | { | ||
468 | /* Get the parameters used for booting to speed up driver startup and avoid testing irrelevant PRFs */ | ||
469 | BOOT_CRYPTO_HEADER* pBootCryptoInfo = (BOOT_CRYPTO_HEADER*) mappedCryptoInfo; | ||
470 | Hash* pHash = HashGet(pBootCryptoInfo->pkcs5); | ||
471 | if (pHash && (bIsGPT || pHash->SystemEncryption)) | ||
472 | pkcs5_prf = pBootCryptoInfo->pkcs5; | ||
473 | } | ||
474 | } | 481 | } |
475 | 482 | ||
476 | pim = (int) (BootArgs.Flags >> 16); | 483 | pim = (int) (BootArgs.Flags >> 16); |
@@ -499,13 +506,7 @@ static NTSTATUS MountDrive (DriveFilterExtension *Extension, Password *password, | |||
499 | 506 | ||
500 | if (Extension->Queue.CryptoInfo->VolumeSize.Value > hiddenPartitionOffset - BootArgs.DecoySystemPartitionStart) | 507 | if (Extension->Queue.CryptoInfo->VolumeSize.Value > hiddenPartitionOffset - BootArgs.DecoySystemPartitionStart) |
501 | { | 508 | { |
502 | // Erase boot loader scheduled keys | 509 | // we have already erased boot loader scheduled keys |
503 | if (mappedCryptoInfo) | ||
504 | { | ||
505 | burn (mappedCryptoInfo, BootArgs.CryptoInfoLength); | ||
506 | MmUnmapIoSpace (mappedCryptoInfo, BootArgs.CryptoInfoLength); | ||
507 | BootArgs.CryptoInfoLength = 0; | ||
508 | } | ||
509 | TC_THROW_FATAL_EXCEPTION; | 510 | TC_THROW_FATAL_EXCEPTION; |
510 | } | 511 | } |
511 | 512 | ||
@@ -533,13 +534,7 @@ static NTSTATUS MountDrive (DriveFilterExtension *Extension, Password *password, | |||
533 | Dump ("Loaded: ConfiguredEncryptedAreaStart=%I64d (%I64d) ConfiguredEncryptedAreaEnd=%I64d (%I64d)\n", Extension->ConfiguredEncryptedAreaStart / 1024 / 1024, Extension->ConfiguredEncryptedAreaStart, Extension->ConfiguredEncryptedAreaEnd / 1024 / 1024, Extension->ConfiguredEncryptedAreaEnd); | 534 | Dump ("Loaded: ConfiguredEncryptedAreaStart=%I64d (%I64d) ConfiguredEncryptedAreaEnd=%I64d (%I64d)\n", Extension->ConfiguredEncryptedAreaStart / 1024 / 1024, Extension->ConfiguredEncryptedAreaStart, Extension->ConfiguredEncryptedAreaEnd / 1024 / 1024, Extension->ConfiguredEncryptedAreaEnd); |
534 | Dump ("Loaded: EncryptedAreaStart=%I64d (%I64d) EncryptedAreaEnd=%I64d (%I64d)\n", Extension->Queue.EncryptedAreaStart / 1024 / 1024, Extension->Queue.EncryptedAreaStart, Extension->Queue.EncryptedAreaEnd / 1024 / 1024, Extension->Queue.EncryptedAreaEnd); | 535 | Dump ("Loaded: EncryptedAreaStart=%I64d (%I64d) EncryptedAreaEnd=%I64d (%I64d)\n", Extension->Queue.EncryptedAreaStart / 1024 / 1024, Extension->Queue.EncryptedAreaStart, Extension->Queue.EncryptedAreaEnd / 1024 / 1024, Extension->Queue.EncryptedAreaEnd); |
535 | 536 | ||
536 | // Erase boot loader scheduled keys | 537 | // at this stage, we have already erased boot loader scheduled keys |
537 | if (mappedCryptoInfo) | ||
538 | { | ||
539 | burn (mappedCryptoInfo, BootArgs.CryptoInfoLength); | ||
540 | MmUnmapIoSpace (mappedCryptoInfo, BootArgs.CryptoInfoLength); | ||
541 | BootArgs.CryptoInfoLength = 0; | ||
542 | } | ||
543 | 538 | ||
544 | BootDriveFilterExtension = Extension; | 539 | BootDriveFilterExtension = Extension; |
545 | BootDriveFound = Extension->BootDrive = Extension->DriveMounted = Extension->VolumeHeaderPresent = TRUE; | 540 | BootDriveFound = Extension->BootDrive = Extension->DriveMounted = Extension->VolumeHeaderPresent = TRUE; |
@@ -565,8 +560,8 @@ static NTSTATUS MountDrive (DriveFilterExtension *Extension, Password *password, | |||
565 | uint32 i; | 560 | uint32 i; |
566 | for(i = 0; i<pwdCache->Count; ++i){ | 561 | for(i = 0; i<pwdCache->Count; ++i){ |
567 | if (CacheBootPassword && pwdCache->Pwd[i].Length > 0) { | 562 | if (CacheBootPassword && pwdCache->Pwd[i].Length > 0) { |
568 | int pim = CacheBootPim? (int) (pwdCache->Pim[i]) : 0; | 563 | int cachedPim = CacheBootPim? (int) (pwdCache->Pim[i]) : 0; |
569 | AddPasswordToCache (&pwdCache->Pwd[i], pim); | 564 | AddPasswordToCache (&pwdCache->Pwd[i], cachedPim); |
570 | } | 565 | } |
571 | } | 566 | } |
572 | burn(pwdCache, sizeof(*pwdCache)); | 567 | burn(pwdCache, sizeof(*pwdCache)); |
@@ -577,8 +572,8 @@ static NTSTATUS MountDrive (DriveFilterExtension *Extension, Password *password, | |||
577 | 572 | ||
578 | if (CacheBootPassword && BootArgs.BootPassword.Length > 0) | 573 | if (CacheBootPassword && BootArgs.BootPassword.Length > 0) |
579 | { | 574 | { |
580 | int pim = CacheBootPim? (int) (BootArgs.Flags >> 16) : 0; | 575 | int cachedPim = CacheBootPim? pim : 0; |
581 | AddPasswordToCache (&BootArgs.BootPassword, pim); | 576 | AddPasswordToCache (&BootArgs.BootPassword, cachedPim); |
582 | } | 577 | } |
583 | 578 | ||
584 | burn (&BootArgs.BootPassword, sizeof (BootArgs.BootPassword)); | 579 | burn (&BootArgs.BootPassword, sizeof (BootArgs.BootPassword)); |