-
-
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.
Nyx hypercall API support for LibAFL QEMU (#2801)
* Nyx hypercall API support * fix linux kernel fuzzer * hash_me -> hash_64_fast * fix multiple bug in kernel harness * do not check libmozjpeg's C files format.
- Loading branch information
Showing
53 changed files
with
5,352 additions
and
1,252 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
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
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
obj-m += harness.o | ||
|
||
all: | ||
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules | ||
make -C /lib/modules/$(LINUX_MODULES)/build M=$(PWD) modules | ||
gcc -Wall -Werror -o user user.c | ||
|
||
clean: | ||
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean | ||
rm user | ||
make -C /lib/modules/$(LINUX_MODULES)/build M=$(PWD) clean | ||
rm -f user |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
#!/bin/bash | ||
|
||
LINUX_MODULES=$(pacman -Ql linux-headers | grep -m 1 -E '/usr/lib/modules/[^/]*/' | sed 's|.*/usr/lib/modules/\([^/]*\)/.*|\1|') | ||
export LINUX_MODULES | ||
|
||
cd /setup | ||
make clean | ||
make -j | ||
ls /setup | ||
make -j |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,10 @@ authors = ["Romain Malmain <[email protected]>"] | |
edition = "2021" | ||
|
||
[features] | ||
|
||
## Build and run the target with the Nyx API instead of the built-in LibAFL QEMU API. | ||
nyx = [] | ||
|
||
shared = ["libafl_qemu/shared"] | ||
|
||
[profile.release] | ||
|
@@ -16,15 +20,10 @@ codegen-units = 1 | |
[dependencies] | ||
libafl = { path = "../../../libafl" } | ||
libafl_bolts = { path = "../../../libafl_bolts" } | ||
libafl_qemu = { path = "../../../libafl_qemu", features = [ | ||
"x86_64", | ||
"systemmode", | ||
# "paranoid_debug" | ||
] } | ||
libafl_qemu_sys = { path = "../../../libafl_qemu/libafl_qemu_sys", features = [ | ||
libafl_qemu = { path = "../../../libafl_qemu", default-features = false, features = [ | ||
"x86_64", | ||
"systemmode", | ||
# "paranoid_debug" | ||
# "paranoid_debug", | ||
] } | ||
env_logger = "0.11.5" | ||
libafl_targets = { path = "../../../libafl_targets" } | ||
|
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 |
---|---|---|
@@ -1,12 +1,20 @@ | ||
env_scripts = [''' | ||
#!@duckscript | ||
profile = get_env PROFILE | ||
harness_api = get_env HARNESS_API | ||
if eq ${profile} "dev" | ||
set_env PROFILE_DIR debug | ||
else | ||
set_env PROFILE_DIR ${profile} | ||
end | ||
if eq ${harness_api} "nyx" | ||
set_env FEATURE nyx | ||
else | ||
set_env FEATURE "" | ||
end | ||
''', ''' | ||
#!@duckscript | ||
runs_on_ci = get_env RUN_ON_CI | ||
|
@@ -25,12 +33,12 @@ TARGET_DIR = "${CARGO_MAKE_CRATE_TARGET_DIRECTORY}" | |
LIBAFL_QEMU_CLONE_DIR = { value = "${CARGO_MAKE_CRATE_TARGET_DIRECTORY}/qemu-libafl-bridge", condition = { env_not_set = [ | ||
"LIBAFL_QEMU_DIR", | ||
] } } | ||
|
||
LINUX_BUILDER_URL = "[email protected]:AFLplusplus/linux-qemu-image-builder.git" | ||
LINUX_BUILDER_DIR = { value = "${TARGET_DIR}/linux_builder", condition = { env_not_set = [ | ||
"LINUX_BUILDER_DIR", | ||
] } } | ||
LINUX_BUILDER_OUT = "${LINUX_BUILDER_DIR}/output" | ||
HARNESS_API = { value = "lqemu", condition = { env_not_set = ["HARNESS_API"] } } | ||
|
||
[tasks.target_dir] | ||
condition = { files_not_exist = [ | ||
|
@@ -51,7 +59,22 @@ script = ''' | |
git clone ${LINUX_BUILDER_URL} ${LINUX_BUILDER_DIR} | ||
''' | ||
|
||
[tasks.compile_target] | ||
[tasks.compile_target_nyx] | ||
condition = { env = { "HARNESS_API" = "nyx" } } | ||
dependencies = ["target_dir", "linux_builder_dir"] | ||
command = "clang" | ||
args = [ | ||
"-O0", | ||
"-static", | ||
"${WORKING_DIR}/example/harness_nyx.c", | ||
"-o", | ||
"${TARGET_DIR}/runtime/harness", | ||
"-I", | ||
"${TARGET_DIR}/${PROFILE_DIR}/include", | ||
] | ||
|
||
[tasks.compile_target_native] | ||
condition = { env = { "HARNESS_API" = "lqemu" } } | ||
dependencies = ["target_dir", "linux_builder_dir"] | ||
command = "clang" | ||
args = [ | ||
|
@@ -64,6 +87,9 @@ args = [ | |
"${TARGET_DIR}/${PROFILE_DIR}/include", | ||
] | ||
|
||
[tasks.compile_target] | ||
dependencies = ["compile_target_native", "compile_target_nyx"] | ||
|
||
[tasks.target] | ||
dependencies = ["build", "compile_target"] | ||
script_runner = "@shell" | ||
|
@@ -96,7 +122,15 @@ ${LINUX_BUILDER_DIR}/update.sh | |
[tasks.build] | ||
dependencies = ["target_dir"] | ||
command = "cargo" | ||
args = ["build", "--profile", "${PROFILE}", "--target-dir", "${TARGET_DIR}"] | ||
args = [ | ||
"build", | ||
"--profile", | ||
"${PROFILE}", | ||
"--target-dir", | ||
"${TARGET_DIR}", | ||
"--features", | ||
"${FEATURE}", | ||
] | ||
|
||
[tasks.run] | ||
dependencies = ["build"] | ||
|
@@ -111,15 +145,15 @@ else | |
LIBAFL_QEMU_BIOS_DIR=${LIBAFL_QEMU_CLONE_DIR}/build/qemu-bundle/usr/local/share/qemu | ||
fi | ||
cp ${LINUX_BUILDER_OUT}/OVMF_CODE.fd ${LINUX_BUILDER_OUT}/OVMF_CODE.fd.clone | ||
cp ${LINUX_BUILDER_OUT}/OVMF_VARS.fd ${LINUX_BUILDER_OUT}/OVMF_VARS.fd.clone | ||
cp ${LINUX_BUILDER_OUT}/OVMF_CODE.4m.fd ${LINUX_BUILDER_OUT}/OVMF_CODE.fd.clone | ||
cp ${LINUX_BUILDER_OUT}/OVMF_VARS.4m.fd ${LINUX_BUILDER_OUT}/OVMF_VARS.fd.clone | ||
cp ${LINUX_BUILDER_OUT}/linux.qcow2 ${LINUX_BUILDER_OUT}/linux.qcow2.clone | ||
${TARGET_DIR}/${PROFILE_DIR}/qemu_linux_process \ | ||
-accel tcg \ | ||
-m 4G \ | ||
-drive if=pflash,format=raw,file="${LINUX_BUILDER_OUT}/OVMF_CODE.fd" `# OVMF code pflash` \ | ||
-drive if=pflash,format=raw,file="${LINUX_BUILDER_OUT}/OVMF_VARS.fd" `# OVMF vars pflash` \ | ||
-drive if=pflash,format=raw,file="${LINUX_BUILDER_OUT}/OVMF_CODE.4m.fd" `# OVMF code pflash` \ | ||
-drive if=pflash,format=raw,file="${LINUX_BUILDER_OUT}/OVMF_VARS.4m.fd" `# OVMF vars pflash` \ | ||
-device virtio-scsi-pci,id=scsi0 `# SCSI bus` \ | ||
-device scsi-hd,bus=scsi0.0,drive=disk,id=virtio-disk0,bootindex=1 \ | ||
-blockdev driver=file,filename="${LINUX_BUILDER_OUT}/linux.qcow2",node-name=storage `# Backend file of "disk"` \ | ||
|
Oops, something went wrong.