Repository navigation
http: Restore requirement of IPv4 bind success - #36187
hodlinator wants to merge 6 commits into
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, 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, thanks for pushing the fix |
This comment was marked as resolved.
This comment was marked as resolved.
054bcdc to
8e30cc9
Compare
8e30cc9 to
64fd5ce
Compare
bc9985a to
690a4b1
Compare
hodlinator
left a comment
There was a problem hiding this comment.
Latest push addresses all but 1 comment from #36187 (review)
|
Concept ACK |
690a4b1 to
05de7be
Compare
hodlinator
left a comment
There was a problem hiding this comment.
Latest push avoids stringly typing endpoints_seen and addresses points from #36187 (review).
|
Updated PR description, primarily the History-section. |
05de7be to
1e57675
Compare
hodlinator
left a comment
There was a problem hiding this comment.
Pushed 1e57675 to address latest round of review.
| endpoints.push_back({.address = "::1", .port = http_port, .required = false}); | ||
| endpoints.push_back({.address = "127.0.0.1", .port = http_port, .required = true}); |
There was a problem hiding this comment.
re #36187 (comment):
I prefer maintaining the same order as on master.
winterrdog
left a comment
There was a problem hiding this comment.
tested ACK 1e57675
successfully built and tested with clang++-20 on Debian, targeting x86_64
l0rinc
left a comment
There was a problem hiding this comment.
I'll review this in more detail a bit later, left a few low-effort suggestions in the meantime...
1e57675 to
a8e7faa
Compare
hodlinator
left a comment
There was a problem hiding this comment.
Pushed new version based on l0rinc's initial feedback, sorry for invalidating the 2 ACKs.
|
Removed AI Disclaimer from PR desc as it could be taken as avoidance of responsibility. Credits for finding the credential exfiltration vulnerability and the initial broad strokes solution still go in part to LLMs. |
l0rinc
left a comment
There was a problem hiding this comment.
Thanks for taking my earlier suggestions! I went over the change more thoroughly now and left a few nits and cleanups. The reason I'm not acking yet is that the new deduplication drops IPv6 binds that differ only in their scope.
When the IPv4 RPC address is already owned, the server starts on its remaining IPv6 listener for both default and explicit bind configurations. bitcoin-cli then sends the generated cookie to the other process on its default IPv4 destination. Record the partial startup and exact captured Authorization credential for the following fail-closed fix.
The next commit requires all binds to succeed, and without this change that one would fail on Mac CI with: [InitHTTPServer] [warning] Binding RPC on address 127.1.1.1:19036 failed: Unable to bind to 127.1.1.1:19036 on this computer (bind returned error Can't assign requested address (49)) The options in this test are there to verify log censorship of sensitive data and bind-addresses were made non-sensitive in bitcoin#26829 / b9d5674. That commit added the missing -rpcallowip option to actually make -rpcbind not be ignored any longer. That commit added 127.0.0.1 in addition to the already existing 127.1.1.1, probably because the latter would fail by itself.
a8e7faa to
44bcdbd
Compare
hodlinator
left a comment
There was a problem hiding this comment.
Latest push addresses #36187 (comment) and #36187 (review) + adds anonymous namespace to make BindAddress fully local to httpserver.cpp.
l0rinc
left a comment
There was a problem hiding this comment.
ACK 44bcdbd
If you need to touch this again, consider using a smaller reproducer in the characterization commit (showing that startup succeeds despite the occupied IPv4 port), with the full credential-capture proof in a collapsible section of the PR description as an optional demo. That would avoid removing all that code we just introduced in the earlier commit.
Allows us to catch fail earlier and have simpler code in a later commit where binds are required to succeed. Co-authored-by: janb84 <[email protected]> Co-authored-by: winterrdog <[email protected]>
While the search is quadratic, we don't expect many local bind addresses.
When any RPC bind succeeds, initialization ignores every other endpoint failure. A process that already owns the default IPv4 port can therefore receive bitcoin-cli credentials while the node continues on IPv6. Switch to safe defaults through only making the default IPv6 address optional, requiring all others. Hosts intentionally providing only an IPv6 interface must use -rpcbind to set that endpoint explicitly. This carries the fail-closed policy from bitcoin#14968 now that the in-tree socket implementation reports each bind result. Co-authored-by: laanwj <[email protected]> Co-authored-by: Lőrinc <[email protected]>
44bcdbd to
061eb6f
Compare
|
reACK 061eb6f Just the explanatory comment and the shared |
|
cc @pinheadmz |
janb84
left a comment
There was a problem hiding this comment.
re ACK 061eb6f
There are some behavioral changes in startup, maybe consider adding a release-note (Ralph suggested the same, but cryptic in his reasoning).
The change that could use a release note is for Ipv6 only hosts, a host or jail without 127.0.0.1 / ipv4 used to start (on master) on ::1 alone. The same functionality now needs -rpcbind=[::1] -rpcallowip=::1 other wise the node will error out.
| with (socket.create_server(('127.0.0.1', self.defaultport)), | ||
| self.nodes[0].assert_debug_log([f"Binding RPC on required address '127.0.0.1:{self.defaultport}' failed:"])): | ||
| self.nodes[0].assert_start_raises_init_error(extra_args, 'Error: Unable to start HTTP server. See debug log for details.') | ||
|
|
There was a problem hiding this comment.
Nit, non-block. Adding something like the test below will fix 2 of the gaps in test as reported by corecheck.
| def run_optional_ipv6_bind_test(self): | |
| self.log.info('Check that the node starts on IPv4 when the default IPv6 RPC address is already owned') | |
| self.nodes[0].rpchost = None | |
| with socket.create_server(('::1', self.defaultport), family=socket.AF_INET6): | |
| with self.nodes[0].assert_debug_log([f"Binding RPC on optional address '[::1]:{self.defaultport}' failed:"]): | |
| self.start_node(0, ['-disablewallet', '-nolisten']) | |
| assert_equal(set(get_bind_addrs(self.nodes[0].process.pid)), {(addr_to_hex('127.0.0.1'), self.defaultport)}) | |
| self.stop_node(0) | |
| def run_unbindable_bind_test(self): | |
| self.log.info('Check that startup fails when an explicit RPC address cannot be bound, even if others succeed') | |
| # 192.0.2.1 (TEST-NET-1, RFC 5737) is not assigned to a local interface, | |
| # so bind() fails with EADDRNOTAVAIL rather than EADDRINUSE. | |
| extra_args = ['-disablewallet', '-nolisten', '-rpcallowip=127.0.0.1', '-rpcbind=127.0.0.1', '-rpcbind=192.0.2.1'] | |
| with self.nodes[0].assert_debug_log([ | |
| f"Binding RPC on address '127.0.0.1:{self.defaultport}'", | |
| f"Binding RPC on required address '192.0.2.1:{self.defaultport}' failed:", | |
| ]): | |
| self.nodes[0].assert_start_raises_init_error(extra_args, 'Error: Unable to start HTTP server. See debug log for details.') | |
| def run_unresolvable_bind_test(self): | |
| self.log.info('Check that startup fails when an explicit RPC address is not numeric, even if others are') | |
| extra_args = ['-disablewallet', '-nolisten', '-rpcallowip=127.0.0.1', '-rpcbind=127.0.0.1', '-rpcbind=localhost'] | |
| with self.nodes[0].assert_debug_log( | |
| [f"Could not lookup RPC bind address 'localhost' port {self.defaultport} (only numeric addresses are allowed)."], | |
| unexpected_msgs=["Binding RPC on address"], # fails before any bind is attempted | |
| ): | |
| self.nodes[0].assert_start_raises_init_error(extra_args, 'Error: Unable to start HTTP server. See debug log for details.') | |
|
Thanks for the review @janb84! As stated out-of-band, starting to write the release notes you suggested motivated me to look into being less harsh on IPv6-only hosts. Upon failure to bind the IPv4 loopback port, we could create an IPv4 socket and try to bind it to a random ephemeral port. If that also fails, we could assume that we don't have an IPv4 stack at all and let the IPv6-only bind be sufficient. I'll need some more time to investigate this. |

Problem
When bitcoind starts and the HTTP IPv4 listen address is occupied by another process, but the IPv6 address is available, the server fails open and generates a cookie file. When bitcoin-cli runs it picks up the cookie file and sends the credentials in plain text to the non-bitcoind process running on the default IPv4 port. An attacker can then use the credentials to commandeer bitcoind over IPv6.
Solution
Safe defaults:
-rpcbindis specified, require that all HTTP listen socket binds succeed (fail closed-behavior).Node operators who only have IPv6 are now required to override
-rpcbindand-rpcallowipto only specify the working interface and allowed subnet if they were not doing so already.The problem of bitcoin-cli sending the credentials to what could possibly be the wrong process remains only in non-default setups.
History
40b556d from 2015 switched the HTTP server from Boost Asio to LibEvent, and binding switched from an attempt at dual-binding IPv4+v6 and falling back to IPv4-only (rpcserver.cpp /
StartRPCThreads()), to binding IPv4 or IPv6 (httpserver.cpp /HTTPBindAddresses()). The current PR restores the prior behavior of IPv4 being mandatory.#14968 from 2018 was an attempt to change the behavior to require all binds to succeed. But it ran into issues with poor IPv6 support on CI.
Severity
This credential exfiltration attack requires capability to launch processes on the bitcoind host. If we are on the same account we can already read the cookie credentials off disk. So it's only really interesting when an attacker is on a different user account on the same host.