mirror of
https://boringssl.googlesource.com/boringssl
synced 2026-07-21 14:43:51 +00:00
Simplfy fuzzer build
Instead of having a pair of bespoke build definitions use the standard FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION toggle. We actually originated the idea of a fuzzing-specific build toggle, and then libFuzzer standardized a toggle when we talked to them about what we were doing. The problem is our fuzzer mode toggle substantially changed the TLS stack behavior, such that downstream code would likely go haywire. So we couldn't easily fold into the standard one, and all of BoringSSL's downstream fuzzer builds were messy. Instead, make a few changes: 1. Switch BORINGSSL_UNSAFE_DETERMINISTIC_MODE to FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION. That flag is not expected to cause downstream issues as it just makes the PRNG deterministic. 2. Replace BORINGSSL_UNSAFE_FUZZER_MODE with a runtime toggle that is only available when building with FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION. 3. Instead of the no_fuzzer_mode fuzzers being special corpora for the client and server fuzzers, they're now just separate fuzzerrs and follow the usual naming conventions between fuzzers and their corpora. Update-Note: Downstream fuzzer builds can now be simplified. If the fuzzing infrastructure already builds with FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION, the separate boringssl_fuzz (or whatever) target can be removed. Bug: 42290128 Change-Id: Ia1e479777f366908951e15067c96c9767c229f0a Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/77749 Commit-Queue: David Benjamin <davidben@google.com> Reviewed-by: Bob Beck <bbe@google.com>
This commit is contained in:
committed by
Boringssl LUCI CQ
parent
9ba6410319
commit
56383dabf4
+2
-7
@@ -241,13 +241,8 @@ if(FUZZ)
|
||||
message(FATAL_ERROR "You need Clang ≥ 6.0.0")
|
||||
endif()
|
||||
|
||||
add_definitions(-DBORINGSSL_UNSAFE_DETERMINISTIC_MODE)
|
||||
set(RUNNER_ARGS "-deterministic")
|
||||
|
||||
if(NOT NO_FUZZER_MODE)
|
||||
add_definitions(-DBORINGSSL_UNSAFE_FUZZER_MODE)
|
||||
set(RUNNER_ARGS ${RUNNER_ARGS} "-fuzzer" "-shim-config" "fuzzer_mode.json")
|
||||
endif()
|
||||
add_definitions(-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
|
||||
set(RUNNER_ARGS "-deterministic" "-fuzzer" "-shim-config" "fuzzer_mode.json")
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address,fuzzer-no-link -fsanitize-coverage=edge,indirect-calls")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address,fuzzer-no-link -fsanitize-coverage=edge,indirect-calls")
|
||||
|
||||
+3
-3
@@ -48,11 +48,11 @@ In order to minimise all the corpora, build for fuzzing and run `./fuzz/minimise
|
||||
|
||||
## Fuzzer mode
|
||||
|
||||
When `-DFUZZ=1` is passed into CMake, BoringSSL builds with `BORINGSSL_UNSAFE_FUZZER_MODE` and `BORINGSSL_UNSAFE_DETERMINISTIC_MODE` defined. This modifies the library to be more friendly to fuzzers. If `BORINGSSL_UNSAFE_DETERMINISTIC_MODE` is set, BoringSSL will:
|
||||
When `-DFUZZ=1` is passed into CMake, BoringSSL builds with `FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION` defined. BoringSSL will then:
|
||||
|
||||
* Replace `RAND_bytes` with a deterministic PRNG. Call `RAND_reset_for_fuzzing()` at the start of fuzzers which use `RAND_bytes` to reset the PRNG state.
|
||||
|
||||
Additionally, if `BORINGSSL_UNSAFE_FUZZER_MODE` is set, BoringSSL will:
|
||||
Additionally, if `CRYPTO_set_fuzzer_mode()` is called to enable fuzzer mode, BoringSSL will:
|
||||
|
||||
* Modify the TLS stack to perform all signature checks (CertificateVerify and ServerKeyExchange) and the Finished check, but always act as if the check succeeded.
|
||||
|
||||
@@ -68,7 +68,7 @@ This is to prevent the fuzzer from getting stuck at a cryptographic invariant in
|
||||
|
||||
The `client` and `server` corpora are seeded from the test suite. The test suite has a `-fuzzer` flag which mirrors the fuzzer mode changes above and a `-deterministic` flag which removes all non-determinism on the Go side. Not all tests pass, so `ssl/test/runner/fuzzer_mode.json` contains the necessary suppressions. The `run_tests` target will pass appropriate command-line flags.
|
||||
|
||||
There are separate corpora, `client_corpus_no_fuzzer_mode` and `server_corpus_no_fuzzer_mode`. These are transcripts for fuzzers with only `BORINGSSL_UNSAFE_DETERMINISTIC_MODE` defined. To build in this mode, pass `-DNO_FUZZER_MODE=1` into CMake. This configuration is run in the same way but without `-fuzzer` and `-shim-config` flags.
|
||||
There are separate fuzzers, `client_no_fuzzer_mode` and `server_no_fuzzer_mode`, with fuzzer mode disabled. This configuration is run in the same way but without `-fuzzer` and `-shim-config` flags.
|
||||
|
||||
If both sets of tests pass, refresh the fuzzer corpora with `refresh_ssl_corpora.sh`:
|
||||
|
||||
|
||||
@@ -272,6 +272,7 @@
|
||||
"crypto/evp/sign.cc",
|
||||
"crypto/ex_data.cc",
|
||||
"crypto/fipsmodule/fips_shared_support.cc",
|
||||
"crypto/fuzzer_mode.cc",
|
||||
"crypto/hpke/hpke.cc",
|
||||
"crypto/hrss/hrss.cc",
|
||||
"crypto/kyber/kyber.cc",
|
||||
|
||||
@@ -140,7 +140,7 @@ static void rand_thread_state_free(void *state_in) {
|
||||
}
|
||||
|
||||
#if defined(OPENSSL_X86_64) && !defined(OPENSSL_NO_ASM) && \
|
||||
!defined(BORINGSSL_UNSAFE_DETERMINISTIC_MODE)
|
||||
!defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
|
||||
// rdrand should only be called if either |have_rdrand| or |have_fast_rdrand|
|
||||
// returned true.
|
||||
static int rdrand(uint8_t *buf, const size_t len) {
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
// Copyright 2025 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/crypto.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
#if defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
|
||||
static CRYPTO_atomic_u32 fuzzer_mode_enabled = 0;
|
||||
|
||||
int CRYPTO_fuzzer_mode_enabled(void) {
|
||||
return CRYPTO_atomic_load_u32(&fuzzer_mode_enabled);
|
||||
}
|
||||
|
||||
void CRYPTO_set_fuzzer_mode(int enabled) {
|
||||
CRYPTO_atomic_store_u32(&fuzzer_mode_enabled, !!enabled);
|
||||
}
|
||||
#endif // FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
||||
@@ -1404,6 +1404,7 @@ inline int CRYPTO_is_ARMv8_SHA512_capable(void) {
|
||||
|
||||
#endif // OPENSSL_ARM || OPENSSL_AARCH64
|
||||
|
||||
|
||||
#if defined(BORINGSSL_DISPATCH_TEST)
|
||||
// Runtime CPU dispatch testing support
|
||||
|
||||
@@ -1420,6 +1421,7 @@ inline int CRYPTO_is_ARMv8_SHA512_capable(void) {
|
||||
extern uint8_t BORINGSSL_function_hit[8];
|
||||
#endif // BORINGSSL_DISPATCH_TEST
|
||||
|
||||
|
||||
// OPENSSL_vasprintf_internal is just like |vasprintf(3)|. If |system_malloc| is
|
||||
// 0, memory will be allocated with |OPENSSL_malloc| and must be freed with
|
||||
// |OPENSSL_free|. Otherwise the system |malloc| function is used and the memory
|
||||
@@ -1428,6 +1430,19 @@ OPENSSL_EXPORT int OPENSSL_vasprintf_internal(char **str, const char *format,
|
||||
va_list args, int system_malloc)
|
||||
OPENSSL_PRINTF_FORMAT_FUNC(2, 0);
|
||||
|
||||
|
||||
// Fuzzer mode.
|
||||
|
||||
#if defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
|
||||
// CRYPTO_fuzzer_mode_enabled returns whether fuzzer mode is enabled. See
|
||||
// |CRYPTO_set_fuzzer_mode|. In non-fuzzer builds, this function statically
|
||||
// returns zero so the codepaths will be deleted by the optimizer.
|
||||
int CRYPTO_fuzzer_mode_enabled(void);
|
||||
#else
|
||||
inline int CRYPTO_fuzzer_mode_enabled(void) { return 0; }
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern C
|
||||
#endif
|
||||
|
||||
@@ -135,10 +135,6 @@ TEST(PKCS12Test, TestNoEncryption) {
|
||||
}
|
||||
|
||||
TEST(PKCS12Test, TestEmptyPassword) {
|
||||
#if defined(BORINGSSL_UNSAFE_FUZZER_MODE)
|
||||
return; // The MAC check always passes in fuzzer mode.
|
||||
#endif
|
||||
|
||||
// Generated with
|
||||
// openssl pkcs12 -export -inkey ecdsa_p256_key.pem -in ecdsa_p256_cert.pem -password pass:
|
||||
std::string data = GetTestData("crypto/pkcs8/test/empty_password.p12");
|
||||
@@ -164,10 +160,6 @@ TEST(PKCS12Test, TestEmptyPassword) {
|
||||
}
|
||||
|
||||
TEST(PKCS12Test, TestNullPassword) {
|
||||
#if defined(BORINGSSL_UNSAFE_FUZZER_MODE)
|
||||
return; // The MAC check always passes in fuzzer mode.
|
||||
#endif
|
||||
|
||||
// Generated with
|
||||
// openssl pkcs12 -export -inkey ecdsa_p256_key.pem -in ecdsa_p256_cert.pem -password pass:
|
||||
// But with OpenSSL patched to pass NULL into PKCS12_create and
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
|
||||
|
||||
int pkcs12_iterations_acceptable(uint64_t iterations) {
|
||||
#if defined(BORINGSSL_UNSAFE_FUZZER_MODE)
|
||||
#if defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
|
||||
static const uint64_t kIterationsLimit = 2048;
|
||||
#else
|
||||
// Windows imposes a limit of 600K. Mozilla say: “so them increasing
|
||||
@@ -528,9 +528,9 @@ static int pkcs12_check_mac(int *out_mac_ok, const char *password,
|
||||
}
|
||||
|
||||
*out_mac_ok = CBS_mem_equal(expected_mac, hmac, hmac_len);
|
||||
#if defined(BORINGSSL_UNSAFE_FUZZER_MODE)
|
||||
*out_mac_ok = 1;
|
||||
#endif
|
||||
if (CRYPTO_fuzzer_mode_enabled()) {
|
||||
*out_mac_ok = 1;
|
||||
}
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
#include <openssl/base.h>
|
||||
|
||||
#if defined(BORINGSSL_UNSAFE_DETERMINISTIC_MODE)
|
||||
#if defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
|
||||
#define OPENSSL_RAND_DETERMINISTIC
|
||||
#elif defined(OPENSSL_TRUSTY)
|
||||
#define OPENSSL_RAND_TRUSTY
|
||||
|
||||
@@ -55,7 +55,8 @@ TEST(RandTest, NotObviouslyBroken) {
|
||||
}
|
||||
|
||||
#if !defined(OPENSSL_WINDOWS) && !defined(OPENSSL_IOS) && \
|
||||
!defined(OPENSSL_FUCHSIA) && !defined(BORINGSSL_UNSAFE_DETERMINISTIC_MODE)
|
||||
!defined(OPENSSL_FUCHSIA) && \
|
||||
!defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
|
||||
static bool ForkAndRand(bssl::Span<uint8_t> out, bool fork_unsafe_buffering) {
|
||||
int pipefds[2];
|
||||
if (pipe(pipefds) < 0) {
|
||||
@@ -162,7 +163,7 @@ TEST(RandTest, Fork) {
|
||||
}
|
||||
}
|
||||
#endif // !OPENSSL_WINDOWS && !OPENSSL_IOS &&
|
||||
// !OPENSSL_FUCHSIA && !BORINGSSL_UNSAFE_DETERMINISTIC_MODE
|
||||
// !OPENSSL_FUCHSIA && !FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
||||
|
||||
#if defined(OPENSSL_THREADS)
|
||||
static void RunConcurrentRands(size_t num_threads) {
|
||||
|
||||
+2
-1
@@ -15,7 +15,8 @@
|
||||
#include "../ssl/test/fuzzer.h"
|
||||
|
||||
|
||||
static TLSFuzzer g_fuzzer(TLSFuzzer::kTLS, TLSFuzzer::kClient);
|
||||
static TLSFuzzer g_fuzzer(TLSFuzzer::kTLS, TLSFuzzer::kClient,
|
||||
TLSFuzzer::kFuzzerModeOn);
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
|
||||
return g_fuzzer.TestOneInput(buf, len);
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
// Copyright 2016 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "../ssl/test/fuzzer.h"
|
||||
|
||||
|
||||
static TLSFuzzer g_fuzzer(TLSFuzzer::kTLS, TLSFuzzer::kClient,
|
||||
TLSFuzzer::kFuzzerModeOff);
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
|
||||
return g_fuzzer.TestOneInput(buf, len);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user