Commit Graph

14255 Commits

Author SHA1 Message Date
Luke Dashjr 6b278b20cb lockedpool: When possible, use madvise to avoid including sensitive information in core dumps 2020-07-31 07:22:23 +01:00
Jeffrey Czyz 4277ef2063 Fix segfault in allocator_tests/arena_tests
The test uses reinterpret_cast<void*> on unallocated memory. Using this
memory in printchunk as char* causes a segfault, so have printchunk take
void* instead.

Zcash: Includes change from bitcoin/bitcoin#13163
2020-07-31 07:21:19 +01:00
Jeffrey Czyz 28825123eb Fix compilation errors in support/lockedpool.cpp
Changes in #12048 cause a compilation error in Arena::walk() when
ARENA_DEBUG is defined. Specifically, Arena's chunks_free map was
changed to have a different value type.

Additionally, missing includes cause other compilation errors when
ARENA_DEBUG is defined.

Reproduced with:

make CPPFLAGS=-DARENA_DEBUG
2020-07-31 07:17:03 +01:00
practicalswift 3d635dd09f Fix out-of-bounds write in case of failing mmap(...) in PosixLockedPageAllocator::AllocateLocked 2020-07-31 07:16:36 +01:00
Martin Ankerl e64df07811 fix nits: variable naming, typos 2020-07-31 07:15:46 +01:00
Martin Ankerl 1245ce0d8c Use best-fit strategy in Arena, now O(log(n)) instead O(n)
This replaces the first-fit algorithm used in the Arena with a best-fit. According to "Dynamic Storage Allocation: A Survey and Critical Review", Wilson et. al. 1995, http://www.scs.stanford.edu/14wi-cs140/sched/readings/wilson.pdf, both startegies work well in practice.

The advantage of using best-fit is that we can switch the slow O(n) algorithm to O(log(n)) operations. Additionally, some previously O(log(n)) operations are now replaced with O(1) operations by using a hash map. The end effect is that the benchmark runs about 2.5 times faster on my machine:

old: BenchLockedPool, 5, 530, 5.25749, 0.00196938, 0.00199755, 0.00198172
new: BenchLockedPool, 5, 1300, 5.11313, 0.000781493, 0.000793314, 0.00078606

I've run all unit tests and benchmarks.

Zcash: Excludes change to benchmark.
2020-07-31 07:14:34 +01:00
Pieter Wuille 614d1bb207 Remove some unused functions and methods
In the case of CKey's destructor, it seems to have been an oversight in
f4d1fc259 not to delete it. At this point, it results in the move
constructors/assignment operators for CKey being deleted, which may have
a performance impact.
2020-07-31 06:51:33 +01:00
Kaz Wesley 2555074c22 LockedPool: avoid quadratic-time allocation
Use separate maps for used/free chunks to avoid linear scan through alloced
chunks for each alloc.
2020-07-31 06:51:33 +01:00
Kaz Wesley 817e36b217 LockedPool: fix explosion for illegal-sized alloc
Check for unreasonable alloc size in LockedPool rather than lancing through new
Arenas until we improbably find one worthy of the quixotic request or the system
can support no more Arenas.
2020-07-31 06:51:00 +01:00
Kaz Wesley 509652e936 LockedPool: test handling of invalid allocations
(Currently fails due to bug)
2020-07-31 06:51:00 +01:00
Pavel Janík d0df44f151 Do not shadow variable, use deprecated MAP_ANON if MAP_ANONYMOUS is not defined. 2020-07-31 06:51:00 +01:00
Wladimir J. van der Laan 088219f786 bench: Add benchmark for lockedpool allocation/deallocation 2020-07-31 06:43:09 +01:00
Wladimir J. van der Laan 82a667591e rpc: Add `getmemoryinfo` call
```
getmemoryinfo
Returns an object containing information about memory usage.

Result:
{
  "locked": {               (json object) Information about locked memory manager
    "used": xxxxx,          (numeric) Number of bytes used
    "free": xxxxx,          (numeric) Number of bytes available in current arenas
    "total": xxxxxxx,       (numeric) Total number of bytes managed
    "locked": xxxxxx,       (numeric) Amount of bytes that succeeded locking. If this number is smaller than total, locking pages failed at some point and key data could be swapped to disk.
  }
}

Examples:
> bitcoin-cli getmemoryinfo
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getmemoryinfo", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/
```
2020-07-31 06:43:09 +01:00
Wladimir J. van der Laan d570eabc38 support: Add LockedPool
Add a pool for locked memory chunks, replacing LockedPageManager.

This is something I've been wanting to do for a long time. The current
approach of locking objects where they happen to be on the stack or heap
in-place causes a lot of mlock/munlock system call overhead, slowing
down any handling of keys.

