-
Notifications
You must be signed in to change notification settings - Fork 38k
net: fuzz: bypass network magic and checksum validation #31012
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
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsNo conflicts as of last run. |
cc: @dergoegge |
Concept ACK |
fe8fa56
to
aa8208b
Compare
Just moved it to draft to get some conceptual feedbacks first. I added a commit to bypass some asserts in |
Can you explain why the asserts and sanity checks would be failing? They are unrelated to the checksum, so if they are failing, it seems like this patch is incomplete and some part is still checking the magic or checksum, no? |
I'm guessing that we need to make sure that (if we are fuzzing) |
aa8208b
to
ffdbf6c
Compare
Some previously valid magic or checksum could be now be considered invalid. But I removed the commit that bypasses the asserts and changed the verification to: #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
if ((hdr.pchMessageStart[0] & 1) != 0 && hdr.pchMessageStart != m_magic_bytes) {
#else instead of just: #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
if ((hdr.pchMessageStart[0] & 1) != 0) {
#else I think this way we still facilitate it without invalidating valid magic/checksum. |
63fc7e5
to
d5c8c62
Compare
Force-pushed addressing #31012 (comment) and #31012 (comment). Thanks, @dergoegge. |
Approach ACK. The use of I haven't yet worked through the honggfuzz instructions to confirm that they work. I'll circle back to this to give it a try. |
Copy and pasting the command from the docs doesn't work:
|
d5c8c62
to
37a6a75
Compare
Just fixed it. Can you check it? |
Also playing around with this and reading the netdriver post (i couldn't find any other docs on it) I'm not sure if this will ever even get past the version handshake? So I'm wondering how useful this tool really is for us. |
37a6a75
to
f53543f
Compare
Well noticed, just added it. |
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
f53543f
to
d439666
Compare
Yes, I don't think it will pass the version handshake. I can't see what kind of bugs it would find that other fuzzers would not get. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK d439666
I think we could consider removing the honggfuzz netdriver instructions in a follow up but the changes look good to me anyway. I tested this by running honggfuzz in netdriver mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested ACK d439666
If we're going to be peppering the code with these, could we add a safety harness to make sure it's never being used accidentally for a live node? Maybe somewhere in init.cpp or bitcoind.cpp: #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
exit(1);
#endif Edit: I realize that bitcoind should be disabled in that case. This would be belt-and-suspenders to make sure that always holds. |
Seems good. Note that we're already use |
Just want to note that putting something in either of these files wouldn't be enough to prevent someone producing a kernel lib with the fuzzing code. |
Not sure about touching real code with the motivation to make instructions happy that may be removed anyway. If the changes are meaningful for the fuzz target, then it may be fine.
Can you provide more details here? IIUC a hash will still be calculated, just not compared, so this may only drop one hash call, with a possible maximum speed-up of 2x. However, it would be good to actually measure the difference. Otherwise, I am not sure if this is worth it. |
This is not about performance. It makes the |
Ok, then I am nack-ish on this. Generally, test code should follow real code, not the other way round, unless there is a reason. Saving 15 lines of test-only code seems a weak reason to me, but I don't mind if others like this. |
Since everyone agrees on removing Honggfuzz netdriver, I think we can change the approach to simply just remove it from the documentation. |
Closing this in favor of #31092 |
d823ba6 doc: fuzz: remove Honggfuzz NetDriver instructions (brunoerg) Pull request description: Remove Honggfuzz NetDriver instructions from the documentation since it has not been useful for us. See #30957 and #31012. ACKs for top commit: maflcko: lgtm ACK d823ba6 marcofleon: ACK d823ba6 Tree-SHA512: f63fde1076d523dc5e511ef868ca3c1ea2e38fe7df56ae275f33209581f96452d86effedb54d9b0ee8b7a1d492b610799807a727d8bd81e2286d31db4aa68731
Fixes #30957
We currently have some instructions on the documentation about how to fuzz the Bitcoin Core P2P layer using Honggfuzz NetDriver. It includes a patch to be applied to bypass network magic and checksum validation, that is outdated. However, we can change the code to bypass them using
FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
. It also makes thep2p_transport_serialization
fuzz target simpler since we do not need to assist the network magic and checksum creation anymore.