mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:47:36 +00:00
net: stop sharing P2P listeners with automatic Tor services #36170
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36170
Loading…
Reference in a new issue
No description provided.
Delete branch "l0rinc/identify-tor-shared-binds"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem: With a normal
-bindbut no dedicated onion bind, the automatically created Tor onion service can forward incoming connections to the normal P2P listener, where they may be misclassified and inherit IP-based whitelist permissions.Fix: Without a dedicated onion bind, keep Tor control available for outbound proxy discovery but skip automatic onion service creation and log a warning after authenticating with Tor.
The node starts with its configured listeners, including the default onion listener when no
-bindis supplied, and starts Tor control only after those listeners have opened successfully.To accept incoming Tor connections, add a specific non-wildcard
-bind=<addr>:<port>=onionreachable from the Tor daemon.Wildcard onion binds are rejected when
-listenonionis enabled.With
-listenonion=0, they remain accepted, but incoming connections are not identified as Tor connections.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.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
Concept ACK
0.0.0.0is the default for-binditself, and-bind=0.0.0.0:8334=onionpasses the new check while tagging nothing.addr_bindcomes fromGetBindAddresson the accepted socket, so whatCreateNodeFromAcceptedSocketcompares againstm_onion_bindsis the concrete address the peer reached.Same node, same arriving address, same
-whitelist. With-bind=0.0.0.0:P=onionthe inbound peer is classified by its IP network ingetpeerinfoand keeps itsnoban. Spelling that same address out instead of the wildcard givesonionwith no permissions.[::]is classified the same way, and either wildcard is what reaches Tor as theADD_ONIONtarget.Rejecting a wildcard onion bind would close that. Naming
127.0.0.1:8334=onionin the message would only make it less likely. Is the first one in scope here?The release note covers upgraders. For someone setting Tor up from scratch, the
-bindhelp advertisesdefault: 127.0.0.1:8334=onion, which still holds with no explicit-bindbut not once one is given, and section 2 ofdoc/tor.mddoes not mention the dedicated bind. Would a line in one of the two be worth it?nit: this could use the helper the file already uses further down, and then
re,assert_raisesandFailedToStartErrordrop out of the imports. It does loosen the exit status from exactly 1 to any non-zero. Ran it that way and it passes.Approach ACK
Thanks , added a wildcard-bind check and test (added you as coauthor), but I’d appreciate a second look from e.g. @vasild who has more experience with this part of the networking code than I do.
Thanks, added this to both the
-bindhelp and section 2 ofdoc/tor.md. They now explain when the default onion bind is added and when an explicit, non-wildcard=onionbind is required.Switched to
assert_start_raises_init_error, thanks.Approach ACK
69116ee97csame reasoning as in the comment above, wildcard can distinguish.
The impression is that
127.0.0.1must be used.With this PR the automatic Tor service requires a dedicated bind, always, unconditionally. Not only "when -bind is set".
To clarify - if the user did not set
-bind, then the defaults do provide both-bindand-bind=...=onion.Isn't this check redundant? Seems to be the same as the added check in
AppInitParameterInteraction(). Better have just one. I prefer this one because it usesconnOptions.onion_binds. The other one manually "parses" the arguments and checks for=onionsuffix which is redundant with the code that setsconnOptions.onion_binds. That is, if=onionwould have to be changed to e.g. to support case insensitive match, then it would have to be changed in two places, not nice.This message is technically not correct. If wildcard address is used, incoming Tor connections will still be identified just fine. For example:
-bind=1.2.3.4:8333 -bind=0.0.0.0:8334=onion- anything that arrives on port8334will be correctly identified as incoming Tor.The problem, however, is that
0.0.0.0:8334in addition to being used for binding and classifying connections is also used to instruct the Tor daemon to forward incoming connections to it. And telling the Tor daemon to forward connections to0.0.0.0:8334is ill.So, maybe something like: "The automatic Tor onion service cannot use a wildcard onion bind because the Tor daemon wouldn't be able to forward incoming connections to us. Use a specific address such as
-bind=127.0.0.1:<port>=onion, or disable the service with-listenonion=0."Or just: "The automatic Tor onion service cannot use a wildcard onion bind. Use a specific address such as
-bind=127.0.0.1:<port>=onion, or disable the service with-listenonion=0."(not tested)
(not tested)
Earlier concerns neither republished nor resolved: 1 major finding · 2 suggestions. See the Run archive linked from the Review report for their assessments.
🔵 Suggestion ·
-listenonionhelp omits wildcard-bind startup rejectionThe help says proxy discovery remains available without a non-wildcard onion bind, but a wildcard onion bind aborts startup rather than merely disabling service creation.
Location:
src/init.cpp:578(head).🔵 Suggestion · Skipped services lack a startup notice, and explicit
-onionleaves an idle controllerExplicit Tor configurations with only normal
-bindsettings get no GUI or stderr notice that incoming service creation is skipped; an explicit-onionalso leaves the controller with neither service creation nor proxy discovery to perform.Location:
src/torcontrol.cpp:574(head).🔵 Suggestion · Default onion forwarding has no mock-controller coverage
The mock-controller tests never exercise the retained no-
-bindor-whitebind-only path, so they cannot detect losing automatic service creation for those configurations.Location:
src/init.cpp:2312(head).🔵 Suggestion · IPv6 availability guard skips a socket-independent rejection test
The IPv6 wildcard check needs only numeric address parsing, so
test_ipv6_local()unnecessarily skips it on hosts without a route to::1.Location:
test/functional/feature_bind_extra.py:120(head).🔵 Suggestion · Skipped-service coverage omits existing onion identities
The new skipped-service test deletes the cached key first, leaving identity preservation across the recommended bind migration untested; source inspection shows no current key loss.
Location:
test/functional/feature_torcontrol.py:219(head).🔵 Suggestion · Remote-Tor bind guidance omits access restrictions
The remote-Tor guidance does not warn that exposing a non-loopback
=onionlistener to other hosts lets direct peers be treated as Tor peers and become eligible for onion self-advertisements.Location:
doc/tor.md:114(head).Reviewed:
0dfaa81cca91· Review report · Previous reportspermalink
Keep in mind that when running in a container, it is considered best practise to bind to
0.0.0.0/[::]rather than a specific IP. That is because most container engines (e.g. Docker) use dynamic IPs.The issue that
0.0.0.0/[::]are unsuitable to pass via Tor control should imho be solved by a second configuration option, as suggested in https://github.com/bitcoin/bitcoin/issues/25094.I originally added it to reject the configuration before loading chainstate, but I agree that duplicating the argument parsing just for this case isn’t worth it - removed, thanks
Addressed @vasild’s suggestions: reused the configured test arguments, removed the duplicate early check, shortened the errors, and clarified the release notes.
I'd keep rejecting these configurations in this PR and handle that support separately. What do you think @vasild?
I kept "wildcard" here because the IPv4 and IPv6 checks described above both showed misclassification and retained whitelist permissions.
I prefer non-negated versions, it was deliberate
Used your shorter version, thanks.
Further clarification (thanks for double checking this after an offline chat):
Indeed shared binds cannot distinguish incoming Tor vs direct connections. E.g. if we bind on
1.2.3.4:8333and accept incoming Tor and incoming direct connections on that address and port then we can't distinguish, obviously.If we use a wildcard bind for Tor, e.g.
-bind=0.0.0.0:8334=onion, then the problem is slightly different. I got this wrong initially, thanks for correcting me. The wildcard will bind on all addresses of the machine, e.g.127.0.0.1:8334,1.2.3.4:8334,5.6.7.8:8334and there will be no overlap between those and the direct connections1.2.3.4:8333. So far so good, but when an incoming Tor connection arrives, we will then compare the address it arrived on e.g.5.6.7.8:8334to whatever was given to-bindwhich is0.0.0.0:8334and that will not match 💣. So the connection will be wrongly not considered as an incoming Tor connection. In theory, if we want to fix this:github.com/bitcoin/bitcoin@6301d464f7/src/net.cpp (L1791)then we would have to tweak that comparison to "if there is an entry in
m_onion_bindthat is a wildcard and the port matches to the port inaddr_bind, then consider they are equal. I think that is unnecessary.s/Tor-forwarded connections/incoming Tor connections/ACK
5527295cb4IMO it would be an overkill to add one more configuration option to cover this. I think it should be possible to retrieve the IP address that docker assigned to the VM or instruct docker to assign a given one.
Show Signature
vasild's public key is on openpgp.org
ACK
5527295cb4tACK
5527295cb4successfully built & tested with
clang++-19on FreeBSD15.0, targetingx86_64. changes LGTMsince #34892 was closed in favour of this PR (https://github.com/bitcoin/bitcoin/pull/34892#issuecomment-5577081511), i think it makes sense to add a
fixes #33458in the the PR description so that the issue can be closed on merge because this PR actually resolves the issueI'm not sure about this approach. So any existing deployment that has a single bind, which I think is a common configuration, will now fail to start? That seems harsh to me. How about falling back to the default onion bind if no explicit one is given? Maybe I'm missing something, but wouldn't that match more closely with what would be expected to happen with a default on feature?
Shouldn't be because that is flawed because then incoming IP and Tor cannot be distinguished. But I have no idea how widespread it is.
Right.
I agree, it is.
Like a wake up call "fix your config!"
Note that then there is no way to disable the Tor bind. Right now we have:
I think that is logical and is a natural way to disable the Tor bind. By IP bind I mean
-bind=and by Tor bind I mean-bind=...=onion.I agree it is harsh. I think it is acceptable though. But if others find it unacceptable, then it is unacceptable. What other ways might be, hmm...
So, the problem is if
-listenonion=1and only-bind=is used without-bind=...=onion. Then we tell the Tor daemon to forward incoming Tor connections to our normal bind and we cannot distinguish those from incoming IP connections.Some ideas, if the current approach seems unacceptable:
Log a startup warning and still end up in a state where IP and Tor incomings cannot be distinguished. A warning in the GUI as a pop up window will be noticed, but
bitcoindusers with only a warning in the log will probably miss it.Brick only the Tor listening service. That is - allow start but refuse to create the Tor listening service and log a warning periodically, like:
Might result the node operating in semi-degraded state for a long time before the user notices they have no incoming Tor connections and starts investigating. I still like more the refuse-to-start approach because it is obvious.
The root problem here is that there are two options that have to be set together: if
-listenonionis set, then-bind=...=onionmust also be set. And we are trying to handle the cases in which the later is not set. That is a bad interface.A good interface is impossible to misuse.
So, what about another idea: the name of the option
-listenonionis very confusing. I have always wished to do something about it ever since I grasped what it does. What it does is to automatically create the Tor service. It has nothing to do with listening, as in-bind. We might accept incoming Tor connections without it as well, if the Tor service is statically configured inside the Tor daemon, intorrc.So, what about replacing
-listenonionwith-bind=addr:port=onionauto? Note that in order to enable the auto Tor service creation, now one must specify a bind address and port. It is bundled together, impossible to misuse. Currently one can enable auto Tor service without specifying the listening address:port and that is a problem.-listenonion=0-bind=addr:port=onionauto-listenonion=1-bind=addr:port=onionautoThe old default is as if
-listenonion=1 -bind=0.0.0.0:8333 -bind=127.0.0.1:8334=onionwere given. The new one will be as if-bind=0.0.0.0:8333 -bind=127.0.0.1:8334=onionautowere given.What about the problematic case where the user has only explicitly set
-bind=addr:portand has inherited the default-listenonion=1(and thus cannot distinguish incoming IP from Tor)? In the new variant with only an explicit-bind=addr:portand without an explicit-bind=addr:port=onionautothe Tor service will not be created.Doing a cursory search, singular binds in general seem very common, it's even on the bitcoin wiki. I did find a couple of deployment configurations that don't include tor and set a single bind (1, 2).
I don't see why we would necessarily have to brick it. Wouldn't using the current default bind if not onion bind is provided just continue working for most deployments?
That is to ditch this PR? Then leave the problem it tries to resolve opened, from the OP:
FWIW I considered this fine (to not be able to distinguish incoming Tor from IP), but I didn't think it would be widespread. It is a misconfiguration. And then AIs came and told us this this dangerous and I kind of agree to some extent...
I'm not suggesting doing nothing. Maybe I'm not quite following the actual problems, but what I'm suggesting is basically along the lines of adding
-bind=127.0.0.1:<-port+1>=onioninternally whenever a non-onion bind at port is detected in combination with-listenonionand no onion bind is given. Could also combine this with a warning that they should set their onion bind explicitly. I'm also not really sold whether to call this a misconfiguration, or a bug on our side.Requested comments on IRC:
Wonder if we can navigate this issue through only failing during startup if:
-listenonionAND-bind=IPAND-whitelisthas been set.E.g., if this only is an issue when differing permissions are set for different IPs and adjusting permissions is not common, then this should catch the cases we worry about, while letting harmless & common cases continue.
But maybe I'm missing some detail, I've just had a first look.
(This idea was also communicated out of band with l0rinc).
I agree with sedited that this solution, which makes non-tor users of
-bindchange their setup by changing a tor-related config option set by default is not great. They haven't misconfigured anything, and it is not their fault that-listenonionis enabled by default if they don't use it or even know about it, so they should not be expected to turn it off.My favourite short-term solution would be to do what vasild mentioned ("Brick only the Tor listening service"). We could log a warning in torcontrol, but could still have tor outbounds with torcontrol.
Having inbounds is, for the most part, a service to the network, and unlike on clearnet, inbound capacity isn't scarce on the tor network, so a couple of nodes not having inbounds anymore until they fix their config wouldn't be a major problem in my opinion.
As a long-term solution, I would agree that replacing
-listenonionmakes sense, but that would require every tor user to change their config, so is not easily done."-listenonion AND -bind=IP AND -whitelist has been set." would work, but it feels a little bit like a hack to me to disallow a certain combination of options that are not really related logically.
Thanks for the reviews and discussions!
Rebased and pushed, a missing dedicated onion bind now disables only automatic incoming service creation instead of preventing startup, preserving the configured listeners and outbound proxy discovery.
The controller warns after authentication so affected Tor users can add an explicit
=onionbind to restore incoming connections.Tor control now waits for successful binding before requesting a service, and wildcard onion binds remain rejected with
-listenonionenabled.To simplify review, refactors/characterization tests remain separate from behavior fixes (and their matching test updates), with documentation and comments last.
🐙 This pull request conflicts with the target branch and needs rebase.
Rebased after #36637: its new
-torpasswordtest now sets an explicit onion bind so it can verify that successful authentication leads to onion service creation.🐙 This pull request conflicts with the target branch and needs rebase.
Rebase after #36759