1
0
mirror of https://github.com/veracrypt/VeraCrypt.git synced 2025-11-11 19:08:26 -06:00

Windows: fix issue with fastCreate by requesting SE_MANAGE_VOLUME_NAME privilege before calling CreateFile

This ensures that the returned handle inherits the privilege
This commit is contained in:
Mounir IDRASSI
2023-07-16 11:08:24 +02:00
parent c759c2230b
commit 6267b91931

View File

@@ -344,6 +344,26 @@ begin_format:
else else
{ {
/* File-hosted volume */ /* File-hosted volume */
BOOL speedupFileCreation = FALSE;
// speedup for file creation only makes sens when using quick format for non hidden volumes
if (!volParams->hiddenVol && !bInstantRetryOtherFilesys && volParams->quickFormat && volParams->fastCreateFile)
{
// we set required privileges to speedup file creation before we create the file so that the file handle inherits the privileges
if (!SetPrivilege(SE_MANAGE_VOLUME_NAME, TRUE))
{
DWORD dwLastError = GetLastError();
if (Silent || (MessageBoxW(hwndDlg, GetString ("ADMIN_PRIVILEGES_WARN_MANAGE_VOLUME"), lpszTitle, MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2) == IDNO))
{
SetLastError(dwLastError);
nStatus = ERR_OS_ERROR;
goto error;
}
}
else
{
speedupFileCreation = TRUE;
}
}
dev = CreateFile (volParams->volumePath, GENERIC_READ | GENERIC_WRITE, dev = CreateFile (volParams->volumePath, GENERIC_READ | GENERIC_WRITE,
(volParams->hiddenVol || bInstantRetryOtherFilesys) ? (FILE_SHARE_READ | FILE_SHARE_WRITE) : 0, (volParams->hiddenVol || bInstantRetryOtherFilesys) ? (FILE_SHARE_READ | FILE_SHARE_WRITE) : 0,
@@ -373,13 +393,8 @@ begin_format:
if (!volParams->hiddenVol && !bInstantRetryOtherFilesys) if (!volParams->hiddenVol && !bInstantRetryOtherFilesys)
{ {
LARGE_INTEGER volumeSize; LARGE_INTEGER volumeSize;
BOOL speedupFileCreation = FALSE;
volumeSize.QuadPart = dataAreaSize + TC_VOLUME_HEADER_GROUP_SIZE; volumeSize.QuadPart = dataAreaSize + TC_VOLUME_HEADER_GROUP_SIZE;
// speedup for file creation only makes sens when using quick format
if (volParams->quickFormat && volParams->fastCreateFile)
speedupFileCreation = TRUE;
if (volParams->sparseFileSwitch && volParams->quickFormat) if (volParams->sparseFileSwitch && volParams->quickFormat)
{ {
// Create as sparse file container // Create as sparse file container
@@ -400,18 +415,6 @@ begin_format:
} }
if (speedupFileCreation) if (speedupFileCreation)
{
if (!SetPrivilege(SE_MANAGE_VOLUME_NAME, TRUE))
{
DWORD dwLastError = GetLastError();
if (Silent || (MessageBoxW(hwndDlg, GetString ("ADMIN_PRIVILEGES_WARN_MANAGE_VOLUME"), lpszTitle, MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2) == IDNO))
{
SetLastError(dwLastError);
nStatus = ERR_OS_ERROR;
goto error;
}
}
else
{ {
// accelerate file creation by telling Windows not to fill all file content with zeros // accelerate file creation by telling Windows not to fill all file content with zeros
// this has security issues since it will put existing disk content into file container // this has security issues since it will put existing disk content into file container
@@ -424,7 +427,6 @@ begin_format:
goto error; goto error;
} }
} }
}
if (SetFilePointer (dev, 0, NULL, FILE_BEGIN) != 0) if (SetFilePointer (dev, 0, NULL, FILE_BEGIN) != 0)
{ {