lockedpool: avoid sensitive data in core files (FreeBSD)

This is a followup to
23991ee53 / https://github.com/bitcoin/bitcoin/pull/15600
to also use madvise(2) on FreeBSD to avoid sensitive data allocated
with secure_allocator ending up in core files in addition to preventing
it from going to the swap.
This commit is contained in:
Vasil Dimov 2020-03-26 20:43:17 +01:00 committed by Patrick Lodder
parent b4b98d7ad0
commit 09f86e7494
No known key found for this signature in database
GPG Key ID: 7C523F5FBABE80E7
1 changed files with 3 additions and 1 deletions

View File

@ -230,8 +230,10 @@ void *PosixLockedPageAllocator::AllocateLocked(size_t len, bool *lockingSuccess)
addr = mmap(nullptr, len, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
if (addr) {
*lockingSuccess = mlock(addr, len) == 0;
#ifdef MADV_DONTDUMP
#if defined(MADV_DONTDUMP) // Linux
madvise(addr, len, MADV_DONTDUMP);
#elif defined(MADV_NOCORE) // FreeBSD
madvise(addr, len, MADV_NOCORE);
#endif
}
return addr;