aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Moffett <john.moff@gmail.com>2023-02-10 16:13:40 -0500
committerfanquake <fanquake@gmail.com>2023-02-20 17:15:38 +0000
commit64e7db6f4f256656f4d78a96b07e51f7d5c6d526 (patch)
tree752e173ec74afba218d33cce97be63ba984affd9
parentb7e242ecb3aa0074aea753e5bc9f8d22674e8294 (diff)
downloadbitcoin-64e7db6f4f256656f4d78a96b07e51f7d5c6d526.tar.xz
Zero out wallet master key upon lock
When an encrypted wallet is locked (for instance via the RPC `walletlock`), the docs indicate that the key is removed from memory. However, the vector (with a secure allocator) is merely cleared. This allows the key to persist indefinitely in memory. Instead, manually fill the bytes with zeroes before clearing. Github-Pull: #27080 Rebased-From: 3a11adc7004d21b3dfe028b190d83add31691c55
-rw-r--r--src/wallet/wallet.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 9149152bb0..5d77b4ed8f 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -25,6 +25,7 @@
#include <script/descriptor.h>
#include <script/script.h>
#include <script/signingprovider.h>
+#include <support/cleanse.h>
#include <txmempool.h>
#include <util/bip32.h>
#include <util/check.h>
@@ -3293,7 +3294,10 @@ bool CWallet::Lock()
{
LOCK(cs_wallet);
- vMasterKey.clear();
+ if (!vMasterKey.empty()) {
+ memory_cleanse(vMasterKey.data(), vMasterKey.size() * sizeof(decltype(vMasterKey)::value_type));
+ vMasterKey.clear();
+ }
}
NotifyStatusChanged(this);