Page MenuHomePhabricator

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

Authored by PiRK on Jan 24 2023, 07:22.

Details

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

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

PiRK requested review of this revision.Jan 24 2023, 07:22
Fabien requested changes to this revision.Jan 24 2023, 09:03
Fabien added a subscriber: Fabien.
Fabien added inline comments.
src/blockindex.h
88 ↗(On Diff #37656)

Macro likestamp:

src/test/blockindex_tests.cpp
55 ↗(On Diff #37656)

Just lock once before the loops

276 ↗(On Diff #37656)

dito

src/txdb.cpp
344 ↗(On Diff #37656)
This revision now requires changes to proceed.Jan 24 2023, 09:03
PiRK edited the summary of this revision. (Show Details)
This revision is now accepted and ready to land.Jan 24 2023, 10:16