VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Common/Apidrvr.h1
-rw-r--r--src/Common/Language.xml1
-rw-r--r--src/Driver/DriveFilter.c43
-rw-r--r--src/Driver/Ntdriver.c4
-rw-r--r--src/Driver/Ntdriver.h2
-rw-r--r--src/Mount/Mount.c4
-rw-r--r--src/Mount/Mount.rc56
-rw-r--r--src/Mount/Resource.h3
8 files changed, 86 insertions, 28 deletions
diff --git a/src/Common/Apidrvr.h b/src/Common/Apidrvr.h
index fda2d94..1230fc4 100644
--- a/src/Common/Apidrvr.h
+++ b/src/Common/Apidrvr.h
@@ -411,5 +411,6 @@ typedef struct
#define TC_DRIVER_CONFIG_DISABLE_EVIL_MAID_ATTACK_DETECTION 0x20
#define TC_DRIVER_CONFIG_CACHE_BOOT_PIM 0x40
#define VC_DRIVER_CONFIG_ALLOW_NONSYS_TRIM 0x80
+#define VC_DRIVER_CONFIG_BLOCK_SYS_TRIM 0x100
#endif /* _WIN32 */
diff --git a/src/Common/Language.xml b/src/Common/Language.xml
index 38457c4..cf7cfa8 100644
--- a/src/Common/Language.xml
+++ b/src/Common/Language.xml
@@ -1424,6 +1424,7 @@
<control lang="en" key="IDT_ADVANCED_OPTIONS">Advanced Options</control>
<string lang="en" key="AFTER_UPGRADE_RESCUE_DISK">It is strongly recommended that you create a new VeraCrypt Rescue Disk (which will contain the new version of the VeraCrypt Boot Loader) by selecting 'System' > 'Create Rescue Disk'.\nDo you want to do it now?</string>
<control lang="en" key="IDC_ALLOW_TRIM_NONSYS_SSD">Allow TRIM operation for non-system SSD partition/drive</control>
+ <control lang="en" key="IDC_BLOCK_SYSENC_TRIM">Block TRIM command on system partition/drive</control>
</localization>
<!-- XML Schema -->
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
diff --git a/src/Driver/DriveFilter.c b/src/Driver/DriveFilter.c
index 08bebe1..bb7083c 100644
--- a/src/Driver/DriveFilter.c
+++ b/src/Driver/DriveFilter.c
@@ -941,6 +941,46 @@ static NTSTATUS DispatchPower (PDEVICE_OBJECT DeviceObject, PIRP Irp, DriveFilte
return status;
}
+static NTSTATUS DispatchControl (PDEVICE_OBJECT DeviceObject, PIRP Irp, DriveFilterExtension *Extension, PIO_STACK_LOCATION irpSp)
+{
+ BOOL bBlockTrim = BlockSystemTrimCommand || IsHiddenSystemRunning();
+ NTSTATUS status = IoAcquireRemoveLock (&Extension->Queue.RemoveLock, Irp);
+ if (!NT_SUCCESS (status))
+ return TCCompleteIrp (Irp, status, 0);
+
+ switch (irpSp->Parameters.DeviceIoControl.IoControlCode)
+ {
+ case IOCTL_STORAGE_MANAGE_DATA_SET_ATTRIBUTES:
+ Dump ("DriverFilter-DispatchControl: IOCTL_STORAGE_MANAGE_DATA_SET_ATTRIBUTES\n");
+ if (bBlockTrim)
+ {
+ PIO_STACK_LOCATION irpSp = IoGetCurrentIrpStackLocation (Irp);
+ DWORD inputLength = irpSp->Parameters.DeviceIoControl.InputBufferLength;
+ if (inputLength >= sizeof (DEVICE_MANAGE_DATA_SET_ATTRIBUTES))
+ {
+ PDEVICE_MANAGE_DATA_SET_ATTRIBUTES pInputAttrs = (PDEVICE_MANAGE_DATA_SET_ATTRIBUTES) Irp->AssociatedIrp.SystemBuffer;
+ DEVICE_DATA_MANAGEMENT_SET_ACTION action = pInputAttrs->Action;
+ if (action == DeviceDsmAction_Trim)
+ {
+ Dump ("DriverFilter-DispatchControl: IOCTL_STORAGE_MANAGE_DATA_SET_ATTRIBUTES - DeviceDsmAction_Trim.\n");
+
+ if (bBlockTrim)
+ {
+ Dump ("DriverFilter-DispatchControl:: TRIM command blocked.\n");
+ IoReleaseRemoveLock (&Extension->Queue.RemoveLock, Irp);
+ return TCCompleteDiskIrp (Irp, STATUS_SUCCESS, 0);
+ }
+ }
+ }
+ }
+ break;
+ }
+
+ status = PassIrp (Extension->LowerDeviceObject, Irp);
+ IoReleaseRemoveLock (&Extension->Queue.RemoveLock, Irp);
+ return status;
+}
+
NTSTATUS DriveFilterDispatchIrp (PDEVICE_OBJECT DeviceObject, PIRP Irp)
{
@@ -970,6 +1010,9 @@ NTSTATUS DriveFilterDispatchIrp (PDEVICE_OBJECT DeviceObject, PIRP Irp)
case IRP_MJ_POWER:
return DispatchPower (DeviceObject, Irp, Extension, irpSp);
+
+ case IRP_MJ_DEVICE_CONTROL:
+ return DispatchControl (DeviceObject, Irp, Extension, irpSp);
}
status = IoAcquireRemoveLock (&Extension->Queue.RemoveLock, Irp);
diff --git a/src/Driver/Ntdriver.c b/src/Driver/Ntdriver.c
index ce2f01c..fca2ca4 100644
--- a/src/Driver/Ntdriver.c
+++ b/src/Driver/Ntdriver.c
@@ -128,6 +128,7 @@ BOOL VolumeClassFilterRegistered = FALSE;
BOOL CacheBootPassword = FALSE;
BOOL CacheBootPim = FALSE;
BOOL NonAdminSystemFavoritesAccessDisabled = FALSE;
+BOOL BlockSystemTrimCommand = FALSE;
static size_t EncryptionThreadPoolFreeCpuCountLimit = 0;
static BOOL SystemFavoriteVolumeDirty = FALSE;
static BOOL PagingFileCreationPrevented = FALSE;
@@ -4220,6 +4221,9 @@ NTSTATUS ReadRegistryConfigFlags (BOOL driverEntry)
if (flags & TC_DRIVER_CONFIG_CACHE_BOOT_PIM)
CacheBootPim = TRUE;
+
+ if (flags & VC_DRIVER_CONFIG_BLOCK_SYS_TRIM)
+ BlockSystemTrimCommand = TRUE;
}
EnableHwEncryption ((flags & TC_DRIVER_CONFIG_DISABLE_HARDWARE_ENCRYPTION) ? FALSE : TRUE);
diff --git a/src/Driver/Ntdriver.h b/src/Driver/Ntdriver.h
index 50a98d0..8403f21 100644
--- a/src/Driver/Ntdriver.h
+++ b/src/Driver/Ntdriver.h
@@ -122,7 +122,7 @@ extern ULONG OsMinorVersion;
extern BOOL VolumeClassFilterRegistered;
extern BOOL CacheBootPassword;
extern BOOL CacheBootPim;
-
+extern BOOL BlockSystemTrimCommand;
/* Helper macro returning x seconds in units of 100 nanoseconds */
#define WAIT_SECONDS(x) ((x)*10000000)
diff --git a/src/Mount/Mount.c b/src/Mount/Mount.c
index 61ce4f7..ac9ef10 100644
--- a/src/Mount/Mount.c
+++ b/src/Mount/Mount.c
@@ -11109,6 +11109,7 @@ static BOOL CALLBACK BootLoaderPreferencesDlgProc (HWND hwndDlg, UINT msg, WPARA
uint16 bootLoaderVersion = 0;
BOOL bPasswordCacheEnabled = (driverConfig & TC_DRIVER_CONFIG_CACHE_BOOT_PASSWORD)? TRUE : FALSE;
BOOL bPimCacheEnabled = (driverConfig & TC_DRIVER_CONFIG_CACHE_BOOT_PIM)? TRUE : FALSE;
+ BOOL bBlockSysEncTrimEnabled = (driverConfig & VC_DRIVER_CONFIG_BLOCK_SYS_TRIM)? TRUE : FALSE;
if (!BootEncObj->ReadBootSectorConfig (nullptr, 0, &userConfig, &customUserMessage, &bootLoaderVersion))
{
@@ -11150,6 +11151,7 @@ static BOOL CALLBACK BootLoaderPreferencesDlgProc (HWND hwndDlg, UINT msg, WPARA
CheckDlgButton (hwndDlg, IDC_BOOT_LOADER_CACHE_PASSWORD, bPasswordCacheEnabled ? BST_CHECKED : BST_UNCHECKED);
EnableWindow (GetDlgItem (hwndDlg, IDC_BOOT_LOADER_CACHE_PIM), bPasswordCacheEnabled);
CheckDlgButton (hwndDlg, IDC_BOOT_LOADER_CACHE_PIM, (bPasswordCacheEnabled && bPimCacheEnabled)? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton (hwndDlg, IDC_BLOCK_SYSENC_TRIM, bBlockSysEncTrimEnabled ? BST_CHECKED : BST_UNCHECKED);
}
catch (Exception &e)
{
@@ -11261,10 +11263,12 @@ static BOOL CALLBACK BootLoaderPreferencesDlgProc (HWND hwndDlg, UINT msg, WPARA
{
BOOL bPasswordCacheEnabled = IsDlgButtonChecked (hwndDlg, IDC_BOOT_LOADER_CACHE_PASSWORD);
BOOL bPimCacheEnabled = IsDlgButtonChecked (hwndDlg, IDC_BOOT_LOADER_CACHE_PIM);
+ BOOL bBlockSysEncTrimEnabled = IsDlgButtonChecked (hwndDlg, IDC_BLOCK_SYSENC_TRIM);
BootEncObj->WriteBootSectorUserConfig (userConfig, customUserMessage, prop.volumePim, prop.pkcs5);
SetDriverConfigurationFlag (TC_DRIVER_CONFIG_CACHE_BOOT_PASSWORD, bPasswordCacheEnabled);
SetDriverConfigurationFlag (TC_DRIVER_CONFIG_CACHE_BOOT_PIM, (bPasswordCacheEnabled && bPimCacheEnabled)? TRUE : FALSE);
SetDriverConfigurationFlag (TC_DRIVER_CONFIG_DISABLE_EVIL_MAID_ATTACK_DETECTION, IsDlgButtonChecked (hwndDlg, IDC_DISABLE_EVIL_MAID_ATTACK_DETECTION));
+ SetDriverConfigurationFlag (VC_DRIVER_CONFIG_BLOCK_SYS_TRIM, bBlockSysEncTrimEnabled);
}
catch (Exception &e)
{
diff --git a/src/Mount/Mount.rc b/src/Mount/Mount.rc
index 9024b0d..9eae9da 100644
--- a/src/Mount/Mount.rc
+++ b/src/Mount/Mount.rc
@@ -285,26 +285,28 @@ BEGIN
LTEXT "",IDT_PKCS11_LIB_HELP,16,63,286,65
END
-IDD_EFI_SYSENC_SETTINGS DIALOGEX 0, 0, 374, 165
+IDD_EFI_SYSENC_SETTINGS DIALOGEX 0, 0, 375, 182
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "VeraCrypt - System Encryption Settings"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
- CONTROL "&Cache pre-boot authentication password in driver memory (for mounting of non-system volumes)",IDC_BOOT_LOADER_CACHE_PASSWORD,
- "Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,68,339,10
- DEFPUSHBUTTON "OK",IDOK,255,141,50,14
- PUSHBUTTON "Cancel",IDCANCEL,313,141,50,14
GROUPBOX "Boot Loader Screen Options",IDT_BOOT_LOADER_SCREEN_OPTIONS,8,7,355,45
- GROUPBOX "Security Options",IDT_SECURITY_OPTIONS,7,53,355,44
- CONTROL "Include PIM when caching pre-boot authentication password",IDC_BOOT_LOADER_CACHE_PIM,
- "Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,16,83,340,10
CONTROL "Do not request PIM in the pre-boot authentication screen (PIM value is stored unencrypted on disk)",IDC_DISABLE_BOOT_LOADER_PIM_PROMPT,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,20,339,9
CONTROL "Do not request Hash algorithm in the pre-boot authentication screen",IDC_DISABLE_BOOT_LOADER_HASH_PROMPT,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,35,339,9
- PUSHBUTTON "Display EFI Platform Information",IDC_SHOW_PLATFORMINFO,187,112,173,14
- PUSHBUTTON "Edit Boot Loader Configuration",IDC_EDIT_DCSPROP,10,112,173,14
- GROUPBOX "Advanced Options",IDT_ADVANCED_OPTIONS,7,99,355,36
+ GROUPBOX "Security Options",IDT_SECURITY_OPTIONS,7,53,355,61
+ CONTROL "&Cache pre-boot authentication password in driver memory (for mounting of non-system volumes)",IDC_BOOT_LOADER_CACHE_PASSWORD,
+ "Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,68,339,10
+ CONTROL "Include PIM when caching pre-boot authentication password",IDC_BOOT_LOADER_CACHE_PIM,
+ "Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,16,83,340,10
+ CONTROL "Block TRIM command on system partition/drive",IDC_BLOCK_SYSENC_TRIM,
+ "Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,98,340,10
+ GROUPBOX "Advanced Options",IDT_ADVANCED_OPTIONS,7,116,355,36
+ PUSHBUTTON "Edit Boot Loader Configuration",IDC_EDIT_DCSPROP,10,129,173,14
+ PUSHBUTTON "Display EFI Platform Information",IDC_SHOW_PLATFORMINFO,187,129,173,14
+ PUSHBUTTON "Cancel",IDCANCEL,313,158,50,14
+ DEFPUSHBUTTON "OK",IDOK,255,158,50,14
END
IDD_PERFORMANCE_SETTINGS DIALOGEX 0, 0, 371, 253
@@ -389,7 +391,7 @@ BEGIN
CONTROL "TrueCrypt Mode",IDC_TRUECRYPT_MODE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,7,76,10
END
-IDD_SYSENC_SETTINGS DIALOGEX 0, 0, 370, 286
+IDD_SYSENC_SETTINGS DIALOGEX 0, 0, 371, 297
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "VeraCrypt - System Encryption Settings"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
@@ -397,22 +399,24 @@ BEGIN
CONTROL "Do not &show any texts in the pre-boot authentication screen (except the below custom message)",IDC_DISABLE_BOOT_LOADER_OUTPUT,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,20,339,9
EDITTEXT IDC_CUSTOM_BOOT_LOADER_MESSAGE,18,50,216,14,ES_AUTOHSCROLL
+ CONTROL "Do not request PIM in the pre-boot authentication screen (PIM value is stored unencrypted on disk)",IDC_DISABLE_BOOT_LOADER_PIM_PROMPT,
+ "Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,157,339,9
CONTROL "&Cache pre-boot authentication password in driver memory (for mounting of non-system volumes)",IDC_BOOT_LOADER_CACHE_PASSWORD,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,192,339,10
+ CONTROL "Include PIM when caching pre-boot authentication password",IDC_BOOT_LOADER_CACHE_PIM,
+ "Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,18,207,340,10
CONTROL "Allow pre-boot &authentication to be bypassed by pressing the Esc key (enables boot manager)",IDC_ALLOW_ESC_PBA_BYPASS,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,222,340,10
- DEFPUSHBUTTON "OK",IDOK,257,262,50,14
- PUSHBUTTON "Cancel",IDCANCEL,313,262,50,14
- LTEXT "Display this custom message in the pre-boot authentication screen (24 characters maximum):",IDT_CUSTOM_BOOT_LOADER_MESSAGE,18,39,337,8
- GROUPBOX "Boot Loader Screen Options",IDT_BOOT_LOADER_SCREEN_OPTIONS,8,7,355,165
- GROUPBOX "Security Options",IDT_SECURITY_OPTIONS,8,177,355,75
- LTEXT "",IDC_CUSTOM_BOOT_LOADER_MESSAGE_HELP,18,72,337,73
CONTROL "Disable ""Evil Maid"" attack detection",IDC_DISABLE_EVIL_MAID_ATTACK_DETECTION,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,237,340,10
- CONTROL "Include PIM when caching pre-boot authentication password",IDC_BOOT_LOADER_CACHE_PIM,
- "Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,18,207,340,10
- CONTROL "Do not request PIM in the pre-boot authentication screen (PIM value is stored unencrypted on disk)",IDC_DISABLE_BOOT_LOADER_PIM_PROMPT,
- "Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,157,339,9
+ CONTROL "Block TRIM command on system partition/drive",IDC_BLOCK_SYSENC_TRIM,
+ "Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,251,340,10
+ PUSHBUTTON "Cancel",IDCANCEL,314,273,50,14
+ DEFPUSHBUTTON "OK",IDOK,257,273,50,14
+ LTEXT "Display this custom message in the pre-boot authentication screen (24 characters maximum):",IDT_CUSTOM_BOOT_LOADER_MESSAGE,18,39,337,8
+ GROUPBOX "Boot Loader Screen Options",IDT_BOOT_LOADER_SCREEN_OPTIONS,9,7,355,165
+ GROUPBOX "Security Options",IDT_SECURITY_OPTIONS,9,177,355,92
+ LTEXT "",IDC_CUSTOM_BOOT_LOADER_MESSAGE_HELP,18,72,337,73
END
/////////////////////////////////////////////////////////////////////////////
@@ -486,9 +490,9 @@ BEGIN
IDD_EFI_SYSENC_SETTINGS, DIALOG
BEGIN
LEFTMARGIN, 7
- RIGHTMARGIN, 367
+ RIGHTMARGIN, 368
TOPMARGIN, 7
- BOTTOMMARGIN, 155
+ BOTTOMMARGIN, 172
END
IDD_PERFORMANCE_SETTINGS, DIALOG
@@ -518,9 +522,9 @@ BEGIN
IDD_SYSENC_SETTINGS, DIALOG
BEGIN
LEFTMARGIN, 7
- RIGHTMARGIN, 363
+ RIGHTMARGIN, 364
TOPMARGIN, 7
- BOTTOMMARGIN, 276
+ BOTTOMMARGIN, 287
END
END
#endif // APSTUDIO_INVOKED
diff --git a/src/Mount/Resource.h b/src/Mount/Resource.h
index 2cefbda..94d5710 100644
--- a/src/Mount/Resource.h
+++ b/src/Mount/Resource.h
@@ -188,6 +188,7 @@
#define IDC_EDIT_DCSPROP 1165
#define IDT_ADVANCED_OPTIONS 1166
#define IDC_ALLOW_TRIM_NONSYS_SSD 1167
+#define IDC_BLOCK_SYSENC_TRIM 1168
#define IDM_HELP 40001
#define IDM_ABOUT 40002
#define IDM_UNMOUNT_VOLUME 40003
@@ -264,7 +265,7 @@
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 120
#define _APS_NEXT_COMMAND_VALUE 40069
-#define _APS_NEXT_CONTROL_VALUE 1168
+#define _APS_NEXT_CONTROL_VALUE 1169
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif