net: fix rare race in Tor stream isolation credentials #37043

Open
PiRK wants to merge 1 commit from net-tor-credentials-race into master AGit
PiRK commented 2026-12-02 11:25:04 +00:00 (Migrated from github.com)

TorStreamIsolationCredentialsGenerator::Generate() reads m_counter to format the credentials, then increments it in a separate operation. The increment is atomic but the read and the increment together are not, so two threads calling Generate() at the same time (e.g. the automatic and added-node connection threads) can get the same credentials, and their connections may then share a Tor circuit.

Use the value returned by fetch_add(), so that each call gets a distinct counter value.

TorStreamIsolationCredentialsGenerator::Generate() reads m_counter to format the credentials, then increments it in a separate operation. The increment is atomic but the read and the increment together are not, so two threads calling Generate() at the same time (e.g. the automatic and added-node connection threads) can get the same credentials, and their connections may then share a Tor circuit. Use the value returned by fetch_add(), so that each call gets a distinct counter value.
DrahtBot commented 2026-12-02 11:25:17 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.
A summary of reviews will appear here.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/37043 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/37043.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/37043#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. A summary of reviews will appear here. <!--5faf32d7da4f0f540f40219e4f7537a3-->
First-time contributor

🔵 Suggestion · Credential uniqueness tests miss concurrent Generate() calls

The existing uniqueness assertion in feature_proxy.py checks sequential connections, so it does not exercise the concurrent credential-generation invariant fixed here.

Location: src/netbase.cpp:783 (head).


Reviewed: b44500fc8d7e · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:e1a29e5e677c47d383756f0fcf8f3760725c91d1104dd3ccb2f333b6217eba26:47880f5569fd2047d249266f337c4f2a509adf7d96c3ccb1c7644c2c2a650bff --> <!-- ralph-base:cc27c50e87f348c154512a15f53cd552d4cd8844 --> <!-- ralph-head:b44500fc8d7e8bc8d2bdce33cc6c85cac6aca37d --> <!-- ralph-case:c182ad0a794f454269f87a2f9b3da6d2f22bcb09d8e1e5d541f26b51e4fe5bec --> **🔵 Suggestion · Credential uniqueness tests miss concurrent `Generate()` calls** The existing uniqueness assertion in `feature_proxy.py` checks sequential connections, so it does not exercise the concurrent credential-generation invariant fixed here. Location: [`src/netbase.cpp:783`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/b44500fc8d7e8bc8d2bdce33cc6c85cac6aca37d/src/netbase.cpp#L783>) (head). <!-- Review tier: sensitive --> --- Reviewed: [`b44500fc8d7e`](<https://git.fish.foo/bitcoin/bitcoin/commit/b44500fc8d7e8bc8d2bdce33cc6c85cac6aca37d>) · [Review report](<https://review.fish.foo/report/37043-b44500fc8d7e8bc8d2bdce33cc6c85cac6aca37d-3431-1.html>) · [Previous reports](<https://review.fish.foo/traces/37043/>) [permalink](<https://review.fish.foo/report/37043-b44500fc8d7e8bc8d2bdce33cc6c85cac6aca37d-3431-1.html>)
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!37043
No description provided.