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

Cryptofuzz (differential crypto fuzzing) #2273

Merged
merged 14 commits into from
Apr 18, 2019
Merged

Conversation

guidovranken
Copy link
Contributor

Currently only embeds OpenSSL. More modules like mbed TLS and cppcrypto are implemented but not enabled at this point.

BoringSSL can be easily added by reusing the OpenSSL module, but I haven't contacted them yet.

KDF function fuzzing works but slows the process down a lot. Maybe I can build a separate fuzzer binary for that in the future.

It has so far found 3 minor API bugs in OpenSSL:
openssl/openssl#8567
openssl/openssl#8563
openssl/openssl#8576

If nothing else, this is a good way to fuzz the multitudes of hash/cipher code in OpenSSL. I don't think any other fuzzer is doing that yet (?).

This project generates two fuzzer binaries, one with and the other without assembly language.

Permission to add OpenSSL e-mail addresses to this project was granted in openssl/openssl#6848

@kroeckx @mattcaswell

@guidovranken
Copy link
Contributor Author

David Benjamin acknowledged to me via e-mail to run BoringSSL in this project.

@guidovranken
Copy link
Contributor Author

(LibreSSL people have agreed to this)

@guidovranken
Copy link
Contributor Author

@mattcaswell @kroeckx Do you prefer to fuzz the non-master branches as well?

@Patater Are you interested incorporating mbed TLS in this project? mbed TLS is already supported. There are currently some mismatches between mbed TLS and other modules, which may be due to bugs in my mbed TLS module, or bugs in mbed TLS. Once we resolve that, we can insert mbed TLS into this project.

@Patater
Copy link

Patater commented Apr 10, 2019

Hi @guidovranken

Yes, that's a really nice project. Do you have any bug reports to share so far?

Thanks

@mattcaswell
Copy link

@guidovranken If you do fuzz any other branches I would only do 1.1.1. I don't have a strong view on it.

@guidovranken
Copy link
Contributor Author

@Patater No memory corruption but some differences with other libraries. I will create issues on the mbed TLS bug tracker.
@mattcaswell OK

@kcc Can this get merged? Is anything blocking this?

Copy link
Contributor

@kcc kcc left a comment

Choose a reason for hiding this comment

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

this didn't build for me in the docker:

[100%] Built target openssl
+ cd /src/cryptofuzz/modules/openssl
+ OPENSSL_INCLUDE_PATH=/src/libressl/include
+ OPENSSL_LIBCRYPTO_A_PATH=/src/libressl/build/crypto/libcrypto.a
+ CXXFLAGS='-O1 -fno-omit-frame-pointer -gline-tables-only -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address -fsanitize-address-use-after-scope -fsanitize=fuzzer-no-link -stdlib=libc++ -I /src/cryptofuzz/fuzzing-headers/include -DCRYPTOFUZZ_LIBRESSL'
+ make -B
test /src/libressl/include
clang++ -O1 -fno-omit-frame-pointer -gline-tables-only -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address -fsanitize-address-use-after-scope -fsanitize=fuzzer-no-link -stdlib=libc++ -I /src/cryptofuzz/fuzzing-headers/include -DCRYPTOFUZZ_LIBRESSL -Wall -Wextra -Werror -std=c++17 -I ../../include -I ../../fuzzing-headers/include -I ../../fuzzing-headers/include -DFUZZING_HEADERS_NO_IMPL -I /src/libressl/include -fPIC -c module.cpp -o module.o
module.cpp:1053:15: error: out-of-line definition of 'checkSetIVLength' does not match any declaration in 'cryptofuzz::module::OpenSSL'
bool OpenSSL::checkSetIVLength(const uint64_t cipherType, const EVP_CIPHER* cipher, EVP_CIPHER_CTX* ctx, const size_t inputIvLength) const {

python gen_repository.py

cd $SRC/openssl
git checkout 9efa0ae0b602c1c0e356009a58410a2e8b80201a
Copy link
Contributor

Choose a reason for hiding this comment

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

please explain why in comments.
Also, better to be done in Dockerfile.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do.

@@ -0,0 +1,16 @@
homepage: "https://github.com/guidovranken/cryptofuzz"
primary_contact: "guidovranken@gmail.com"
auto_ccs:
Copy link
Contributor

Choose a reason for hiding this comment

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

just double-checking that everyone in CC agreed to be here.

@guidovranken
Copy link
Contributor Author

Build is now fixed.

@guidovranken
Copy link
Contributor Author

PS:

LibreSSL crashes on the seed corpus due to a bug that is fixed here. LibreSSL's non-BSD build script pulls https://github.com/libressl-portable/openbsd which is a mirror of their CVS repository, and lags behind a couple of days. This is not ideal for oss-fuzz as this will retain the failure status for an unnecessary amount of time. I will later look into whether OpenBSD's CVS can be used directly, but for now I'm content with the current setup.

OpenSSL crashes on the seed corpus on a bug that is now fixed in upstream but because the oss-fuzz project locks to a an older commit to prevent build failure, the fuzzer still crashes. This can be resolved as soon as OpenSSL fixes their build system.


# Compile Cryptofuzz
cd $SRC/cryptofuzz
LIBFUZZER_LINK="-lFuzzingEngine" CXXFLAGS="$CXXFLAGS -I $SRC/openssl/include" make -B -j$(nproc)
Copy link
Contributor

Choose a reason for hiding this comment

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

here and below, please change -lFuzzingEngine to $LIB_FUZZING_ENGINE -- we are trying to switch to using this variable so that we can use some other flags (such as -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.

Done

@kcc
Copy link
Contributor

kcc commented Apr 18, 2019

One more request: this project is unusual for oss-fuzz, the only other likes this is (yours) bignum-fuzzer.
So, may I ask you to add a short README.md describing what it does (don't go deep into details on "how", a link to cryptofuzz is ok).

One thing not immediately obvious from the first glance: is this doing differential fuzzing between the projects (e.g. boringssl vs opensssl), or self-differential fuzzing, or both.

@guidovranken
Copy link
Contributor Author

One more request: this project is unusual for oss-fuzz, the only other likes this is (yours) bignum-fuzzer.
So, may I ask you to add a short README.md describing what it does (don't go deep into details on "how", a link to cryptofuzz is ok).

One thing not immediately obvious from the first glance: is this doing differential fuzzing between the projects (e.g. boringssl vs opensssl), or self-differential fuzzing, or both.

Done

Copy link
Contributor

@kcc kcc left a comment

Choose a reason for hiding this comment

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

This is going to be fun!

@kcc kcc merged commit 7bdfb2b into google:master Apr 18, 2019
@mattcaswell
Copy link

This can be resolved as soon as OpenSSL fixes their build system.

What needs fixing here?

@guidovranken
Copy link
Contributor Author

This can be resolved as soon as OpenSSL fixes their build system.

What needs fixing here?

OSS-Fuzz builds using OpenSSL, like openssl, bignum-fuzzer, tor are failing.
Eg.: https://oss-fuzz-build-logs.storage.googleapis.com/log-fb4f884a-cac6-4646-b5e3-d1f968963bd7.txt

@mattcaswell
Copy link

Oh right. I think that's the issue addressed by openssl/openssl#8778

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.

None yet

4 participants