|
| 1 | +//// |
| 2 | + Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + contributor license agreements. See the NOTICE file distributed with |
| 4 | + this work for additional information regarding copyright ownership. |
| 5 | + The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + (the "License"); you may not use this file except in compliance with |
| 7 | + the License. You may obtain a copy of the License at |
| 8 | + |
| 9 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + |
| 11 | + Unless required by applicable law or agreed to in writing, software |
| 12 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + See the License for the specific language governing permissions and |
| 15 | + limitations under the License. |
| 16 | +//// |
| 17 | +
|
| 18 | +Log4j contains fuzz tests implemented using https://github.com/CodeIntelligenceTesting/jazzer[Jazzer]footnote:[ |
| 19 | +We are aware that https://github.com/google/oss-fuzz/discussions/12195[Jazzer is discontinued]. |
| 20 | +Yet it is still the only mature fuzzing framework in Java and https://google.github.io/oss-fuzz/getting-started/new-project-guide/jvm-lang/#jazzer[the recommended library by OSS-Fuzz].]. |
| 21 | +These tests are located in `-fuzz-test` prefixed modules; `log4j-core-fuzz-test`, `log4j-layout-template-json-fuzz-test`, etc. |
| 22 | +
|
| 23 | +[#oss-fuzz] |
| 24 | +== Google OSS-Fuzz |
| 25 | +
|
| 26 | +https://github.com/google/oss-fuzz[OSS-Fuzz] is a Google service that continuously runs fuzz tests of critical F/OSS projects on a beefy cluster and reports its findings (bugs, vulnerabilities, etc.) privately to project maintainers. |
| 27 | +Log4j provides OSS-Fuzz integration with following helpers: |
| 28 | +
|
| 29 | +- https://github.com/google/oss-fuzz/tree/master/projects/log4j2/Dockerfile[Dockerfile] to create a container image for running tests |
| 30 | +- link:oss-fuzz-build.sh[`oss-fuzz-build.sh`] to generate fuzz test runner scripts along with all necessary dependencies |
| 31 | +
|
| 32 | +[#faq] |
| 33 | +== F.A.Q. |
| 34 | +
|
| 35 | +Below we will try to answer some frequently asked questions. |
| 36 | +
|
| 37 | +[#running] |
| 38 | +=== How can I run fuzz tests locally? |
| 39 | +
|
| 40 | +. Clone the OSS-Fuzz repository: |
| 41 | ++ |
| 42 | +[source,bash] |
| 43 | +---- |
| 44 | +git clone --depth 1 https://github.com/google/oss-fuzz google-oss-fuzz && cd $_ |
| 45 | +---- |
| 46 | +
|
| 47 | +. Build the container image: |
| 48 | ++ |
| 49 | +[source,bash] |
| 50 | +---- |
| 51 | +python infra/helper.py build_image log4j2 |
| 52 | +---- |
| 53 | +
|
| 54 | +. Run the container image to build the Log4j project and generate runner scripts along with dependencies: |
| 55 | ++ |
| 56 | +[source,bash] |
| 57 | +---- |
| 58 | +python infra/helper.py build_fuzzers \ |
| 59 | + --sanitizer address --engine libfuzzer --architecture x86_64 \ |
| 60 | + log4j2 |
| 61 | +---- |
| 62 | +
|
| 63 | +. List generated runner scripts: |
| 64 | ++ |
| 65 | +[source,bash] |
| 66 | +---- |
| 67 | +ls -al build/out/log4j2 |
| 68 | +---- |
| 69 | +
|
| 70 | +. Check one of the generated runner scripts: |
| 71 | ++ |
| 72 | +[source,bash] |
| 73 | +---- |
| 74 | +python infra/helper.py check_build \ |
| 75 | + --sanitizer address --engine libfuzzer --architecture x86_64 \ |
| 76 | + log4j2 log4j-core-fuzz-test-PatternLayoutFuzzer |
| 77 | +---- |
| 78 | +
|
| 79 | +. Execute one of the generated runner scripts: |
| 80 | ++ |
| 81 | +[source,bash] |
| 82 | +---- |
| 83 | +python infra/helper.py run_fuzzer \ |
| 84 | + --sanitizer address --engine libfuzzer --architecture x86_64 \ |
| 85 | + log4j2 log4j-core-fuzz-test-PatternLayoutFuzzer |
| 86 | +---- |
| 87 | +
|
| 88 | +[#view] |
| 89 | +=== How can I view fuzzing failures detected by OSS-Fuzz? |
| 90 | +
|
| 91 | +The system running fuzzers registered to OSS-Fuzz is called *ClusterFuzz*, which provides https://oss-fuzz.com/[a web interface] for maintainers to monitor the fuzzing results. |
| 92 | +Tests outputs and <<#reproduce,reproduction>> inputs for failed tests are stored in https://console.cloud.google.com/storage/browser/log4j2-logs.clusterfuzz-external.appspot.com[a Google Cloud Storage bucket]. |
| 93 | +Access to both the web interface and the bucket is restricted, and only allowed to https://github.com/google/oss-fuzz/blob/master/projects/log4j2/project.yaml[those configured for the project]. |
| 94 | +
|
| 95 | +[#reproduce] |
| 96 | +=== How can I reproduce fuzzing failures detected by OSS-Fuzz? |
| 97 | +
|
| 98 | +Download the associated `.testcase` file from https://console.cloud.google.com/storage/browser/log4j2-logs.clusterfuzz-external.appspot.com[the Google Cloud Storage bucket], and run the following command: |
| 99 | +
|
| 100 | +[source,bash] |
| 101 | +---- |
| 102 | +python infra/helper.py reproduce \ |
| 103 | + log4j2 <FUZZ-TARGET-NAME> <TESTCASE-FILE-PATH> |
| 104 | +---- |
| 105 | +
|
| 106 | +Refer to https://google.github.io/oss-fuzz/advanced-topics/reproducing/[the related OSS-Fuzz documentation] for details. |
0 commit comments