forked from spring-projects/spring-boot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mayhem support Mayhem support Delete jazzer_driver-mayhem.yml
- Loading branch information
1 parent
b7b467c
commit 9147ec0
Showing
7 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
name: Mayhem | ||
on: | ||
push: | ||
pull_request: | ||
workflow_dispatch: | ||
workflow_call: | ||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
jobs: | ||
build: | ||
name: ${{ matrix.os }} shared=${{ matrix.shared }} ${{ matrix.build_type }} | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest] | ||
shared: [false] | ||
build_type: [Release] | ||
include: | ||
- os: ubuntu-latest | ||
triplet: x64-linux | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
submodules: recursive | ||
- name: Log in to the Container registry | ||
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
- name: Build and push Docker image | ||
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc | ||
with: | ||
context: . | ||
file: mayhem/Dockerfile | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
- name: Start analysis | ||
uses: forallsecure/mcode-action@v1 | ||
with: | ||
mayhem-token: ${{ secrets.MAYHEM_TOKEN }} | ||
args: --image ${{ steps.meta.outputs.tags }} --file mayhem/BasicJsonParserFuzzer.mayhemfile | ||
--cmd '/out/jazzer_driver --agent_path=/out/jazzer_agent_deploy.jar --cp=/out/spring-boot.jar:/out/spring-boot-loader.jar:/out/spring-core.jar:/out/spring-boot-starter-web.jar::/out | ||
--target_class=BasicJsonParserFuzzer --jvm_args="-Xmx2048m"' --env JAVA_HOME="/out/open-jdk-17/" | ||
--env LD_LIBRARY_PATH="/out/open-jdk-17/lib/server":/out --libfuzzer True | ||
sarif-output: sarif | ||
- name: Upload SARIF file(s) | ||
uses: github/codeql-action/upload-sarif@v2 | ||
with: | ||
sarif_file: sarif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import com.code_intelligence.jazzer.api.FuzzedDataProvider; | ||
|
||
import org.springframework.boot.json.BasicJsonParser; | ||
import org.springframework.boot.json.JsonParseException; | ||
|
||
public class BasicJsonParserFuzzer { | ||
public static void fuzzerTestOneInput(FuzzedDataProvider data) { | ||
String content = data.consumeRemainingAsString(); | ||
BasicJsonParser parser = new BasicJsonParser(); | ||
try { | ||
parser.parseList(content); | ||
parser.parseMap(content); | ||
} catch (JsonParseException e) { } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
project: PROJECT | ||
target: BasicJsonParserFuzzer | ||
cmds: | ||
- cmd: /out/jazzer_driver --agent_path=/out/jazzer_agent_deploy.jar --cp=/out/spring-boot.jar:/out/spring-boot-loader.jar:/out/spring-core.jar:/out/spring-boot-starter-web.jar::/out --target_class=BasicJsonParserFuzzer --jvm_args="-Xmx2048m" | ||
env: | ||
JAVA_HOME: '"/out/open-jdk-17/"' | ||
LD_LIBRARY_PATH: '"/out/open-jdk-17/lib/server":/out' | ||
timeout: 50 | ||
libfuzzer: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright 2022 Google LLC | ||
# | ||
# 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. | ||
# | ||
################################################################################ | ||
|
||
FROM gcr.io/oss-fuzz-base/base-builder-jvm | ||
|
||
RUN git clone --depth 1 https://github.com/google/fuzzing && mv fuzzing/dictionaries/json.dict $SRC/BasicJsonParserFuzzer.dict && rm -rf fuzzing | ||
|
||
RUN git clone --depth 1 https://github.com/dvyukov/go-fuzz-corpus && zip -j $SRC/BasicJsonParserFuzzer_seed_corpus.zip go-fuzz-corpus/json/corpus/* && rm -rf go-fuzz-corpus | ||
|
||
ARG java_home="/out/open-jdk-17" | ||
|
||
RUN apt update && apt install -y openjdk-17-jdk | ||
ENV JAVA_HOME $java_home | ||
ENV PATH "${java_home}:${PATH}" | ||
ENV JVM_LD_LIBRARY_PATH "$java_home/lib/server" | ||
|
||
COPY . spring-boot | ||
RUN rm -rf spring-boot/mayhem | ||
RUN git clone --depth 1 https://github.com/spring-projects/spring-framework spring-boot/spring-framework | ||
|
||
COPY mayhem/build.sh $SRC/ | ||
COPY mayhem/*Fuzzer.java $SRC/ | ||
WORKDIR $SRC/spring-boot | ||
ENV FUZZING_LANGUAGE=jvm SANITIZER=address FUZZING_ENGINE=libfuzzer | ||
RUN compile | ||
RUN chmod +x /out/jazzer_driver |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/bin/bash -eu | ||
# Copyright 2022 Google LLC | ||
# | ||
# 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. | ||
# | ||
################################################################################ | ||
|
||
mv $SRC/{*.zip,*.dict} $OUT | ||
|
||
cp -r "/usr/lib/jvm/java-17-openjdk-amd64/" "$JAVA_HOME" | ||
|
||
CURRENT_VERSION=$(./gradlew properties --no-daemon --console=plain | sed -nr "s/^version:\ (.*)/\1/p") | ||
|
||
./gradlew publishToMavenLocal -x test -x intTest -i -x asciidoctor -x javadoc -x asciidoctorPdf -x :spring-boot-project:spring-boot-docs:zip -x :spring-boot-project:spring-boot-docs:publishMavenPublicationToMavenLocal | ||
cp "/root/.m2/repository/org/springframework/boot/spring-boot/$CURRENT_VERSION/spring-boot-$CURRENT_VERSION.jar" "$OUT/spring-boot.jar" | ||
cp "/root/.m2/repository/org/springframework/boot/spring-boot-loader/$CURRENT_VERSION/spring-boot-loader-$CURRENT_VERSION.jar" "$OUT/spring-boot-loader.jar" | ||
cp "/root/.m2/repository/org/springframework/boot/spring-boot-starter-web/$CURRENT_VERSION/spring-boot-starter-web-$CURRENT_VERSION.jar" "$OUT/spring-boot-starter-web.jar" | ||
|
||
# Spring core | ||
CURRENT_VERSION=$(./gradlew properties --no-daemon --console=plain --build-file=spring-framework/build.gradle | sed -nr "s/^version:\ (.*)/\1/p") | ||
./gradlew build --build-file=spring-framework/spring-core/spring-core.gradle -x test -x javadoc -x :checkstyleNohttp | ||
cp "spring-framework/spring-core/build/libs/spring-core-$CURRENT_VERSION.jar" "$OUT/spring-core.jar" | ||
|
||
ALL_JARS="spring-boot.jar spring-boot-loader.jar spring-core.jar spring-boot-starter-web.jar" | ||
|
||
# The classpath at build-time includes the project jars in $OUT as well as the | ||
# Jazzer API. | ||
BUILD_CLASSPATH=$(echo $ALL_JARS | xargs printf -- "$OUT/%s:"):$JAZZER_API_PATH | ||
|
||
# All .jar and .class files lie in the same directory as the fuzzer at runtime. | ||
RUNTIME_CLASSPATH=$(echo $ALL_JARS | xargs printf -- "\$this_dir/%s:"):\$this_dir | ||
|
||
for fuzzer in $(find $SRC -name '*Fuzzer.java'); do | ||
fuzzer_basename=$(basename -s .java $fuzzer) | ||
javac -cp $BUILD_CLASSPATH $fuzzer --release 17 | ||
cp $SRC/$fuzzer_basename.class $OUT/ | ||
|
||
# Create an execution wrapper that executes Jazzer with the correct arguments. | ||
echo "#!/bin/sh | ||
# LLVMFuzzerTestOneInput for fuzzer detection. | ||
this_dir=\$(dirname \"\$0\") | ||
JAVA_HOME=\"\$this_dir/open-jdk-17/\" \ | ||
LD_LIBRARY_PATH=\"$JVM_LD_LIBRARY_PATH\":\$this_dir \ | ||
\$this_dir/jazzer_driver --agent_path=\$this_dir/jazzer_agent_deploy.jar \ | ||
--cp=$RUNTIME_CLASSPATH \ | ||
--target_class=$fuzzer_basename \ | ||
--jvm_args=\"-Xmx2048m\" \ | ||
\$@" > $OUT/$fuzzer_basename | ||
chmod u+x $OUT/$fuzzer_basename | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
project: PROJECT | ||
target: jazzer_driver | ||
cmds: | ||
- cmd: /out/jazzer_driver |