Review report

core: PR #36000

1 minor finding

Earlier concerns neither republished nor resolved: 2 suggestions. See the Run archive for their assessments.

Findings

Link

[minor] · Pending block reads can outlive the kernel context during teardown

An external C API embedder can trigger a use-after-free by releasing the context before the chainstate manager when block-read tasks remain pending.

Location: src/validation.cpp:1868 (head).

Details and suggested fix

ChainMan destroys m_context before m_chainman, even though the context owns the chain parameters used by block reads. ActivateBestChain() can return with read-ahead tasks queued or running, including after an interrupt, an invalid block, or a system error. During chainstate teardown, ThreadPool::Stop() drains queued tasks and joins running ones; those tasks call BlockManager::ReadBlock(), which accesses the freed chain parameters. The flush in btck_chainstate_manager_destroy() holds cs_main, which does not synchronize with those readers. The in-tree callers destroy the chainstate manager first, so no concrete production trigger was identified beyond external embedders that release handles in the opposite order while reads are pending. Declare m_context before m_chainman so the context remains alive until the readers have stopped.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.