Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement fuzz testing #97

Merged
merged 1 commit into from
Feb 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
tags
*DS_Store
*.patch
mappings/
NVChip
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ tss-esapi = { version = "2.0.0", optional = true }
bincode = "1.1.4"
structopt = "0.3.5"
derivative = "1.0.3"
arbitrary = { version = "0.4.0", features = ["derive"], optional = true }

[dev-dependencies]
parsec-client-test = { git = "https://github.com/parallaxsecond/parsec-client-test", tag = "0.1.13" }
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ This project uses the following third party crates:
* bincode (MIT)
* structopt (MIT and Apache-2.0)
* derivative (MIT and Apache-2.0)
* arbitrary (MIT and Apache-2.0)
* libfuzzer-sys (MIT, Apache-2.0 and NCSA)
* flexi_logger (MIT and Apache-2.0)
* lazy_static (MIT and Apache-2.0)

This project uses the following third party libraries:
* [Mbed Crypto](https://github.com/ARMmbed/mbed-crypto) (Apache-2.0)
63 changes: 63 additions & 0 deletions fuzz.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env bash

# ------------------------------------------------------------------------------
# Copyright (c) 2020, Arm Limited, All Rights Reserved
# SPDX-License-Identifier: Apache-2.0
#
# 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.
# ------------------------------------------------------------------------------

FUZZ_CONTAINER_NAME=parsec_fuzzer
CLEANUP_CONTAINER_NAME=parsec_fuzzer_cleanup

set -e

if [[ "$1" == "run" ]]
then
# Set up fuzz folder
docker run --rm -v $(pwd):/parsec -w /parsec/fuzz --name $CLEANUP_CONTAINER_NAME parsec/fuzz ./cleanup.sh
# A copy of the config file is used because the file is modified during the run
cp fuzz/config.toml fuzz/run_config.toml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it needed to copy the configuration file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so that you don't have to remove the PKCS11 slot number after each use

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah makes sense! Maybe a comment would help here then


# Build Docker image
docker build fuzz/docker -t parsec/fuzz

# Stop previous container and run fuzzer
docker kill $FUZZ_CONTAINER_NAME || true
sleep 5s
docker run -d --rm -v $(pwd):/parsec -w /parsec/fuzz --name $FUZZ_CONTAINER_NAME parsec/fuzz ./run_fuzz.sh
elif [[ "$1" == "stop" ]]
then
docker kill $FUZZ_CONTAINER_NAME
elif [[ "$1" == "follow" ]]
then
docker logs -f --tail 100 $FUZZ_CONTAINER_NAME
elif [[ "$1" == "clean" ]]
then
# Cleanup is done via Docker because on some systems ACL settings prevent the user who
# created a container from removing the files created by said container. Another one
# is needed to do the cleanup.
docker run -d --rm -v $(pwd):/parsec -w /parsec/fuzz --name $CLEANUP_CONTAINER_NAME parsec/fuzz ./cleanup.sh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cleanup.sh script seems to only have a dependency on the rm command. Do we need to execute it inside the parsec/fuzz container? We could also write the commands directly here and remove the script.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well yes, but no. if you try that on your server, in the parsec account, you'll see why :) when docker runs, it runs as root, so removing new files isn't possible from a non-sudoer account, unless you do something from a container again

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a comment!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the info!

elif [[ "$1" == "erase" ]]
then
docker run -d --rm -v $(pwd):/parsec -w /parsec/fuzz -e "ERASE=true" --name $CLEANUP_CONTAINER_NAME parsec/fuzz ./cleanup.sh
else
echo "usage: ./fuzz.sh [COMMAND]

Commands:
'run' - builds the fuzzing container and runs the fuzzer
'stop' - stops the fuzzing container
'follow' - prints and follows the log output of the fuzzing container
'clean' - clean up the fuzzing environment (does not remove artifacts or the fuzz corpus)
'erase' - fully clean the fuzzing environment - WARNING: this will remove all the results of previous runs"
fi
7 changes: 7 additions & 0 deletions fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

target
corpus
artifacts
*.log
run_config.toml
NVChip
Loading