Skip to content

Conversation

@vasild
Copy link
Contributor

@vasild vasild commented Jan 9, 2023

In the process of doing so, refactor ConsumeNetAddr() to generate the addresses from IPv4, IPv6, Tor, I2P and CJDNS networks in the same way - by preparing some random stream and deserializing from it. Similar code was already found in RandAddr().

@DrahtBot
Copy link
Contributor

DrahtBot commented Jan 9, 2023

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

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK mzumsande, brunoerg, achow101
Concept ACK dergoegge, jonatack, chinggg
Approach ACK w0xlt
Stale ACK stratospher

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

No conflicts as of last run.

Copy link
Member

@dergoegge dergoegge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

@vasild
Copy link
Contributor Author

vasild commented Jan 10, 2023

0c8daaf752...46a7c30871: fix the build on 32 bit archs and add a comment

Copy link
Contributor

@w0xlt w0xlt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approach ACK

Copy link
Contributor

@mzumsande mzumsande left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

It would be good to also update the netaddress fuzz target with the added networks. At the minimum, we could check / assert IsI2P() for Network::NET_I2P there, maybe we could also assert that addresses from Tor, I2P and CJDNS are always valid, which I believe is guaranteed by the creation process?

@vasild vasild force-pushed the ConsumeNetAddr_I2P_CJDNS branch from 46a7c30 to 74fea1e Compare February 2, 2023 14:04
@vasild
Copy link
Contributor Author

vasild commented Feb 2, 2023

46a7c30871...74fea1e088: expand fuzz/netaddress.cpp with I2P and CJDNS, suggested above. Retry a few times to get a valid address inside RandAddr(), discussion.

@vasild
Copy link
Contributor Author

vasild commented Feb 10, 2023

Don't merge this before the problems it uncovered are fixed by #27071 (the CI is failing anyway).

@jonatack
Copy link
Member

Concept ACK. Reviewed prerequisite PR #27071.

@chinggg
Copy link
Contributor

chinggg commented Feb 15, 2023

Concept ACK

@vasild
Copy link
Contributor Author

vasild commented Sep 8, 2023

74fea1e088...8acdbb5a22: rebase due to conflicts

This PR extends the tests which uncovers a bug. The CI will likely fail due to that bug. The fix of the bug is pending review at #27071.

achow101 added a commit to bitcoin-core/gui that referenced this pull request Oct 19, 2023
0e6f6eb net: remove unused CConnman::FindNode(const CSubNet&) (Vasil Dimov)
9482cb7 netbase: possibly change the result of LookupSubNet() to CJDNS (Vasil Dimov)
53afa68 net: move MaybeFlipIPv6toCJDNS() from net to netbase (Vasil Dimov)
6e30865 net: move IsReachable() code to netbase and encapsulate it (Vasil Dimov)
c42ded3 fuzz: ConsumeNetAddr(): avoid IPv6 addresses that look like CJDNS (Vasil Dimov)
64d6f77 net: put CJDNS prefix byte in a constant (Vasil Dimov)

Pull request description:

  `LookupSubNet()` would treat addresses that start with `fc` as IPv6 even if `-cjdnsreachable` is set. This creates the following problems where it is called:

  * `NetWhitelistPermissions::TryParse()`: otherwise `-whitelist=` fails to white list CJDNS addresses: when a CJDNS peer connects to us, it will be matched against IPv6 `fc...` subnet and the match will never succeed.

  * `BanMapFromJson()`: CJDNS bans are stored as just IPv6 addresses in `banlist.json`. Upon reading from disk they have to be converted back to CJDNS, otherwise, after restart, a ban entry like (`fc00::1`, IPv6) would not match a peer (`fc00::1`, CJDNS).

  * `RPCConsole::unbanSelectedNode()`: in the GUI the ban entries go through `CSubNet::ToString()` and back via `LookupSubNet()`. Then it must match whatever is stored in `BanMan`, otherwise it is impossible to unban via the GUI.

  These were uncovered by bitcoin/bitcoin#26859.

  Thus, flip the result of `LookupSubNet()` to CJDNS if the network base address starts with `fc` and `-cjdnsreachable` is set. Since subnetting/masking does not make sense for CJDNS (the address is "random" bytes, like Tor and I2P, there is no hierarchy) treat `fc.../mask` as an invalid `CSubNet`.

  To achieve that, `MaybeFlipIPv6toCJDNS()` has to be moved from `net` to `netbase` and thus also `IsReachable()`. In the process of moving `IsReachable()`, `SetReachable()` and `vfLimited[]` encapsulate those in a class.

