Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Platform/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace VeraCrypt
void Buffer::Erase ()
{
if (DataSize > 0)
burn (DataPtr, DataSize);
Memory::SecureErase (DataPtr, DataSize);
}

void Buffer::Free ()
Expand Down
2 changes: 1 addition & 1 deletion src/Platform/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace VeraCrypt

operator uint8 * () const { return DataPtr; }
void CopyFrom (const ConstBufferPtr &bufferPtr) const;
void Erase () const { Zero(); }
void Erase () const { Memory::SecureErase (DataPtr, DataSize); }
uint8 *Get () const { return DataPtr; }
BufferPtr GetRange (size_t offset, size_t size) const;
void Set (uint8 *data, size_t size) { DataPtr = data; DataSize = size; }
Expand Down
8 changes: 8 additions & 0 deletions src/Platform/Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ namespace VeraCrypt
memcpy (memoryDestination, memorySource, size);
}

// Secure erasure of sensitive data: the volatile writes of burn() cannot
// be elided by the optimiser even when the buffer is not read afterwards.
// Use Zero() instead for ordinary zero-initialization.
void Memory::SecureErase (void *memory, size_t size)
{
burn (memory, size);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think Memory::Zero should call burn globally. This function is a generic zero fill primitive and is used outside secret erasure contexts, including repeated large buffer paths such as non quick volume creation via outputBuffer.Zero in VolumeCreator.cpp. Please introduce a dedicated secure erasure API instead, use it from BufferPtr::Erase, and leave generic Zero as normal zero initialization.

}

void Memory::Zero (void *memory, size_t size)
{
memset (memory, 0, size);
Expand Down
1 change: 1 addition & 0 deletions src/Platform/Memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ namespace VeraCrypt
static void Copy (void *memoryDestination, const void *memorySource, size_t size);
static void Free (void *memory);
static void FreeAligned (void *memory);
static void SecureErase (void *memory, size_t size);
static void Zero (void *memory, size_t size);
};

Expand Down
Loading