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

Make CMake sanitizer agnostic #82

Closed
wants to merge 1 commit into from

Conversation

bshastry
Copy link
Contributor

@bshastry bshastry commented Aug 20, 2019

Fixes a minor issue in #78 (see #78 (comment)) and another one (see google/oss-fuzz#2834 (comment))

@bshastry
Copy link
Contributor Author

CC @pwnall @Dor1s @inferno-chromium

@pwnall
Copy link
Member

pwnall commented Aug 21, 2019

The CI errors might be due to problems on the master branch. These problems were fixed on the latest master, so rebasing might help.

@Dor1s
Copy link

Dor1s commented Aug 21, 2019

To make sure we're on the same page: when producing a build for OSS-Fuzz, we should use CFLAGS or CXXFLAGS for compilation , then link with clang++ and CXXFLAGS. None additional sanitizer / fuzzing flags are needed.

For CI, -fsanitize=address -fsanitize-coverage=trace-pc-guard is fine, though I'd rather suggest the following:

  1. compile using -fsanitize=address,fuzzer-no-link
  2. link using -fsanitize=address,fuzzer

@bshastry
Copy link
Contributor Author

Update: Rebased and incorporated @Dor1s suggestion of separate compile/link flags.

@bshastry bshastry force-pushed the libfuzzer-harness branch 5 times, most recently from 5947a54 to 6c7dc2b Compare August 21, 2019 14:02
@bshastry
Copy link
Contributor Author

Once this PR is merged,I will create an ossfuzz integration

@bshastry
Copy link
Contributor Author

Dear all, I created a branch locally to add snappy to ossfuzz and verified that all sanitizer builds (asan, ubsan, msan) are successful. Looking forward to the review of this PR. Thank you!

@bshastry
Copy link
Contributor Author

Dear all, A gentle reminder that this PR is awaiting a review :-)

Thank you!

@bshastry
Copy link
Contributor Author

bshastry commented Sep 6, 2019

Dear all, I'm waiting on a review to get this merged :-)

Thank you
Bhargava

@bshastry
Copy link
Contributor Author

bshastry commented Sep 6, 2019

Rebased on current master

@inferno-chromium
Copy link

@pwnall - can you please help to review this latest rebased change. Thanks!

@pwnall
Copy link
Member

pwnall commented Sep 17, 2019

Sorry for the radio silence here. I won't be able to tackle this for another week or so.

@bshastry
Copy link
Contributor Author

Oops, spotted another mistake in this PR in the meantime :-)

Now, snappy builds should build transparently against choice of sanitizer-fuzzer :-)

@pwnall
Copy link
Member

pwnall commented Oct 1, 2019

@bshastry @inferno-chromium @Dor1s I don't like the branching in this PR. I'd prefer that both the CMake config and the Travis config stay as simple as possible, and that it's easy to get a reasonable fuzzing build up in development.

I've prototyped an alternative at pwnall@a4b8446 in https://github.com/pwnall/snappy/tree/fix_fuzz -- TL;DR: the fuzzing flags get extracted to SNAPPY_FUZZING_FLAGS. ossfuzz can set SNAPPY_FUZZING_FLAGS="" and define its own flags with CXXFLAGS and LDFLAGS.

@bshastry
Copy link
Contributor Author

bshastry commented Oct 1, 2019

@pwnall I had a quick look at your prototype. Sadly, it is going to break afl build within ossfuzz because it is not linked against $LIB_FUZZING_ENGINE

I was mistaken. This can work provided we don't hard code the linking option to "-fsanitize=fuzzer" and write the build script correctly.

Also, I think ossfuzz expects one sanitizer per build. So one shouldn't set cxxflags to enable two sanitizers (e.g., address and undefined) at a given time. Moreover, memory and address sanitizer cannot be used together. For these reasons, the MSan CI on the prototype will likely fail as well

@bshastry
Copy link
Contributor Author

bshastry commented Oct 1, 2019

@pwnall Rebased and tried to incorporate your feedback. Hope I got it right.

