Merge bitcoin/bitcoin#36337: fuzz: Cover block filter P2P messages
What changed, and why it matters
This commit adds fuzz-test coverage for BIP157 block-filter P2P messages and fixes a test-only cleanup issue. The fuzz target found an unsigned-integer overflow in net_processing.cpp when handling these messages, but the overflow appears to be in a debug/test code path and is not described as a remotely exploitable network vulnerability. The main code change is test infrastructure: initializing a basic block-filter index during fuzz setup and destroying it on teardown to avoid deadlocks.
Treat the UBSan finding as a code-quality/sanitizer issue to be triaged separately; verify whether net_processing.cpp:3662 can be reached in production or only under fuzz-specific state. The current commit is safe to merge as a test-coverage improvement with cleanup, but it does not remediate the reported overflow.
Security signals we found
Fuzzer-reported unsigned integer overflow in net_processing.cpp:3662 triggered by BIP157 P2P message handling
Test-only change: adds block-filter index initialization and destruction in fuzz/chain testing setup
No patch to production P2P parsing logic in this commit
Pull request description frames the change as increasing fuzz coverage, not fixing a security bug
Evidence from the diff
The PR extends the process_message/process_messages fuzz targets to exercise BIP157 P2P messages by initializing a basic block-filter index in ResetChainmanAndMempool and tearing it down in ~ChainTestingSetup(). The fuzz case reproduced a UBSan unsigned-integer overflow at src/net_processing.cpp:3662 (0 - 1 on size_type, then implicit conversion to int yielding -1). The commit does not patch net_processing.cpp; it only enables the fuzzer to reach that code and adds test cleanup. The overflow is reported as a sanitizer finding in a fuzz run, not as a confirmed production exploit.
Changed components
src/test/fuzz/process_message.cppsrc/test/fuzz/process_messages.cppsrc/test/util/setup_common.cppsrc/test/util/validation.cppsrc/test/util/validation.hsrc/net_processing.cpp (referenced by fuzzer finding, not modified)Inspect captured patch +29 / −6
### src/test/fuzz/process_message.cpp
@@ -60,7 +60,7 @@ void initialize_process_message()
{}),
};
g_setup = testing_setup.get();
- ResetChainmanAndMempool(*g_setup, init_clock);
+ ResetChainmanAndMempool(*g_setup, init_clock, {.init_block_filter_basic = true});
}
FUZZ_TARGET(process_message, .init = initialize_process_message)
@@ -137,6 +137,6 @@ FUZZ_TARGET(process_message, .init = initialize_process_message)
if (block_index_size != WITH_LOCK(chainman.GetMutex(), return chainman.BlockIndex().size()) || initial_sequence != end_sequence) {
// Reuse the global chainman and mempool, but reset them when dirty.
MakeRandDeterministicDANGEROUS(uint256::ZERO);
- ResetChainmanAndMempool(*g_setup, node_clock);
+ ResetChainmanAndMempool(*g_setup, node_clock, {.init_block_filter_basic = true});
}
}
### src/test/fuzz/process_messages.cpp
@@ -52,7 +52,7 @@ void initialize_process_messages()
g_setup = testing_setup.get();
// Replace validation_signals before creating chainman and mempool so they use it.
g_setup->m_node.validation_signals = std::make_unique<ValidationSignals>(std::make_unique<ImmediateBackgroundTaskRunner>());
- ResetChainmanAndMempool(*g_setup, init_clock);
+ ResetChainmanAndMempool(*g_setup, init_clock, {.init_block_filter_basic = true});
}
FUZZ_TARGET(process_messages, .init = initialize_process_messages)
@@ -139,6 +139,6 @@ FUZZ_TARGET(process_messages, .init = initialize_process_messages)
if (block_index_size != WITH_LOCK(chainman.GetMutex(), return chainman.BlockIndex().size()) || initial_sequence != end_sequence) {
// Reuse the global chainman and mempool, but reset them when dirty.
MakeRandDeterministicDANGEROUS(uint256::ZERO);
- ResetChainmanAndMempool(*g_setup, node_clock);
+ ResetChainmanAndMempool(*g_setup, node_clock, {.init_block_filter_basic = true});
}
}
### src/test/util/setup_common.cpp
@@ -15,6 +15,7 @@
#include <consensus/validation.h>
#include <crypto/hex_base.h>
#include <dbwrapper.h>
+#include <index/blockfilterindex.h>
#include <init.h>
#include <interfaces/chain.h>
#include <kernel/caches.h>
@@ -345,6 +346,7 @@ ChainTestingSetup::~ChainTestingSetup()
{
if (m_node.scheduler) m_node.scheduler->stop();
if (m_node.validation_signals) m_node.validation_signals->FlushBackgroundCallbacks();
+ DestroyAllBlockFilterIndexes();
m_node.block_template_manager.reset();
m_node.connman.reset();
m_node.banman.reset();
### src/test/util/validation.cpp
@@ -7,6 +7,8 @@
#include <coins.h>
#include <consensus/consensus.h>
#include <index/base.h>
+#include <index/blockfilterindex.h>
+#include <interfaces/chain.h>
#include <node/block_template_manager.h>
#include <node/blockstorage.h>
#include <node/context.h>
@@ -17,6 +19,7 @@
#include <test/util/time.h>
#include <test/util/txmempool.h>
#include <txmempool.h>
+#include <util/byte_units.h>
#include <util/check.h>
#include <util/time.h>
#include <validation.h>
@@ -108,10 +111,12 @@ void TestChainstateManager::ResetBestInvalid()
m_best_invalid = nullptr;
}
-std::vector<std::pair<COutPoint, CAmount>> ResetChainmanAndMempool(TestingSetup& setup, FakeNodeClock& node_clock)
+std::vector<std::pair<COutPoint, CAmount>> ResetChainmanAndMempool(TestingSetup& setup, FakeNodeClock& node_clock, const ResetOptions& opts)
{
node_clock.set(setup.m_node.chainman->GetParams().GenesisBlock().Time());
+ DestroyAllBlockFilterIndexes();
+
bilingual_str error{};
setup.m_node.block_template_manager.reset();
setup.m_node.mempool.reset();
@@ -135,6 +140,18 @@ std::vector<std::pair<COutPoint, CAmount>> ResetChainmanAndMempool(TestingSetup&
mature_coinbase.emplace_back(prevout, subsidy);
}
}
+
+ if (opts.init_block_filter_basic) {
+ Assert(InitBlockFilterIndex([&] { return interfaces::MakeChain(setup.m_node); }, BlockFilterType::BASIC, 1_MiB, /*f_memory=*/true, /*f_wipe=*/true));
+ auto& index = *Assert(GetBlockFilterIndex(BlockFilterType::BASIC));
+ Assert(index.Init());
+ index.Sync();
+ // The index serves the static setup chain only. Leaving it registered
+ // deadlocks with ImmediateBackgroundTaskRunner when a fuzzed block
+ // connects under cs_main.
+ StopIndex(index, setup.m_node);
+ }
+
return mature_coinbase;
}
### src/test/util/validation.h
@@ -63,7 +63,11 @@ class ValidationInterfaceTest
const CBlockIndex* pindex);
};
-std::vector<std::pair<COutPoint, CAmount>> ResetChainmanAndMempool(TestingSetup& setup, FakeNodeClock& node_clock);
+struct ResetOptions {
+ bool init_block_filter_basic{false};
+};
+
+std::vector<std::pair<COutPoint, CAmount>> ResetChainmanAndMempool(TestingSetup& setup, FakeNodeClock& node_clock, const ResetOptions& opts = {});
/// Drain validation callbacks before stopping an index, matching Shutdown() in init.cpp.
void StopIndex(BaseIndex& index, node::NodeContext& node);Why this scored 23/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.