Skip to content

Commit fc63ff4

Browse files
committed
tutorials/edk2-uefi: use build.sh to create corpus
1 parent 7a28b09 commit fc63ff4

File tree

3 files changed

+38
-16
lines changed

3 files changed

+38
-16
lines changed

docs/src/tutorials/edk2-uefi/building-the-application.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ This Dockerfile will obtain the EDK2 source and compile the BaseTools, then copy
3838

3939
We will want to get our built UEFI application from the container, which we can
4040
do using the `docker cp` command. There are a few files we want to copy, so we'll
41-
use this script `build.sh` to automate the process:
41+
use this script `build.sh` to automate the process.
42+
43+
It will also copy the `tsffs.h` header into the harness sources, copy the minimal boot disk
44+
and create a initial fuzzing corpus to prepare the project.
4245

4346
```sh
4447
#!/bin/bash
@@ -64,6 +67,15 @@ for file_ext in efi map debug; do
6467
done
6568

6669
docker rm -f "${CONTAINER_NAME}"
70+
71+
# ensure corpus
72+
if [ ! -d "${SCRIPT_DIR}/corpus" ]; then
73+
mkdir "${SCRIPT_DIR}/corpus"
74+
curl -L -o "${SCRIPT_DIR}/corpus/0" https://github.com/dvyukov/go-fuzz-corpus/raw/master/x509/certificate/corpus/0
75+
curl -L -o "${SCRIPT_DIR}/corpus/1" https://github.com/dvyukov/go-fuzz-corpus/raw/master/x509/certificate/corpus/1
76+
curl -L -o "${SCRIPT_DIR}/corpus/2" https://github.com/dvyukov/go-fuzz-corpus/raw/master/x509/certificate/corpus/2
77+
curl -L -o "${SCRIPT_DIR}/corpus/3" https://github.com/dvyukov/go-fuzz-corpus/raw/master/x509/certificate/corpus/3
78+
fi
6779
```
6880

6981
The script will build the image, create a container using it, copy the relevant files

docs/src/tutorials/edk2-uefi/configuring-the-fuzzer.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,15 @@ Re-compile the application by running the build script.
7575
7676
## Obtain a Corpus
7777
78-
The fuzzer will take input from the `corpus` directory in the project directory, so
79-
we'll create that directory and add some sample certificate files in DER format as
80-
our input corpus.
81-
82-
```sh
83-
mkdir corpus
84-
curl -L -o corpus/0 https://github.com/dvyukov/go-fuzz-corpus/raw/master/x509/certificate/corpus/0
85-
curl -L -o corpus/1 https://github.com/dvyukov/go-fuzz-corpus/raw/master/x509/certificate/corpus/1
86-
curl -L -o corpus/2 https://github.com/dvyukov/go-fuzz-corpus/raw/master/x509/certificate/corpus/2
87-
curl -L -o corpus/3 https://github.com/dvyukov/go-fuzz-corpus/raw/master/x509/certificate/corpus/3
78+
The fuzzer will take input from the `corpus` directory located under `edk2-uefi`:
79+
80+
```python
81+
@tsffs.corpus_directory = SIM_lookup_file("%simics%/../corpus")
8882
```
8983

84+
In `build.sh` we have already created that directory and added some sample
85+
certificate files in DER format as our input corpus.
86+
9087
## Configuring the Fuzzer
9188

9289
Even though we loaded the fuzzer module, it didn't run previously because we did not
@@ -126,13 +123,17 @@ hangs, and CPU exceptions. we'll enable exceptions 13 for general protection fau
126123
@tsffs.exceptions = [13, 14]
127124
```
128125

129-
We'll tell the fuzzer where to take its corpus and save its solutions. The fuzzer will
130-
take its corpus from the `corpus` directory and save solutions to the `solutions`
131-
directory in the project by default, so this call can be skipped in real usage unless
132-
you want to change the defaults.
126+
By default, TSFFS expects the `corpus` and `solutions` directories to be located within
127+
the Simics project directory.
128+
129+
However, Since our fuzzer is configured to read its corpus from the `../corpus`
130+
directory (relative to the `project` directory), we must explicitly specify the
131+
correct path using the following configuration:
133132

134133
```python
135-
@tsffs.corpus_directory = SIM_lookup_file("%simics%/corpus")
134+
# project/../corpus
135+
@tsffs.corpus_directory = SIM_lookup_file("%simics%/../corpus")
136+
# set solutions directory (default location, explicitly defined for clarity)
136137
@tsffs.solutions_directory = SIM_lookup_file("%simics%/solutions")
137138
```
138139

examples/tutorials/edk2-uefi/build.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,12 @@ for file_ext in efi map debug; do
2626
done
2727

2828
docker rm -f "${CONTAINER_NAME}"
29+
30+
# ensure corpus
31+
if [ ! -d "${SCRIPT_DIR}/corpus" ]; then
32+
mkdir "${SCRIPT_DIR}/corpus"
33+
curl -L -o "${SCRIPT_DIR}/corpus/0" https://github.com/dvyukov/go-fuzz-corpus/raw/master/x509/certificate/corpus/0
34+
curl -L -o "${SCRIPT_DIR}/corpus/1" https://github.com/dvyukov/go-fuzz-corpus/raw/master/x509/certificate/corpus/1
35+
curl -L -o "${SCRIPT_DIR}/corpus/2" https://github.com/dvyukov/go-fuzz-corpus/raw/master/x509/certificate/corpus/2
36+
curl -L -o "${SCRIPT_DIR}/corpus/3" https://github.com/dvyukov/go-fuzz-corpus/raw/master/x509/certificate/corpus/3
37+
fi

0 commit comments

Comments
 (0)