@bshastry bshastry force-pushed the libfuzzer-harness branch 3 times, most recently from 76a560b to f270149 Compare October 1, 2019 16:34
@bshastry
Copy link
Contributor Author

Dear @pwnall

I readied the PR for a re-review. Looking forward.

Thank you,
Bhargava

@bshastry
Copy link
Contributor Author

Dear all,

I was wondering if you had the chance to review this PR. Would be nice to see snappy fuzzed continuously :-)

Best
Bhargava

@inferno-chromium
Copy link

@pwnall - can you please take another look.

@bshastry
Copy link
Contributor Author

Ping :-)

@bshastry
Copy link
Contributor Author

bshastry commented Dec 6, 2019

Rebased.

@Dor1s
Copy link

Dor1s commented Dec 6, 2019

@pwnall could you please take a look?

Copy link
Contributor Author

@bshastry bshastry left a comment

Choose a reason for hiding this comment

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

Annotated PR with my notes.

option(SNAPPY_OSSFUZZ_BUILD "Build Snappy for oss-fuzz." OFF)

set(SNAPPY_FUZZING_FLAGS "-fsanitize=address" CACHE STRING
"Compiler flags for fuzzing (e.g., -fsanitize=address).")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

SNAPPY_FUZZING_FLAGS are used for the CI fuzzer build.

@@ -45,6 +45,11 @@ option(SNAPPY_BUILD_TESTS "Build Snappy's own tests." ON)

option(SNAPPY_FUZZING_BUILD "Build Snappy for fuzzing." OFF)

option(SNAPPY_OSSFUZZ_BUILD "Build Snappy for oss-fuzz." OFF)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

message(WARNING "Fuzzing builds are only supported with Clang")
endif (NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
endif(NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Warn if either the CI fuzzing build or the ossfuzz build is not being compiled via clang

if(NOT DEFINED ENV{LIB_FUZZING_ENGINE})
message(SEND_ERROR "OSS-Fuzz builds require LIB_FUZZING_ENGINE to be set")
endif(NOT DEFINED ENV{LIB_FUZZING_ENGINE})
endif(SNAPPY_OSSFUZZ_BUILD)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Error if the ossfuzz build has not defined LIB_FUZZING_ENGINE environment variable.

if(NOT CMAKE_CXX_FLAGS MATCHES "${SNAPPY_FUZZING_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SNAPPY_FUZZING_FLAGS}")
endif(NOT CMAKE_CXX_FLAGS MATCHES "${SNAPPY_FUZZING_FLAGS}")
endif(SNAPPY_FUZZING_BUILD)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Append fuzzing related compiler flags for the CI fuzzing build

if(DEFINED ENV{LIB_FUZZING_ENGINE})
set_target_properties(snappy_compress_fuzzer
PROPERTIES LINK_FLAGS $ENV{LIB_FUZZING_ENGINE}
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Link against LIB_FUZZING_ENGINE for the ossfuzz build

else()
set_target_properties(snappy_compress_fuzzer
PROPERTIES LINK_FLAGS "-fsanitize=fuzzer"
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Link against libfuzzer for the CI fuzzing build

if(DEFINED ENV{LIB_FUZZING_ENGINE})
set_target_properties(snappy_uncompress_fuzzer
PROPERTIES LINK_FLAGS $ENV{LIB_FUZZING_ENGINE}
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same here and below

@bshastry
Copy link
Contributor Author

Rebased.

@bshastry
Copy link
Contributor Author

Friendly reminder that this PR is pending another round of reviews :-)

@bshastry
Copy link
Contributor Author

bshastry commented Apr 3, 2020

Friendly reminder that this PR is pending review CC @inferno-chromium :-)

This PR blocks google/oss-fuzz#2874

@bshastry
Copy link
Contributor Author

bshastry commented Jan 4, 2021

I think this PR may be closed now since integration is complete?

@bshastry
Copy link
Contributor Author

Closing due to complete integration

@bshastry bshastry closed this Jan 23, 2021
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.

None yet

5 participants