Unix: synchronize encryption fragment exceptions

Serialize updates to the shared exception pointer and retain the first
reported error. Test concurrent failures through all three handlers,
exception cleanup and subsequent successful work.
This commit is contained in:
Mounir IDRASSI
2026-10-16 18:30:43 +09:00
parent 9603625a3d
commit 56834be339
4 changed files with 199 additions and 3 deletions
+16 -3
View File
@@ -344,21 +344,33 @@ namespace VeraCrypt
if (workItem->Type == WorkType::DeriveKey)
workItem->KeyDerivation.WorkItem->ItemException.reset (e.CloneNew());
else
workItem->FirstFragment->ItemException.reset (e.CloneNew());
{
ScopeLock exceptionLock (FragmentExceptionMutex);
if (!workItem->FirstFragment->ItemException.get())
workItem->FirstFragment->ItemException.reset (e.CloneNew());
}
}
catch (exception &e)
{
if (workItem->Type == WorkType::DeriveKey)
workItem->KeyDerivation.WorkItem->ItemException.reset (new ExternalException (SRC_POS, StringConverter::ToExceptionString (e)));
else
workItem->FirstFragment->ItemException.reset (new ExternalException (SRC_POS, StringConverter::ToExceptionString (e)));
{
ScopeLock exceptionLock (FragmentExceptionMutex);
if (!workItem->FirstFragment->ItemException.get())
workItem->FirstFragment->ItemException.reset (new ExternalException (SRC_POS, StringConverter::ToExceptionString (e)));
}
}
catch (...)
{
if (workItem->Type == WorkType::DeriveKey)
workItem->KeyDerivation.WorkItem->ItemException.reset (new UnknownException (SRC_POS));
else
workItem->FirstFragment->ItemException.reset (new UnknownException (SRC_POS));
{
ScopeLock exceptionLock (FragmentExceptionMutex);
if (!workItem->FirstFragment->ItemException.get())
workItem->FirstFragment->ItemException.reset (new UnknownException (SRC_POS));
}
}
if (workItem->Type == WorkType::DeriveKey)
@@ -409,6 +421,7 @@ namespace VeraCrypt
Mutex EncryptionThreadPool::EnqueueMutex;
Mutex EncryptionThreadPool::DequeueMutex;
Mutex EncryptionThreadPool::FragmentExceptionMutex;
Mutex EncryptionThreadPool::KeyDerivationCompletionMutex;
SyncEvent EncryptionThreadPool::WorkItemReadyEvent;
+2
View File
@@ -111,6 +111,8 @@ namespace VeraCrypt
static volatile size_t DequeuePosition;
static volatile size_t EnqueuePosition;
static Mutex EnqueueMutex;
// Fragments of one request share the first fragment's exception pointer.
static Mutex FragmentExceptionMutex;
// Orders KDF outstanding-count transitions against no-outstanding event updates.
static Mutex KeyDerivationCompletionMutex;
static list < shared_ptr <Thread> > RunningThreads;