Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 091ae62f authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes If71ca8d8,I67b27425 into sc-dev

* changes:
  Added audiopolicy_fuzzer
  Added audioflinger_fuzzer
parents 3be54ca3 253887f7
Loading
Loading
Loading
Loading
+70 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * 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:
 *
 * http://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.
 */

cc_fuzz {
    name: "audioflinger_fuzzer",
    srcs: [
        "audioflinger_fuzzer.cpp",
    ],
    static_libs: [
        "android.hardware.audio.common@7.0-enums",
        "effect-aidl-unstable-cpp",
        "libaudioclient",
        "libbase",
        "libcgrouprc",
        "libcgrouprc_format",
        "libcutils",
        "libjsoncpp",
        "liblog",
        "libmediametrics",
        "libmediametricsservice",
        "libmedia_helper",
        "libprocessgroup",
        "shared-file-region-aidl-unstable-cpp",
    ],
    shared_libs: [
        "android.hardware.audio.common-util",
        "audioclient-types-aidl-unstable-cpp",
        "audioflinger-aidl-unstable-cpp",
        "audiopolicy-aidl-unstable-cpp",
        "audiopolicy-types-aidl-unstable-cpp",
        "av-types-aidl-unstable-cpp",
        "capture_state_listener-aidl-unstable-cpp",
        "libaudioclient_aidl_conversion",
        "libaudioflinger",
        "libaudiofoundation",
        "libaudiomanager",
        "libaudiopolicy",
        "libaudioutils",
        "libbinder",
        "libdl",
        "libmediautils",
        "libnblog",
        "libutils",
        "libxml2",
        "mediametricsservice-aidl-unstable-cpp",
    ],
    header_libs: [
        "libaudiofoundation_headers",
        "libmedia_headers",
    ],
    fuzz_config: {
        cc: [
            "android-media-fuzzing-reports@google.com",
        ],
        componentid: 155276,
    },
}
+80 −0
Original line number Diff line number Diff line
# Fuzzer for libaudioflinger

## Plugin Design Considerations
The fuzzer plugin for libaudioflinger is designed based on the understanding of the
library and tries to achieve the following:

##### Maximize code coverage
The configuration parameters are not hardcoded, but instead selected based on
incoming data. This ensures more code paths are reached by the fuzzer. The fuzzer
covers libaudioflinger APIs as called from libaudioclient through IPC.

libaudioflinger supports the following parameters:
1. Unique IDs (parameter name: `uniqueId`)
2. Audio Mode (parameter name: `mode`)
3. Session ID (parameter name: `sessionId`)
4. Encapsulation Mode (parameter name: `encapsulationMode`)
5. Audio Port Role (parameter name: `portRole`)
6. Audio Port Type (parameter name: `portType`)
7. Audio Stream Type (parameter name: `streamType`)
8. Audio Format (parameter name: `format`)
9. Audio Channel Mask (parameter name: `channelMask`)
10. Usage (parameter name: `usage`)
11. Audio Content Type (parameter name: `contentType`)
12. Input Source (parameter name: `inputSource`)
13. Input Flags (parameter name: `inputFlags`)
14. Output Flags (parameter name: `outputFlags`)
15. Audio Gain Mode (parameter name: `gainMode`)
16. Audio Device (parameter name: `device`)

