1# Fuzzer for libaudioflinger 2 3## Plugin Design Considerations 4The fuzzer plugin for libaudioflinger is designed based on the understanding of the 5library and tries to achieve the following: 6 7##### Maximize code coverage 8The configuration parameters are not hardcoded, but instead selected based on 9incoming data. This ensures more code paths are reached by the fuzzer. The fuzzer 10covers libaudioflinger APIs as called from libaudioclient through IPC. 11 12libaudioflinger supports the following parameters: 131. Unique IDs (parameter name: `uniqueId`) 142. Audio Mode (parameter name: `mode`) 153. Session ID (parameter name: `sessionId`) 164. Encapsulation Mode (parameter name: `encapsulationMode`) 175. Audio Port Role (parameter name: `portRole`) 186. Audio Port Type (parameter name: `portType`) 197. Audio Stream Type (parameter name: `streamType`) 208. Audio Format (parameter name: `format`) 219. Audio Channel Mask (parameter name: `channelMask`) 2210. Usage (parameter name: `usage`) 2311. Audio Content Type (parameter name: `contentType`) 2412. Input Source (parameter name: `inputSource`) 2513. Input Flags (parameter name: `inputFlags`) 2614. Output Flags (parameter name: `outputFlags`) 2715. Audio Gain Mode (parameter name: `gainMode`) 2816. Audio Device (parameter name: `device`) 29 30| Parameter| Valid Values| Configured Value| 31|------------- |-------------| ----- | 32| `uniqueId` | 0. `AUDIO_UNIQUE_ID_USE_UNSPECIFIED` 1. `AUDIO_UNIQUE_ID_USE_SESSION` 2. `AUDIO_UNIQUE_ID_USE_MODULE` 3. `AUDIO_UNIQUE_ID_USE_EFFECT` 4. `AUDIO_UNIQUE_ID_USE_PATCH` 5. `AUDIO_UNIQUE_ID_USE_OUTPUT` 6. `AUDIO_UNIQUE_ID_USE_INPUT` 7. `AUDIO_UNIQUE_ID_USE_CLIENT` 8. `AUDIO_UNIQUE_ID_USE_MAX` | Value obtained from FuzzedDataProvider 33| `mode` | 0.`AUDIO_MODE_INVALID` 1. `AUDIO_MODE_CURRENT` 2. ` AUDIO_MODE_NORMAL` 3. `AUDIO_MODE_RINGTONE` 4. `AUDIO_MODE_IN_CALL` 5. `AUDIO_MODE_IN_COMMUNICATION` 6. `AUDIO_MODE_CALL_SCREEN` | Value obtained from FuzzedDataProvider| 34| `sessionId` | 0. `AUDIO_SESSION_NONE` 1. `AUDIO_SESSION_OUTPUT_STAGE` 2. `AUDIO_SESSION_DEVICE` | Value obtained from FuzzedDataProvider| 35| `encapsulationMode` | 0. `AUDIO_ENCAPSULATION_MODE_NONE` 1. `AUDIO_ENCAPSULATION_MODE_ELEMENTARY_STREAM` 2. `AUDIO_ENCAPSULATION_MODE_HANDLE` | Value obtained from FuzzedDataProvider| 36| `portRole` | 0. `AUDIO_PORT_ROLE_NONE` 1. `AUDIO_PORT_ROLE_SOURCE` 2. `AUDIO_PORT_ROLE_SINK` | Value obtained from FuzzedDataProvider| 37| `portType` | 0. `AUDIO_PORT_TYPE_NONE` 1. `AUDIO_PORT_TYPE_DEVICE` 2. `AUDIO_PORT_TYPE_MIX` 3. `AUDIO_PORT_TYPE_SESSION`| Value obtained from FuzzedDataProvider| 38| `streamType` | 15 values of type `audio_stream_type_t` | Value chosen from valid values by obtaining index from FuzzedDataProvider | 39| `format` | 77 values of type `audio_format_t` | Value chosen from valid values by obtaining index from FuzzedDataProvider | 40| `channelMask` | 83 values of type `audio_channel_mask_t` | Value chosen from valid values by obtaining index from FuzzedDataProvider | 41| `usage` | 22 values of type `audio_usage_t` | Value chosen from valid values by obtaining index from FuzzedDataProvider | 42| `contentType` | 5 values of type `audio_content_type_t` | Value chosen from valid values by obtaining index from FuzzedDataProvider | 43| `inputSource` | 14 values of type `audio_source_t` | Value chosen from valid values by obtaining index from FuzzedDataProvider | 44| `inputFlags` | 9 values of type `audio_input_flags_t` | Value chosen from valid values by obtaining index from FuzzedDataProvider | 45| `outputFlags` | 16 values of type `audio_output_flags_t` | Value chosen from valid values by obtaining index from FuzzedDataProvider | 46| `gainMode` | 3 values of type `audio_gain_mode_t` | Value chosen from valid values by obtaining index from FuzzedDataProvider | 47| `device` | 66 values of type `audio_devices_t` | Value chosen from valid values by obtaining index from FuzzedDataProvider | 48 49This also ensures that the plugin is always deterministic for any given input. 50 51##### Maximize utilization of input data 52The plugin tolerates any kind of input (empty, huge, 53malformed, etc) and doesn't `exit()` on any input and thereby increasing the 54chance of identifying vulnerabilities. 55 56## Build 57 58This describes steps to build audioflinger_fuzzer binary. 59 60### Android 61 62#### Steps to build 63Build the fuzzer 64``` 65 $ mm -j$(nproc) audioflinger_fuzzer 66``` 67 68#### Steps to run 69Create a directory CORPUS_DIR and copy some files to that folder 70Push this directory to device. 71 72To run on device 73``` 74 $ adb sync data 75 $ adb shell /data/fuzz/arm64/audioflinger_fuzzer/audioflinger_fuzzer CORPUS_DIR 76``` 77 78## References: 79 * http://llvm.org/docs/LibFuzzer.html 80 * https://github.co 81