ACKs for top commit:
  jonatack:
    Code review ACK 0e6f6eb
  achow101:
    ACK 0e6f6eb
  mzumsande:
    re-ACK 0e6f6eb

Tree-SHA512: 4767a60dc882916de4c8b110ce8de208ff3f58daaa0b560e6547d72e604d07c4157e72cf98b237228310fc05c0a3922f446674492e2ba02e990a272d288bd566
@vasild vasild force-pushed the ConsumeNetAddr_I2P_CJDNS branch from 8acdbb5 to 722fdf1 Compare October 31, 2023 09:58
@vasild
Copy link
Contributor Author

vasild commented Oct 31, 2023

8acdbb5a22...722fdf14a7: rebase and take out of draft because #27071 has been merged. Ready for review.

@vasild
Copy link
Contributor Author

vasild commented Jan 22, 2024

To reproduce: Base64: IAEgdZ/fIAAAAAAaAAQAAUlJSUlZAAAAAALfAAAAGgAEAAH/+/5lAAAAgAAAIwCAKQ==.

@mzumsande, right! What about this fix (git diff -w):

--- i/src/test/fuzz/banman.cpp
+++ w/src/test/fuzz/banman.cpp
@@ -67,18 +67,20 @@ FUZZ_TARGET(banman, .init = initialize_banman)
         LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 300)
         {   
             CallOneOf(
                 fuzzed_data_provider,
                 [&] {
                     CNetAddr net_addr{ConsumeNetAddr(fuzzed_data_provider)};
+                    if (!net_addr.IsCJDNS()) {
                         const std::optional<CNetAddr>& addr{LookupHost(net_addr.ToStringAddr(), /*fAllowLookup=*/false
                         if (addr.has_value() && addr->IsValid()) {
                             net_addr = *addr;
                         } else {
                             contains_invalid = true;
                         }
+                    }
                     ban_man.Ban(net_addr, ConsumeBanTimeOffset(fuzzed_data_provider), fuzzed_data_provider.ConsumeBool
                 },
                 [&] {
                     CSubNet subnet{ConsumeSubNet(fuzzed_data_provider)};

@brunoerg?

@DrahtBot DrahtBot requested review from w0xlt and removed request for w0xlt January 22, 2024 16:30
@brunoerg
Copy link
Contributor

Concept ACK

@DrahtBot DrahtBot requested review from w0xlt and removed request for w0xlt January 23, 2024 10:27
@brunoerg
Copy link
Contributor

brunoerg commented Jan 23, 2024

@brunoerg?

Sounds good to me. I didn't check the code yet but is the CJDNS address from ConsumeNetAddr always valid?

@DrahtBot DrahtBot requested review from w0xlt and removed request for w0xlt January 23, 2024 10:31
In the process of doing so, refactor `ConsumeNetAddr()` to generate the
addresses from IPv4, IPv6, Tor, I2P and CJDNS networks in the same way -
by preparing some random stream and deserializing from it. Similar code
was already found in `RandAddr()`.
@vasild vasild force-pushed the ConsumeNetAddr_I2P_CJDNS branch from 790f0cb to b851c53 Compare January 23, 2024 10:50
@vasild
Copy link
Contributor Author

vasild commented Jan 23, 2024

790f0cb60d...b851c5385d: rebase and adjust fuzz/banman.cpp due to #26859 (review).

is the CJDNS address from ConsumeNetAddr always valid

Yes, I think so. Anyway, for safety wrt future changes I added IsValid() to the check. That is - omit lookup for valid CJDNS addresses.

Copy link
Contributor

@mzumsande mzumsande left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK b851c53

I let the banman fuzzer run for a while, and it didn't crash anymore.

@DrahtBot DrahtBot requested review from brunoerg, stratospher and w0xlt and removed request for w0xlt January 25, 2024 23:24
Copy link
Contributor

@brunoerg brunoerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK b851c53

@DrahtBot DrahtBot requested review from w0xlt and removed request for w0xlt January 26, 2024 01:02
@achow101
Copy link
Member

ACK b851c53

@DrahtBot DrahtBot requested review from w0xlt and removed request for w0xlt January 31, 2024 21:35
@achow101 achow101 merged commit aa9231f into bitcoin:master Jan 31, 2024
@vasild vasild deleted the ConsumeNetAddr_I2P_CJDNS branch February 1, 2024 08:59
Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Post-merge ACK b851c53

/**
* BIP155 network ids recognized by this software.
*/
enum BIP155Network : uint8_t {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, making BIP155Network a public enum facilitates updating #27385.

@bitcoin bitcoin locked and limited conversation to collaborators Feb 1, 2025
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.

10 participants