| Parameter| Valid Values| Configured Value|
|------------- |-------------| ----- |
| `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
| `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|
| `sessionId`   | 0. `AUDIO_SESSION_NONE` 1. `AUDIO_SESSION_OUTPUT_STAGE` 2. `AUDIO_SESSION_DEVICE` | Value obtained from FuzzedDataProvider|
| `encapsulationMode`   | 0. `AUDIO_ENCAPSULATION_MODE_NONE` 1. `AUDIO_ENCAPSULATION_MODE_ELEMENTARY_STREAM` 2. `AUDIO_ENCAPSULATION_MODE_HANDLE` | Value obtained from FuzzedDataProvider|
| `portRole`   | 0. `AUDIO_PORT_ROLE_NONE` 1. `AUDIO_PORT_ROLE_SOURCE` 2. `AUDIO_PORT_ROLE_SINK` | Value obtained from FuzzedDataProvider|
| `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|
| `streamType` | 15 values of type `audio_stream_type_t` | Value chosen from valid values by obtaining index from FuzzedDataProvider |
| `format` | 77 values of type `audio_format_t` | Value chosen from valid values by obtaining index from FuzzedDataProvider |
| `channelMask` | 83 values of type `audio_channel_mask_t` | Value chosen from valid values by obtaining index from FuzzedDataProvider |
| `usage` | 22 values of type `audio_usage_t` | Value chosen from valid values by obtaining index from FuzzedDataProvider |
| `contentType` | 5 values of type `audio_content_type_t` | Value chosen from valid values by obtaining index from FuzzedDataProvider |
| `inputSource` | 14 values of type `audio_source_t` | Value chosen from valid values by obtaining index from FuzzedDataProvider |
| `inputFlags` | 9 values of type `audio_input_flags_t` | Value chosen from valid values by obtaining index from FuzzedDataProvider |
| `outputFlags` | 16 values of type `audio_output_flags_t` | Value chosen from valid values by obtaining index from FuzzedDataProvider |
| `gainMode` | 3 values of type `audio_gain_mode_t` | Value chosen from valid values by obtaining index from FuzzedDataProvider |
| `device` | 66 values of type `audio_devices_t` | Value chosen from valid values by obtaining index from FuzzedDataProvider |

This also ensures that the plugin is always deterministic for any given input.

##### Maximize utilization of input data
The plugin tolerates any kind of input (empty, huge,
malformed, etc) and doesn't `exit()` on any input and thereby increasing the
chance of identifying vulnerabilities.

## Build

This describes steps to build audioflinger_fuzzer binary.

### Android

#### Steps to build
Build the fuzzer
```
  $ mm -j$(nproc) audioflinger_fuzzer
```

#### Steps to run
Create a directory CORPUS_DIR and copy some files to that folder
Push this directory to device.

To run on device
```
  $ adb sync data
  $ adb shell /data/fuzz/arm64/audioflinger_fuzzer/audioflinger_fuzzer CORPUS_DIR
