Skip to content
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

Add the first fuzz target for Qt #3171

Merged
merged 3 commits into from
Jan 2, 2020
Merged

Conversation

rlohning
Copy link
Contributor

This builds Qt and a first fuzz target for it. Qt's sources contain further fuzz targets already, but I'd like to start with one to see if and how this all works. If it does, I'll add the others one by one.

Improvements I'd like to do soon, i.e. not in this change:

  • further fuzz targets
  • dictionaries
  • add proper parameters to Qt's configure instead of editing the mkspec files in build.sh

In case I made any mistakes, please let me know and I'll happily fix them.

A healthy, happy new year to all of you. :-)

@rlohning
Copy link
Contributor Author

Can you please give me a hint how I could fix the afl-build in the CI?

It fails because the "binary is not instrumented" and points me to docs/README. That again tells me to use AFL's compiler wrappers, but Travis uses "CC=clang" and "CXX=clang++".

What am I missing? What can I do to fix this?

Thanks in advance for your help, see you next year. :-)

@jonathanmetzman
Copy link
Contributor

jonathanmetzman commented Dec 30, 2019

That usually happens when your AFL target is actually built for use with libFuzzer (-fsanitize=fuzzer) instead of AFL (LIB_FUZZING_ENGINE).
I can't tell that you are doing this for sure, since your build.sh doesn't seem to be using -fsanitize=fuzzer or LIB_FUZZING_ENGINE, but that itself is a sign that you aren't building AFL targets correctly.

@rlohning
Copy link
Contributor Author

rlohning commented Jan 2, 2020

Happy new year! :-)

Thank you for that hint. I have "-fsanitize=fuzzer" hardcoded in the fuzz target's project file. Now I added a workaround which removes that line using sed. I'll provide a better fix in Qt's sources but this will take a bit of time for the review- and merging-process, so for now, continuing with the workaround seems fine to me.

Please let me know if there's anything else I should change.

@jonathanmetzman jonathanmetzman merged commit 04ea24e into google:master Jan 2, 2020
@jonathanmetzman
Copy link
Contributor

2020 resolution: Find Qt bugs!

@rlohning
Copy link
Contributor Author

rlohning commented Jan 2, 2020

We will, I'm afraid. ;-)

Thank you!

@kcc
Copy link
Contributor

kcc commented Jan 3, 2020

Does this fuzz target actually run?
I've tried running it locally and it complains

build/out/qt/readnext: error while loading shared libraries: libQt6Core.so.6: cannot open shared object file: No such file or directory

Adding LD_LIBRARY_PATH=build/out/qt/lib makes it work, but will ClusterFuzz do it?

@jonathanmetzman
Copy link
Contributor

@jonathanmetzman
Copy link
Contributor

You can't use absolute paths to dynamic libraries. In fact it's better not to use them at all. But if you must, then you need to use $ORIGIN.

I wonder how this passed travis.

Because /out exists on the runner and the builder but not on ClusterFuzz :-(

@rlohning
Copy link
Contributor Author

rlohning commented Jan 6, 2020

/out does not exist? So where am I supposed to put the binaries instead?

@rlohning
Copy link
Contributor Author

rlohning commented Jan 6, 2020

Does this fuzz target actually run?
I've tried running it locally and it complains

This looks like you tried running the fuzz target directly from outside the docker image. Then, of course, it cannot find the lib inside the docker image.

When I start the fuzz target using
python infra/helper.py run_fuzzer qt readnext
it seems to work fine.

Is running the fuzz target from outside the docker image expected to work?

@rlohning rlohning mentioned this pull request Jan 6, 2020
@rlohning
Copy link
Contributor Author

rlohning commented Jan 6, 2020

If it is meant to work, #3188 will do it.

@jonathanmetzman
Copy link
Contributor

Is running the fuzz target from outside the docker image expected to work?

It isn't mean to work.

When I start the fuzz target using
python infra/helper.py run_fuzzer qt readnext
it seems to work fine.

Sorry this should have failed. It only passed due to a bug that made run_fuzzer run the fuzzer in an environment that resembled (in one important respect) the builder instead of ClusterFuzz

@rlohning
Copy link
Contributor Author

rlohning commented Jan 7, 2020

Today, my build failed with:

Step #13: BAD BUILD: fuzzing /tmp/not-out/readnext with afl-fuzz failed.

Just like a number of other projects did. Running check_build locally passes.

Is this something I could fix or may I hope that the next build will pass?

@jonathanmetzman
Copy link
Contributor

Sorry I think that was a hiccup (see #3194) I caused when trying to ensure that the mistake you initially made gets caught by CI.
I apologize for the confusion. I've fixed the issue. The latest builds for qt seem to pass.

@rlohning
Copy link
Contributor Author

rlohning commented Jan 9, 2020

They do. Thank you for fixing it.

@rlohning
Copy link
Contributor Author

rlohning commented Jan 9, 2020

Oh, no they don't, see https://oss-fuzz-build-logs.storage.googleapis.com/log-cd589d68-203a-4e05-af65-efb95abe3484.txt

Step #5: [/corpus/readnext.zip]
Step #5: End-of-central-directory signature not found. Either this file is not
Step #5: a zipfile, or it constitutes one disk of a multi-part archive. In the
Step #5: latter case the central directory and zipfile comment will be found on
Step #5: the last disk(s) of this archive.
Step #5: unzip: cannot find zipfile directory in one of /corpus/readnext.zip or
Step #5: /corpus/readnext.zip.zip, and cannot find /corpus/readnext.zip.ZIP, period.
Finished Step #5
ERROR
ERROR: build step 5 "gcr.io/oss-fuzz-base/base-runner" failed: exit status 9

The file was zipped a couple of lines higher and that seems to have succeeded. Does anything go wrong when copying the file?

@Dor1s
Copy link
Contributor

Dor1s commented Jan 9, 2020

@rlohning This last error is from the coverage build. The missing corpus in not seed corpus provided with the build, it's minimized corpus backup created by ClusterFuzz.

I have added an auxiliary message to such failures in cfe13cb#diff-40efeb3947f1f992a35c2c73c6992689R180

@rlohning
Copy link
Contributor Author

rlohning commented Jan 9, 2020

Sorry, I don't quite get it. Is there anything I can do about that issue?

@rlohning
Copy link
Contributor Author

Now, without any changes from my side, a build succeed and I get coverage statistics. This seems to answer the question above. :-)

@Dor1s
Copy link
Contributor

Dor1s commented Jan 13, 2020

Awesome! Sorry for the trouble.

@rlohning
Copy link
Contributor Author

All fine. Thank you for your patience. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants