shim/ is an LD_PRELOAD guard around close/fclose/dup2/dup3: - before each close it resolves /proc/self/fd/N; - it reports, with a backtrace, a non-owner close of wallet.dat, database/log.* or blocks/*.dat, and every close that fails with EBADF (the second half of a double close); - FDGUARD_ABORT=1 aborts on the first hit; - run_tests.sh self-tests it (51 checks). repro/ runs a shimmed dragonxd on isolated regtest. Each run gets its own unprivileged network namespace (loopback only). The loads are: - rpc: a hammer with impatient/RST/half-open clients, work-queue bursts and long-polls; - p2p: TLS peers churned by disconnectnode, ban and kill, plus a raw TCP/TLS misbehaver; - tor: a fake control port; - mine: mining with blocknotify and autoshield. tools/tally.py groups the reports by closer. tools/scan_bdb.py finds BDB pages written into block files. With the wolfSSL CloseSocket macro in effect: - p2pmin (300 s) gives one EBADF double close per disconnect; - the full load (1200 s) gives 930 EBADF closes, 186 non-owner closes (37 of wallet/log/blk files) and a 632 KB db.log with BDB0060 PANIC; - RPC-only and Tor-only loads give none. After the fix, every count is 0 and db.log stays empty. The README has the commands and the numbers. Paths come from the environment (GOLDEN, BIN, RUNS, SHIM, ASMAP and the Sapling params). Run output goes to $RUNS, outside the tree. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
16 lines
772 B
Bash
Executable File
16 lines
772 B
Bash
Executable File
#!/bin/sh
|
|
# Build the fdguard LD_PRELOAD shim and its self-test program.
|
|
# ./build.sh -> libfdguard.so, fdguard_test
|
|
set -e
|
|
cd "$(dirname "$0")"
|
|
CC=${CC:-gcc}
|
|
$CC -O2 -g -fPIC -shared -Wall -Wextra -Wno-unused-parameter -fvisibility=default \
|
|
-o libfdguard.so.tmp fdguard.c -ldl -lpthread
|
|
# rename, never overwrite in place: a running process may have the old one mapped
|
|
mv -f libfdguard.so.tmp libfdguard.so
|
|
# the test program keeps its symbols (no -rdynamic on purpose: like dragonxd,
|
|
# owner detection must work from .symtab alone) and frame pointers for clarity
|
|
$CC -O1 -g -fno-omit-frame-pointer -fno-inline -Wall -o fdguard_test.tmp fdguard_test.c -lpthread
|
|
mv -f fdguard_test.tmp fdguard_test
|
|
echo "built: $(pwd)/libfdguard.so $(pwd)/fdguard_test"
|