```

## References:
 * http://llvm.org/docs/LibFuzzer.html
 * https://github.co
+730 −0

File added.

Preview size limit exceeded, changes collapsed.

+55 −0
Original line number Diff line number Diff line
/******************************************************************************
 *
 * Copyright (C) 2021 The Android Open Source Project
 *
 * 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:
 *
 * http://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.
 *
 ******************************************************************************/

cc_fuzz {
    name: "audiopolicy_fuzzer",
    srcs: [
        "audiopolicy_fuzzer.cpp",
    ],
    include_dirs: [
        "frameworks/av/services/audiopolicy",
    ],
    shared_libs: [
        "android.hardware.audio.common-util",
        "capture_state_listener-aidl-cpp",
        "libaudioclient",
        "libaudiofoundation",
        "libbase",
        "libcutils",
        "libhidlbase",
        "libdl",
        "liblog",
        "libmedia_helper",
        "libmediametrics",
        "libutils",
        "libxml2",
        "libbinder",
        "libaudiopolicy",
        "libaudiopolicymanagerdefault",
    ],
    static_libs: [
        "android.hardware.audio.common@7.0-enums",
        "libaudiopolicycomponents",
    ],
    header_libs: [
        "libaudiopolicycommon",
        "libaudiopolicyengine_interface_headers",
        "libaudiopolicymanager_interface_headers",
    ],
    data: [":audiopolicyfuzzer_configuration_files"],
}
+63 −0
Original line number Diff line number Diff line
# Fuzzer for libaudiopolicy

## Plugin Design Considerations
The fuzzer plugin for libaudiopolicy is designed based on the
understanding of the service and tries to achieve the following:

##### Maximize code coverage
The configuration parameters are not hardcoded, but instead selected based on
incoming data. This ensures more code paths are reached by the fuzzer.

AudioPolicy APIs contain the following parameters:
1. AudioFormats
2. AudioChannelMasks
3. AudioOutputFlags
4. AudioDevices
5. MixTypes
6. MixRouteFlags
7. SampleRates
8. AudioUsages
9. AudioContentTypes
10. AudioSources
11. AudioFlagMasks
12. AudioPolicyDeviceStates

| Parameter| Valid Input Values| Configured Value|
|------------- |-------------| ----- |
| `AudioFormat` | 77 values of type `audio_format_t` | Value chosen from valid values by obtaining index from FuzzedDataProvider |
| `AudioChannelMask` | 83 values of type `audio_channel_mask_t` | Value chosen from valid values by obtaining index from FuzzedDataProvider |
| `AudioOutputFlag` | 16 values of type `audio_output_flags_t` | Value chosen from valid values by obtaining index from FuzzedDataProvider |
| `AudioDevice`   | `AUDIO_DEVICE_OUT_AUX_DIGITAL`, `AUDIO_DEVICE_OUT_STUB`, `AUDIO_DEVICE_IN_VOICE_CALL`, `AUDIO_DEVICE_IN_AUX_DIGITAL`, `AUDIO_DEVICE_IN_STUB` | Value chosen from valid values by obtaining index from FuzzedDataProvider |
| `MixType`   | `MIX_TYPE_PLAYERS`, `MIX_TYPE_RECORDERS` | Value chosen from valid values by obtaining index from FuzzedDataProvider |
| `MixRouteFlag`   | `MIX_ROUTE_FLAG_RENDER`, `MIX_ROUTE_FLAG_LOOP_BACK`, `MIX_ROUTE_FLAG_LOOP_BACK_AND_RENDER`, `MIX_ROUTE_FLAG_ALL` | Value chosen from valid values by obtaining index from FuzzedDataProvider |
| `SampleRate` | `0` to `UINT32_MAX` | Value obtained from FuzzedDataProvider |
| `AudioUsage` | `AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST`, `AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT`, `AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED`, `AUDIO_USAGE_NOTIFICATION_EVENT` | Value chosen from valid values by obtaining index from FuzzedDataProvider |
| `AudioContentType` | `AUDIO_CONTENT_TYPE_UNKNOWN`, `AUDIO_CONTENT_TYPE_SPEECH`, `AUDIO_CONTENT_TYPE_MUSIC`, `AUDIO_CONTENT_TYPE_MOVIE`, `AUDIO_CONTENT_TYPE_SONIFICATION` | Value chosen from valid values by obtaining index from FuzzedDataProvider |
| `AudioSource` | 14 values of type `audio_source_t` | Value chosen from valid values by obtaining index from FuzzedDataProvider |
| `AudioFlagMask` | 15 values of type `audio_flags_mask_t` | Value chosen from valid values by obtaining index from FuzzedDataProvider |
| `AudioPolicyDeviceStates` | `AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE`, `AUDIO_POLICY_DEVICE_STATE_AVAILABLE`, `AUDIO_POLICY_DEVICE_STATE_CNT` | Value chosen from valid values by obtaining index from FuzzedDataProvider |

This also ensures that the plugin is always deterministic for any given input.

## Build

This describes steps to build audiopolicy_fuzzer binary.

### Android

#### Steps to build
Build the fuzzer
```
  $ mm -j$(nproc) audiopolicy_fuzzer
```

#### Steps to run
To run on device
```
  $ adb sync data
  $ adb shell /data/fuzz/arm64/audiopolicy_fuzzer/audiopolicy_fuzzer
```

## References:
 * http://llvm.org/docs/LibFuzzer.html
 * https://github.com/google/oss-fuzz
Loading