8000 Fuzz: extend CConnman tests by vasild · Pull Request #28584 · bitcoin/bitcoin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fuzz: extend CConnman tests #28584

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

vasild
Copy link
Contributor
@vasild vasild commented Oct 4, 2023

Extend CConnman fuzz tests to also exercise the methods OpenNetworkConnection(), CreateNodeFromAcceptedSocket(), InitBinds() and SocketHandler().

Previously fuzzin 8000 g those methods would have resulted in real socket functions being called in the operating system which is undesirable during fuzzing. Now that #21878 is complete all those are mocked to a fuzzed socket and a fuzzed DNS resolver (see how CreateSock and g_dns_lookup are replaced in the first commit).

@DrahtBot
Copy link
Contributor
DrahtBot commented Oct 4, 2023

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

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/28584.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK jonatack
Concept ACK dergoegge
Stale ACK brunoerg

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #32065 (i2p: make a time gap between creating transient sessions and using them by vasild)
  • #32015 (net: replace manual reference counting of CNode with shared_ptr by vasild)
  • #30988 (Split CConnman by vasild)
  • #29641 (scripted-diff: Use LogInfo over LogPrintf [WIP, NOMERGE, DRAFT] by maflcko)
  • #29415 (Broadcast own transactions only via short-lived Tor or I2P connections by vasild)

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.

@dergoegge
Copy link
Member

Concept ACK

@dergoegge
Copy link
Member

The cpu utilization of this target doesn't look great, i suspect this is due to timeouts/sleeps e.g.:

interruptNet.sleep_for(timeout);

Would be nice to address that (maybe in a follow up).

Here is a preliminary coverage report: https://dergoegge.github.io/bitcoin-coverage/pr28584/fuzz.coverage/index.html (I'll update this after fuzzing for longer). Looks good to me as the target alone now has more coverage (by line count) in net.cpp than our coverage on master with all targets.

@brunoerg
Copy link
Contributor
brunoerg commented Oct 4, 2023

Concept ACK

@DrahtBot DrahtBot removed the CI failed label Oct 5, 2023
@vasild
Copy link
Contributor Author
vasild commented Oct 5, 2023

@dergoegge, thanks for looking into this!

The cpu utilization of this target doesn't look great

How did you measure? I guess it should be possible to mock CConnman::interruptNet so that its sleep_for() method returns immediately.

@dergoegge
Copy link
Member

How did you measure?

Eyeballing htop this target only achieves about 10% - 30% per core on my machine.

I guess it should be possible to mock CConnman::interruptNet so that its sleep_for() method returns immediately.

Sounds good to me.

@vasild
Copy link
Contributor Author
vasild commented Oct 5, 2023

When I run FUZZ=connman ./src/test/fuzz/fuzz it is single CPU/single threaded and it stays at 98%-100% CPU all the time. It is the same in master. Does it get executed on >1 cores for you?

@dergoegge
Copy link
Member

When I run FUZZ=connman ./src/test/fuzz/fuzz it is single CPU/single threaded and it stays at 98%-100% CPU all the time.

For how long did you run this? The fuzzer needs to first find inputs that trigger sleep_for for you to be able to observe the problem. I have tested this on two machines now and the result is always the same.

Does it get executed on >1 cores for you?

You can let libfuzzer run on multiple cores with either -jobs=<num cpus> or -fork=<num cpus>. I prefer fork since it also includes a minimization step.

@vasild
Copy link
Contributor Author
vasild commented Oct 11, 2023

I guess it should be possible to mock CConnman::interruptNet so that its sleep_for() method returns immediately.

Another use-case for that mock: #28635:

If the test suite could mock the delay in ThreadOpenAddedConnections ...

@vasild
Copy link
Contributor Author
vasild commented Jan 18, 2024

20a9fc83bd...cd5bbb12e0: rebase due to conflicts

@vasild
Copy link
Contributor Author
vasild commented Feb 4, 2024

cd5bbb12e0...5e3c80da14: address suggestions

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 5e3c80d

@DrahtBot
Copy link
Contributor

🚧 At least one of the CI tasks failed. Make sure to run all tests locally, according to the
documentation.

Possibly this is due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.

Leave a comment here, if you need help tracking down a confusing failure.

Debug: https://github.com/bitcoin/bitcoin/runs/21199329709

@vasild
Copy link
Contributor Author
vasild commented Apr 11, 2025

696b6671da...7e42c92d2b: rebase due to conflicts

@vasild
Copy link
Contributor Author
vasild commented May 30, 2025

7e42c92d2b...582d9e3dbd: rebase due to conflicts

@vasild
Copy link
Contributor Author
vasild commented May 30, 2025

I believe all issues here have been addressed and this is ready for review. Has a stale ACK from @brunoerg and @jonatack and Concept ACK from @dergoegge.

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.

reACK 582d9e3

Just generated this coverage report with some hours of running: https://brunoerg.xyz/bitcoin-core-coverage/28584/coverage_report/

@DrahtBot DrahtBot requested a review from jonatack June 2, 2025 14:31
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.

re-ACK 582d9e3 per git range-diff 1c66023 c97d496 582d9e3

changes since my last review #28584 (review) have been rebases and adding commit cf0a497

@DrahtBot DrahtBot requested a review from dergoegge June 4, 2025 15:35
vasild added 7 commits June 9, 2025 10:45
`FuzzedSock::Accept()` properly returns a new socket, but it forgot to
set the output argument `addr`, like `accept(2)` is expected to.

This could lead to reading uninitialized data during testing when we
read it, e.g. from `CService::SetSockAddr()` which reads the `sa_family`
member.

Set `addr` to a fuzzed IPv4 or IPv6 address.
Now that all network calls done by `CConnman::OpenNetworkConnection()`
are done via `Sock` they can be redirected (mocked) to `FuzzedSocket`
for testing.
* Make the methods of `CThreadInterrupt` virtual and store a pointer to
  it in `CConnman`, thus making it possible to override with a mocked
  instance.
* Initialize `CConnman::m_interrupt_net` from the constructor, making it
  possible for callers to supply mocked version.
* Introduce `FuzzedThreadInterrupt` and `ConsumeThreadInterrupt()` and
  use them in `src/test/fuzz/connman.cpp` and `src/test/fuzz/i2p.cpp`.

This improves the CPU utilization of the `connman` fuzz test.

As a nice side effect, the `std::shared_ptr` used for
`CConnman::m_interrupt_net` resolves the possible lifetime issues with
it (see the removed comment for that variable).
@vasild
Copy link
Contributor Author
vasild commented Jun 9, 2025

582d9e3dbd...0802398e74: rebase and address suggestions

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.

Review re-ACK 0802398

@DrahtBot DrahtBot requested a review from brunoerg June 19, 2025 00:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
0