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