-
-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add builder and tests for QASAN (#2898)
* Add tests for QASAN from aflplusplus * refactor asan module to use the builder pattern * move injection tests to the new tests directory
- Loading branch information
Showing
19 changed files
with
574 additions
and
245 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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,30 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||
|
||
if [[ ! -x "$QEMU_LAUNCHER" ]]; then | ||
echo "env variable QEMU_LAUNCHER does not point to a valid executable" | ||
echo "QEMU_LAUNCHER should point to qemu_launcher location, but points to ${QEMU_LAUNCHER} instead." | ||
exit 1 | ||
fi | ||
|
||
cd "$SCRIPT_DIR" | ||
|
||
make | ||
|
||
mkdir in || true | ||
|
||
echo aaaaaaaaaa > in/a | ||
|
||
timeout 10s "$QEMU_LAUNCHER" -o out -i in -j ../../injections.toml -v -- ./static >/dev/null 2>fuzz.log || true | ||
if ! grep -Ei "found.*injection" fuzz.log; then | ||
echo "Fuzzer does not generate any testcases or any crashes" | ||
echo "Logs:" | ||
cat fuzz.log | ||
exit 1 | ||
else | ||
echo "Fuzzer is working" | ||
fi | ||
|
||
make clean |
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,7 @@ | ||
all: qasan | ||
|
||
qasan: qasan.c | ||
gcc qasan.c -o qasan | ||
|
||
clean: | ||
rm -rf qasan out stats.txt |
1 change: 1 addition & 0 deletions
1
fuzzers/binary_only/qemu_launcher/tests/qasan/inputs/double_free.txt
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 @@ | ||
D |
1 change: 1 addition & 0 deletions
1
fuzzers/binary_only/qemu_launcher/tests/qasan/inputs/memset.txt
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 @@ | ||
M |
1 change: 1 addition & 0 deletions
1
fuzzers/binary_only/qemu_launcher/tests/qasan/inputs/overflow.txt
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 @@ | ||
O |
1 change: 1 addition & 0 deletions
1
fuzzers/binary_only/qemu_launcher/tests/qasan/inputs/test_limits.txt
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 @@ | ||
T |
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 @@ | ||
A |
1 change: 1 addition & 0 deletions
1
fuzzers/binary_only/qemu_launcher/tests/qasan/inputs/underflow.txt
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 @@ | ||
U |
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,85 @@ | ||
// taken from | ||
// https://github.com/AFLplusplus/AFLplusplus/blob/da2d4d8258d725f79c2daa22bf3b1a59c593e472/frida_mode/test/fasan/test.c | ||
|
||
#include <stdbool.h> | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <stdint.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
|
||
#define UNUSED_PARAMETER(x) (void)(x) | ||
|
||
#define LOG(x) \ | ||
do { \ | ||
char buf[] = x; \ | ||
write(STDOUT_FILENO, buf, sizeof(buf)); \ | ||
\ | ||
} while (false); | ||
|
||
void LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { | ||
char *buf = malloc(10); | ||
|
||
if (buf == NULL) return; | ||
|
||
switch (*data) { | ||
/* Underflow */ | ||
case 'U': | ||
LOG("Underflow\n"); | ||
buf[-1] = '\0'; | ||
free(buf); | ||
break; | ||
/* Overflow */ | ||
case 'O': | ||
LOG("Overflow\n"); | ||
buf[10] = '\0'; | ||
free(buf); | ||
break; | ||
/* Double free */ | ||
case 'D': | ||
LOG("Double free\n"); | ||
free(buf); | ||
free(buf); | ||
break; | ||
/* Use after free */ | ||
case 'A': | ||
LOG("Use after free\n"); | ||
free(buf); | ||
buf[0] = '\0'; | ||
break; | ||
/* Test Limits (OK) */ | ||
case 'T': | ||
LOG("Test-Limits - No Error\n"); | ||
buf[0] = 'A'; | ||
buf[9] = 'I'; | ||
free(buf); | ||
break; | ||
case 'M': | ||
LOG("Memset too many\n"); | ||
memset(buf, '\0', 11); | ||
free(buf); | ||
break; | ||
default: | ||
LOG("Nop - No Error\n"); | ||
break; | ||
} | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
UNUSED_PARAMETER(argc); | ||
UNUSED_PARAMETER(argv); | ||
|
||
char input = '\0'; | ||
|
||
// if (read(STDIN_FILENO, &input, 1) < 0) { | ||
|
||
// LOG("Failed to read stdin\n"); | ||
// return 1; | ||
|
||
// } | ||
|
||
LLVMFuzzerTestOneInput(&input, 1); | ||
|
||
LOG("DONE\n"); | ||
return 0; | ||
} |
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,69 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||
|
||
if [[ ! -x "$QEMU_LAUNCHER" ]]; then | ||
echo "env variable QEMU_LAUNCHER does not point to a valid executable" | ||
echo "QEMU_LAUNCHER should point to qemu_launcher" | ||
exit 1 | ||
fi | ||
|
||
cd "$SCRIPT_DIR" | ||
make | ||
|
||
tests=( | ||
"overflow" | ||
"underflow" | ||
"double_free" | ||
"memset" | ||
"uaf" | ||
"test_limits" | ||
) | ||
|
||
tests_expected=( | ||
"is 0 bytes to the right of the 10-byte chunk" | ||
"is 1 bytes to the left of the 10-byte chunk" | ||
"is 0 bytes inside the 10-byte chunk" | ||
"is 0 bytes to the right of the 10-byte chunk" | ||
"is 0 bytes inside the 10-byte chunk" | ||
"Test-Limits - No Error" | ||
) | ||
|
||
tests_not_expected=( | ||
"dummy" | ||
"dummy" | ||
"dummy" | ||
"dummy" | ||
"dummy" | ||
"Context:" | ||
) | ||
|
||
for i in "${!tests[@]}" | ||
do | ||
test="${tests[i]}" | ||
expected="${tests_expected[i]}" | ||
not_expected="${tests_not_expected[i]}" | ||
|
||
echo "Running $test detection test..." | ||
OUT=$("$QEMU_LAUNCHER" \ | ||
-r "inputs/$test.txt" \ | ||
--input dummy \ | ||
--output out \ | ||
--asan-cores 0 \ | ||
-- qasan 2>&1 | tr -d '\0') | ||
|
||
if ! echo "$OUT" | grep -q "$expected"; then | ||
echo "ERROR: Expected: $expected." | ||
echo "Output is:" | ||
echo "$OUT" | ||
exit 1 | ||
elif echo "$OUT" | grep -q "$not_expected"; then | ||
echo "ERROR: Did not expect: $not_expected." | ||
echo "Output is:" | ||
echo "$OUT" | ||
exit 1 | ||
else | ||
echo "OK." | ||
fi | ||
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
Oops, something went wrong.