Also locked memory is a limited resource on many operating systems (and
using a lot of it bogs down the system), so the previous approach of
locking every page that may contain any key information (but also other
information) is wasteful.
2020-07-31 06:43:09 +01:00
Wladimir J. van der Laan 8d0f80f831 wallet: Get rid of LockObject and UnlockObject calls in key.h
Replace these with vectors allocated from the secure allocator.

This avoids mlock syscall churn on stack pages, as well as makes
it possible to get rid of these functions.

Please review this commit and the previous one carefully that
no `sizeof(vectortype)` remains in the memcpys and memcmps usage
(ick!), and `.data()` or `&vec[x]` is used as appropriate instead of
&vec.
2020-07-31 06:43:08 +01:00
Wladimir J. van der Laan b997b30a91 wallet: Change CCrypter to use vectors with secure allocator
Change CCrypter to use vectors with secure allocator instead of buffers
on in the object itself which will end up on the stack. This avoids
having to call LockedPageManager to lock stack memory pages to prevent the
memory from being swapped to disk. This is wasteful.
2020-07-31 06:43:08 +01:00
Thomas Snider 20280556ba [trivial] Switched constants to sizeof() 2020-07-31 06:43:08 +01:00
Homu 2589b2fcc5 Auto merge of #4614 - str4d:ctaes, r=str4d
Replace OpenSSL AES with ctaes-based version

Backported from upstream PR https://github.com/bitcoin/bitcoin/pull/7689.

This is backported primarily to remove merge conflicts for a subsequent
backport, and also helps us towards removing OpenSSL. Its actual usage
in wallet encryption would be replaced by a more modern construction
before we make wallet encryption a supported feature, but for now this
does not affect anyone using the experimental feature.
2020-07-31 00:14:40 +00:00
Jack Grigg fb2edcc352 Debian: Add copyright entries for ctaes and secp256k1 2020-07-30 05:57:00 +01:00
Cory Fields 7e4a74ddf6 depends: bump native_cctools for fixed lto with external clang
https://github.com/tpoechtrager/cctools-port/pull/85 was merged upstream, which
fixes lto detection for external clang with some Linux Distro's including
Ubuntu.
2020-07-30 04:36:02 +01:00
Cory Fields 7a714958d4 depends: enable lto support for Apple's ld64
Note that this does not _enable_ lto by default in any way, only hooks up the
machinery for -flto to work correctly.

enable-lto-support is explicitly used for pinned-clang because we know it
works. It is neither enabled nor disabled in the external clang case so that
it can be auto-detected.
2020-07-30 04:35:25 +01:00
Carl Dong 25cc992ea3 depends: Add justifications for macOS clang flags 2020-07-30 04:33:36 +01:00
Cory Fields b22d18063b depends: specify libc++ header location for darwin
For depends builds this was fixed by fbcfcf69, which deleted the conflicting
headers. When we no longer control the clang installation, we need to ensure
that the SDK's libc++ headers are used rather than the ones shipped with clang.
We can do that by turning off the default include path and hard-coding our own.
This hard-coded path is ok because we control (via SDK packaging) where these
headers end-up.

Side-note: Now that this path is hard-coded in depends, we can potentially
package the SDK differently, as the c++ folder can live wherever is most
convenient for us.
2020-07-30 04:33:36 +01:00
Carl Dong 6ae57751cc depends: Specify path to native binaries as clang argument
Zcash: Extracted from upstream commit:
    depends: Allow building with system clang
2020-07-30 04:33:36 +01:00
Carl Dong d6c3af5e84 depends: Decouple toolchain + binutils
For now they remain the same, but in the next commit, we will assign
them differently according to wether or not we're using system clang.
2020-07-30 04:33:36 +01:00
fanquake a21fa08e0b doc: explain why passing -mlinker-version is required 2020-07-30 04:33:36 +01:00
Cory Fields 6b785ae72d darwin: pass mlinker-version so that clang enables new features
Without this clang fails to add any newly-added linker features.

Removing this in ca5055a5aa07aba81a87cf12f6f0526a63c423b5 was likely a
regression.

See https://github.com/bitcoin/bitcoin/pull/19240#issuecomment-647764049
for more discussion.
2020-07-30 04:33:36 +01:00
Cory Fields cc934c2b1d macos: Bump to xcode 11.3.1 and 10.15 SDK
This gets us a newer SDK with c++17 support and retains 10.12
back-compat.

