Home | History | Annotate | Line # | Download | only in fuzz
      1      1.1  christos libfido2 can be fuzzed using AFL or libFuzzer, with or without
      2      1.1  christos ASAN/MSAN/UBSAN.
      3      1.1  christos 
      4      1.1  christos AFL is more convenient when fuzzing the path from the authenticator to
      5      1.1  christos libfido2 in an existing application. To do so, use preload-snoop.c with a real
      6  1.1.1.3  christos authenticator to obtain an initial corpus, rebuild libfido2 with -DFUZZ=ON, and
      7  1.1.1.2  christos use preload-fuzz.c to read device data from stdin.
      8      1.1  christos 
      9      1.1  christos libFuzzer is better suited for bespoke fuzzers; see fuzz_cred.c, fuzz_credman.c,
     10  1.1.1.3  christos fuzz_assert.c, fuzz_hid.c, and fuzz_mgmt.c for examples. To build these
     11  1.1.1.4  christos harnesses, use -DCMAKE_C_FLAGS=-fsanitize=fuzzer-no-link
     12  1.1.1.4  christos -DFUZZ_LDFLAGS=-fsanitize=fuzzer -DFUZZ=ON.
     13  1.1.1.4  christos 
     14  1.1.1.4  christos If -DFUZZ=ON is enabled, symbols listed in wrapped.sym are wrapped in the
     15  1.1.1.4  christos resulting shared object. The wrapper functions simulate failure according to a
     16  1.1.1.4  christos deterministic RNG and probabilities defined in wrap.c. Harnesses wishing to
     17  1.1.1.4  christos use this functionality should call prng_init() with a seed obtained from the
     18  1.1.1.4  christos corpus. To mutate only the seed part of a libFuzzer harness's corpora,
     19  1.1.1.4  christos use '-reduce_inputs=0 --fido-mutate=seed'.
     20      1.1  christos 
     21      1.1  christos To run under ASAN/MSAN/UBSAN, libfido2 needs to be linked against flavours of
     22      1.1  christos libcbor and OpenSSL built with the respective sanitiser. In order to keep
     23      1.1  christos memory utilisation at a manageable level, you can either enforce limits at
     24  1.1.1.2  christos the OS level (e.g. cgroups on Linux), or patch libcbor with the diff below.
     25  1.1.1.4  christos N.B., the patch below is relative to libcbor 0.10.1.
     26      1.1  christos 
     27      1.1  christos diff --git src/cbor/internal/memory_utils.c src/cbor/internal/memory_utils.c
     28  1.1.1.4  christos index bbea63c..3f7c9af 100644
     29      1.1  christos --- src/cbor/internal/memory_utils.c
     30      1.1  christos +++ src/cbor/internal/memory_utils.c
     31  1.1.1.4  christos @@ -41,7 +41,11 @@ size_t _cbor_safe_signaling_add(size_t a, size_t b) {
     32      1.1  christos  
     33      1.1  christos  void* _cbor_alloc_multiple(size_t item_size, size_t item_count) {
     34      1.1  christos    if (_cbor_safe_to_multiply(item_size, item_count)) {
     35  1.1.1.4  christos -    return _cbor_malloc(item_size * item_count);
     36      1.1  christos +    if (item_count > 1000) {
     37      1.1  christos +      return NULL;
     38  1.1.1.4  christos +    } else {
     39  1.1.1.4  christos +      return _cbor_malloc(item_size * item_count);
     40  1.1.1.4  christos +    }
     41      1.1  christos    } else {
     42      1.1  christos      return NULL;
     43      1.1  christos    }
     44