Skip to content

Commit ca467fa

Browse files
author
Damian Rickard
committed
Wipe memory reliably in Memory::Zero
Memory::Zero() used a plain memset(), which the compiler is free to remove as a dead store when the buffer is not read afterwards. It backs BufferPtr::Erase() and BufferPtr::Zero(), which are used to clear key material and other secrets, so an elided memset can leave secrets in memory. Use burn() instead, the same volatile-write wipe already used by Buffer::Erase(). Memory::Zero is not called on the bulk encryption/I/O path, so this has no throughput impact.
1 parent d773ce9 commit ca467fa

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎src/Platform/Memory.cpp‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@ namespace VeraCrypt
6363

6464
void Memory::Zero (void *memory, size_t size)
6565
{
66-
memset (memory, 0, size);
66+
// Use burn() rather than memset() so the write is not elided by the
67+
// optimiser. Memory::Zero backs BufferPtr::Erase()/Zero(), which are
68+
// used to wipe key material and other secrets; a plain memset() on a
69+
// buffer that is not read afterwards can be removed as a dead store,
70+
// leaving secrets in memory. burn() is the same volatile-write wipe
71+
// already used by Buffer::Erase(). This is not on the bulk I/O path.
72+
burn (memory, size);
6773
}
6874

6975
void Memory::Free (void *memory)

0 commit comments

Comments
 (0)