Skip to content

Conversation

@laanwj
Copy link
Member

@laanwj laanwj commented Nov 18, 2016

Make a copy of the boost time-point to wait for, as the head of the queue may be deleted by another thread while this one is waiting, while the boost function still has a reference to it.

Although this problem is in non-test code, this is not an actual problem outside of the tests because we use the thread scheduler with only one service thread, so there will never be threads fighting at the head of the queue.

The old boost fallback escapes this problem because it passes a scalar value to wait_until instead of a const object reference.

Found by running the bitcoin_test in LLVM-4.0-master asan.
See also: https://svn.boost.org/trac/boost/ticket/11097#comment:10

Make a copy of the boost time-point to wait for, otherwise the head of
the queue may be deleted by another thread while this one is waiting,
while the boost function still has a reference to it.

Although this problem is in non-test code, this is not an actual problem
outside of the tests because we use the thread scheduler with only one
service thread, so there will never be threads fighting at the head of
the queue.

The old boost fallback escapes this problem because it passes a scalar
value to wait_until instead of a const object reference.

Found by running the tests in LLVM-4.0-master asan.
@maflcko
Copy link
Member

maflcko commented Nov 18, 2016

utACK 12519bf

@gmaxwell
Copy link
Contributor

utACK

@laanwj laanwj merged commit 12519bf into bitcoin:master Nov 19, 2016
laanwj added a commit that referenced this pull request Nov 19, 2016
12519bf test: Fix use-after-free in scheduler tests (Wladimir J. van der Laan)
maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request Nov 19, 2016
Make a copy of the boost time-point to wait for, otherwise the head of
the queue may be deleted by another thread while this one is waiting,
while the boost function still has a reference to it.

Although this problem is in non-test code, this is not an actual problem
outside of the tests because we use the thread scheduler with only one
service thread, so there will never be threads fighting at the head of
the queue.

The old boost fallback escapes this problem because it passes a scalar
value to wait_until instead of a const object reference.

Found by running the tests in LLVM-4.0-master asan.

Github-Pull: bitcoin#9186
Rebased-From: 12519bf
codablock pushed a commit to codablock/dash that referenced this pull request Jan 15, 2018
12519bf test: Fix use-after-free in scheduler tests (Wladimir J. van der Laan)
lateminer pushed a commit to lateminer/bitcoin that referenced this pull request Oct 21, 2018
Make a copy of the boost time-point to wait for, otherwise the head of
the queue may be deleted by another thread while this one is waiting,
while the boost function still has a reference to it.

Although this problem is in non-test code, this is not an actual problem
outside of the tests because we use the thread scheduler with only one
service thread, so there will never be threads fighting at the head of
the queue.

The old boost fallback escapes this problem because it passes a scalar
value to wait_until instead of a const object reference.

Found by running the tests in LLVM-4.0-master asan.

Github-Pull: bitcoin#9186
Rebased-From: 12519bf
andvgal pushed a commit to energicryptocurrency/gen2-energi that referenced this pull request Jan 6, 2019
12519bf test: Fix use-after-free in scheduler tests (Wladimir J. van der Laan)
CryptoCentric pushed a commit to absolute-community/absolute that referenced this pull request Feb 24, 2019
12519bf test: Fix use-after-free in scheduler tests (Wladimir J. van der Laan)
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants