HomePhabricator

Guard CBlockIndex::nStatus/nFile/nDataPos/nUndoPos by cs_main

Description

Guard CBlockIndex::nStatus/nFile/nDataPos/nUndoPos by cs_main

Summary:

CBlockIndex::nStatus may be racy, i.e. potentially accessed by multiple threads, see core#17161. A solution is to guard it by cs_main, along with fellow data members nFile, nDataPos and nUndoPos.

Co-authored-by: Vasil Dimov <vd@FreeBSD.org>

This concludes backport of core#22932 and core#24197
https://github.com/bitcoin/bitcoin/pull/22932/commits/6ea56827842b9b2bd730edc38f3a7b1f46f6247b
https://github.com/bitcoin/bitcoin/pull/24197/commits/20276ca5d124285bdd1bda4cd777ca186b378555

Depends on D13037

Test Plan:
With clang and DEBUG:

ninja all check-all

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D13038

Details

Provenance
Jon Atack <jon@atack.com>Authored on Jan 23 2023, 16:52
PiRKCommitted on Jan 24 2023, 10:18
PiRKPushed on Jan 24 2023, 10:18
Reviewer
Restricted Project
Differential Revision
D13038: Guard CBlockIndex::nStatus/nFile/nDataPos/nUndoPos by cs_main
Parents
rABCbd5235a5a860: Require IsBlockPruned() to hold mutex cs_main
Branches
Unknown
Tags
Unknown