Co-authored-by: Carl Dong <contact@carldong.me>
2020-07-30 04:33:36 +01:00
Cory Fields a53d5ea8e9 depends: bump MacOS toolchain
clang   6.0.1  -> 8.0.0
cctools 921    -> 949.0.1
ld64    409.12 -> 530
2020-07-30 04:33:36 +01:00
Carl Dong addae3b250 contrib: macdeploy: Remove historical extraction notes 2020-07-30 04:33:36 +01:00
Carl Dong 6296a1e9ac contrib: macdeploy: Use apple-sdk-tools instead of xar+pbzx 2020-07-30 04:33:36 +01:00
Carl Dong 8e1a78ab63 native_cctools: Don't use libc++ from pinned clang
Now that we include the macOS SDK libc++ headers in our macOS SDK
tarball, we no longer need this hack to use the libc++ from our pinned
clang.
2020-07-30 04:33:36 +01:00
Carl Dong d02d06b565 Adapt rest of tooling to new SDK naming scheme 2020-07-30 04:33:36 +01:00
Carl Dong 29fbb65b14 contrib: macdeploy: Correctly generate macOS SDK
Previously, we did not include the macOS SDK libc++ headers in our SDK
creation process and instead used whichever libc++ headers shipped with
the clang package we downloaded in depends.

This change adds a script (which works on both GNU/Linux and macOS) to
correctly generate the macOS SDK including the libc++ headers. This can
be thought of as a simplified rewrite of tpoechtrager's script:

d3392f4eae/tools/gen_sdk_package.sh

The location within the SDK where we place the libc++ headers is chosen
such that clang's search path detection logic for sysroots would pick up
the headers properly.

We also document this change.
2020-07-30 04:33:36 +01:00
Andrew Chow 79c707aaf2 Fix naming of macOS SDK and clarify version 2020-07-30 04:33:36 +01:00
fanquake d75478432f build: use macOS 10.14 SDK
Co-Authored-By: Carl Dong <accounts@carldong.me>
2020-07-30 04:33:36 +01:00
fanquake a346fc0086 depends: native_cctools 921, ld64 409.12, libtapi 1000.10.8
This also removes the obsolete mlinker-version option

Co-Authored-By: Cory Fields <cory-nospam-@coryfields.com>

Zcash: Excludes QT changes.
2020-07-30 04:33:36 +01:00
fanquake 49c023c871 depends: clang 6.0.1
This also removes some now-unnecessary cctools hacks.

Co-Authored-By: Cory Fields <cory-nospam-@coryfields.com>
2020-07-30 04:33:36 +01:00
fanquake e04c184205 build: set minimum supported macOS to 10.12 2020-07-30 04:33:36 +01:00
fanquake d84878d853 scripted-diff: prefer MAC_OSX over __APPLE__
-BEGIN VERIFY SCRIPT-
sed -i 's/__APPLE__/MAC_OSX/g' src/compat/byteswap.h src/util.cpp
-END VERIFY SCRIPT-

Zcash: Excludes byteswap.h change as we don't have bitcoin/bitcoin#9366.
2020-07-30 04:33:36 +01:00
fanquake a0f3ef7e13 doc: mention that macOS 10.10 is now required 2020-07-30 04:33:36 +01:00
fanquake 0d3e5fc43c depends: set OSX_MIN_VERSION to 10.10 2020-07-30 04:33:36 +01:00
Daira Hopwood 63bfdad106 Fix a return status issue.
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2020-07-29 14:28:54 +01:00
Homu f39e4dbaf1 Auto merge of #4627 - LarryRuane:issue4596-flush-wallet-db, r=str4d
flush witness cache (SetBestChain()) on clean shutdown

Closes #4596, follow-on to #4573. In addition to flushing witness data on shutdown, fix the RPC test that was preventing this change from being part of #4573.
2020-07-29 13:12:04 +00:00
Daira Hopwood 454fd23a90 Update .gitignore.
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2020-07-29 13:31:19 +01:00
Daira Hopwood 499d9c222c zcutil/distclean.sh: remove BDB utility programs.
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2020-07-29 13:31:19 +01:00
Alfredo Garcia 6abcf40a3e
add more allowed duplicates
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2020-07-29 08:45:02 -03:00
Homu 615efd2a52 Auto merge of #4584 - defuse:update-ignore, r=str4d
Block release when we haven't checked dependency updates for security fixes
2020-07-29 10:45:44 +00:00
Homu 24f3bcf275 Auto merge of #4623 - str4d:metrics-locking, r=str4d
metrics: Collect general stats before clearing screen

This prevents the metrics screen from flashing if locks are being held
by long-running processes, specifically cs_main during block validation.

We split up locking on cs_main and cs_vNodes to make obtaining the locks
easier, at the expense of potentially having slightly out-of-sync
statistics (which doesn't really matter, as all we are fetching from the
latter lock is the number of connected peers).
2020-07-29 09:33:07 +00:00
Homu 91cb52adc5 Auto merge of #4606 - str4d:safe-mode-alert-for-pre-heartwood-nodes, r=str4d
Send alert to put pre-Heartwood nodes into safe mode.

The alert targets nodes running protocol version <= 170010.
Heartwood-compatible nodes run protocol version >= 170011.
2020-07-29 07:59:59 +00:00