AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Moderate 54 Bitcoin

net: move cs_main up in FetchBlock to fix rpc assert crash

Public commit record

What the developer wrote

Authored by Eugene Siegel

85/100 · Strong
net: move cs_main up in FetchBlock to fix rpc assert crash

1. FetchBlock runs in a http worker thread. It acquires a PeerRef,
locks cs_main, then may later call BlockRequested which asserts
that CNodeState exists for the peer.

2. FinalizeNode may run in either the bitcoind or b-net threads. It
locks cs_main, fetches a PeerRef from RemovePeer, fetches a CNodeState,
and later removes it from m_node_states.

Because of the lock placement in FetchBlock, the http worker thread in 1)
can acquire a valid PeerRef and block while the b-net thread in 2) is
cleaning up the peer in FinalizeNode. When the worker thread later acquires
cs_main, it may crash in BlockRequested since no CNodeState exists. Fix
this by acquiring the lock earlier in FetchBlock.

The lock can be replaced with a net-specific lock when the remaining
CNodeState fields are moved to Peer.
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode
The short version

What changed, and why it matters

This commit fixes a rare crash in Bitcoin Core's networking code. When a user called a specific RPC command to fetch a block, the program could crash with an assertion failure if a peer disconnected at exactly the wrong moment. The fix moves a lock earlier so the peer's state cannot be cleaned up while the RPC thread is still using it. It is a stability bug, not a code-execution vulnerability, and requires precise timing to trigger.

Recommended action

Treat as a denial-of-service/stability fix worth backporting. Nodes serving RPC should upgrade, especially if exposed to untrusted or automated RPC callers. No immediate incident response is needed beyond normal patch management.

Security signals we found

01

Assertion failure / crash in RPC path

02

Race condition between RPC worker thread and peer finalization

03

Missing synchronization around peer lifecycle lookup

04

Fix moves lock before resource acquisition

Risk score

Why this scored 54/100

Our methodology →
Potential impact 18/30
Exploitability 8/25
Stealth signal 6/15
Affected reach 10/15
Confidence 8/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.