Home | History | Annotate | Line # | Download | only in fuzz
README revision 1.1.1.2
      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.2  christos authenticator to obtain an initial corpus, rebuild libfido2 with -DFUZZ=1, 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  christos fuzz_assert.c, and fuzz_mgmt.c for examples. To build these harnesses,
     11      1.1  christos use -DFUZZ=1 -DLIBFUZZER=1.
     12      1.1  christos 
     13      1.1  christos To run under ASAN/MSAN/UBSAN, libfido2 needs to be linked against flavours of
     14      1.1  christos libcbor and OpenSSL built with the respective sanitiser. In order to keep
     15      1.1  christos memory utilisation at a manageable level, you can either enforce limits at
     16  1.1.1.2  christos the OS level (e.g. cgroups on Linux), or patch libcbor with the diff below.
     17      1.1  christos 
     18      1.1  christos diff --git src/cbor/internal/memory_utils.c src/cbor/internal/memory_utils.c
     19      1.1  christos index aa049a2..e294b38 100644
     20      1.1  christos --- src/cbor/internal/memory_utils.c
     21      1.1  christos +++ src/cbor/internal/memory_utils.c
     22      1.1  christos @@ -28,7 +28,10 @@ bool _cbor_safe_to_multiply(size_t a, size_t b) {
     23      1.1  christos  
     24      1.1  christos  void* _cbor_alloc_multiple(size_t item_size, size_t item_count) {
     25      1.1  christos    if (_cbor_safe_to_multiply(item_size, item_count)) {
     26      1.1  christos -    return _CBOR_MALLOC(item_size * item_count);
     27      1.1  christos +    if (item_count > 1000) {
     28      1.1  christos +      return NULL;
     29      1.1  christos +    } else
     30      1.1  christos +      return _CBOR_MALLOC(item_size * item_count);
     31      1.1  christos    } else {
     32      1.1  christos      return NULL;
     33      1.1  christos    }
     34