From c85587ada2359cefef9ac20656e35bc8bff23d04 Mon Sep 17 00:00:00 2001 From: Romain Malmain Date: Mon, 22 Apr 2024 23:03:38 +0200 Subject: [PATCH 1/6] Checkout before filter --- .github/workflows/build_and_test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index e0cba65abf..4561090d87 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -368,6 +368,7 @@ jobs: outputs: qemu: ${{ steps.filter.outputs.qemu }} steps: + - uses: actions/checkout@v3 - uses: dorny/paths-filter@v3 id: filter with: From f3c20468549b6376b087a3c1c6930f7526195d1b Mon Sep 17 00:00:00 2001 From: Romain Malmain Date: Wed, 24 Apr 2024 10:54:17 +0200 Subject: [PATCH 2/6] Refactoring --- libafl/src/executors/inprocess/mod.rs | 2 +- libafl_qemu/libafl_qemu_sys/src/lib.rs | 4 +- libafl_qemu/src/{ => arch}/aarch64.rs | 2 +- libafl_qemu/src/{ => arch}/arm.rs | 2 +- libafl_qemu/src/{ => arch}/hexagon.rs | 2 +- libafl_qemu/src/{ => arch}/i386.rs | 2 +- libafl_qemu/src/{ => arch}/mips.rs | 2 +- libafl_qemu/src/arch/mod.rs | 34 +++++++++ libafl_qemu/src/{ => arch}/ppc.rs | 2 +- libafl_qemu/src/{ => arch}/x86_64.rs | 2 +- libafl_qemu/src/command.rs | 2 +- libafl_qemu/src/{emu.rs => emu/mod.rs} | 2 +- libafl_qemu/src/emu/usermode.rs | 2 +- libafl_qemu/src/executor/mod.rs | 2 +- libafl_qemu/src/executor/stateful.rs | 2 +- libafl_qemu/src/{ => helpers}/asan.rs | 7 +- libafl_qemu/src/{ => helpers}/asan_guest.rs | 2 +- libafl_qemu/src/{ => helpers}/calls.rs | 2 +- libafl_qemu/src/{ => helpers}/cmplog.rs | 2 +- libafl_qemu/src/{ => helpers}/drcov.rs | 0 libafl_qemu/src/{ => helpers}/edges.rs | 2 +- libafl_qemu/src/{ => helpers}/injections.rs | 0 libafl_qemu/src/{helper.rs => helpers/mod.rs} | 31 ++++++++ libafl_qemu/src/{ => helpers}/snapshot.rs | 2 +- libafl_qemu/src/hooks.rs | 2 +- libafl_qemu/src/lib.rs | 76 ++----------------- .../src/{sync_backdoor.rs => sync_exit.rs} | 0 27 files changed, 95 insertions(+), 95 deletions(-) rename libafl_qemu/src/{ => arch}/aarch64.rs (98%) rename libafl_qemu/src/{ => arch}/arm.rs (98%) rename libafl_qemu/src/{ => arch}/hexagon.rs (98%) rename libafl_qemu/src/{ => arch}/i386.rs (98%) rename libafl_qemu/src/{ => arch}/mips.rs (98%) create mode 100644 libafl_qemu/src/arch/mod.rs rename libafl_qemu/src/{ => arch}/ppc.rs (98%) rename libafl_qemu/src/{ => arch}/x86_64.rs (98%) rename libafl_qemu/src/{emu.rs => emu/mod.rs} (99%) rename libafl_qemu/src/{ => helpers}/asan.rs (99%) rename libafl_qemu/src/{ => helpers}/asan_guest.rs (99%) rename libafl_qemu/src/{ => helpers}/calls.rs (99%) rename libafl_qemu/src/{ => helpers}/cmplog.rs (99%) rename libafl_qemu/src/{ => helpers}/drcov.rs (100%) rename libafl_qemu/src/{ => helpers}/edges.rs (99%) rename libafl_qemu/src/{ => helpers}/injections.rs (100%) rename libafl_qemu/src/{helper.rs => helpers/mod.rs} (86%) rename libafl_qemu/src/{ => helpers}/snapshot.rs (99%) rename libafl_qemu/src/{sync_backdoor.rs => sync_exit.rs} (100%) diff --git a/libafl/src/executors/inprocess/mod.rs b/libafl/src/executors/inprocess/mod.rs index aa409c0189..87d07acf8e 100644 --- a/libafl/src/executors/inprocess/mod.rs +++ b/libafl/src/executors/inprocess/mod.rs @@ -134,7 +134,7 @@ where } self.inner.hooks.pre_exec_all(state, input); - let ret = (self.harness_fn.borrow_mut())(input); + let ret = self.harness_fn.borrow_mut()(input); self.inner.hooks.post_exec_all(state, input); self.inner.leave_target(fuzzer, state, mgr, input); diff --git a/libafl_qemu/libafl_qemu_sys/src/lib.rs b/libafl_qemu/libafl_qemu_sys/src/lib.rs index 945777745e..e8ce35b4aa 100644 --- a/libafl_qemu/libafl_qemu_sys/src/lib.rs +++ b/libafl_qemu/libafl_qemu_sys/src/lib.rs @@ -17,6 +17,8 @@ __Warning__: The documentation is built by default for `x86_64` in `usermode`. T mod bindings { include!(concat!(env!("OUT_DIR"), "/bindings.rs")); } +#[cfg(all(not(feature = "clippy"), target_os = "linux"))] +pub use bindings::*; #[cfg(any(feature = "clippy", not(target_os = "linux")))] mod x86_64_stub_bindings; @@ -100,8 +102,6 @@ macro_rules! extern_c_checked { use core::ops::BitAnd; use std::ffi::c_void; -#[cfg(all(not(feature = "clippy"), target_os = "linux"))] -pub use bindings::*; #[cfg(feature = "python")] use pyo3::{pyclass, pymethods, IntoPy, PyObject, Python}; #[cfg(any(feature = "clippy", not(target_os = "linux")))] diff --git a/libafl_qemu/src/aarch64.rs b/libafl_qemu/src/arch/aarch64.rs similarity index 98% rename from libafl_qemu/src/aarch64.rs rename to libafl_qemu/src/arch/aarch64.rs index 3793146d4a..023cb34da5 100644 --- a/libafl_qemu/src/aarch64.rs +++ b/libafl_qemu/src/arch/aarch64.rs @@ -8,7 +8,7 @@ use pyo3::prelude::*; pub use strum_macros::EnumIter; pub use syscall_numbers::aarch64::*; -use crate::{sync_backdoor::BackdoorArgs, CallingConvention}; +use crate::{sync_exit::BackdoorArgs, CallingConvention}; #[derive(IntoPrimitive, TryFromPrimitive, Debug, Clone, Copy, EnumIter)] #[repr(i32)] diff --git a/libafl_qemu/src/arm.rs b/libafl_qemu/src/arch/arm.rs similarity index 98% rename from libafl_qemu/src/arm.rs rename to libafl_qemu/src/arch/arm.rs index fcdf9b1a06..42b6d8d24f 100644 --- a/libafl_qemu/src/arm.rs +++ b/libafl_qemu/src/arch/arm.rs @@ -8,7 +8,7 @@ use pyo3::prelude::*; pub use strum_macros::EnumIter; pub use syscall_numbers::arm::*; -use crate::{sync_backdoor::BackdoorArgs, CallingConvention}; +use crate::{sync_exit::BackdoorArgs, CallingConvention}; /// Registers for the ARM instruction set. #[derive(IntoPrimitive, TryFromPrimitive, Debug, Clone, Copy, EnumIter)] diff --git a/libafl_qemu/src/hexagon.rs b/libafl_qemu/src/arch/hexagon.rs similarity index 98% rename from libafl_qemu/src/hexagon.rs rename to libafl_qemu/src/arch/hexagon.rs index d931876034..bd4ff32cd9 100644 --- a/libafl_qemu/src/hexagon.rs +++ b/libafl_qemu/src/arch/hexagon.rs @@ -6,7 +6,7 @@ use num_enum::{IntoPrimitive, TryFromPrimitive}; use pyo3::prelude::*; pub use strum_macros::EnumIter; -use crate::{sync_backdoor::BackdoorArgs, CallingConvention}; +use crate::{sync_exit::BackdoorArgs, CallingConvention}; #[derive(IntoPrimitive, TryFromPrimitive, Debug, Clone, Copy, EnumIter)] #[repr(i32)] diff --git a/libafl_qemu/src/i386.rs b/libafl_qemu/src/arch/i386.rs similarity index 98% rename from libafl_qemu/src/i386.rs rename to libafl_qemu/src/arch/i386.rs index d70578987a..ca91b8ddf6 100644 --- a/libafl_qemu/src/i386.rs +++ b/libafl_qemu/src/arch/i386.rs @@ -8,7 +8,7 @@ use pyo3::prelude::*; pub use strum_macros::EnumIter; pub use syscall_numbers::x86::*; -use crate::{sync_backdoor::BackdoorArgs, CallingConvention, GuestAddr}; +use crate::{sync_exit::BackdoorArgs, CallingConvention, GuestAddr}; #[derive(IntoPrimitive, TryFromPrimitive, Debug, Clone, Copy, EnumIter)] #[repr(i32)] diff --git a/libafl_qemu/src/mips.rs b/libafl_qemu/src/arch/mips.rs similarity index 98% rename from libafl_qemu/src/mips.rs rename to libafl_qemu/src/arch/mips.rs index 96b464d9fd..4810b33508 100644 --- a/libafl_qemu/src/mips.rs +++ b/libafl_qemu/src/arch/mips.rs @@ -7,7 +7,7 @@ use pyo3::prelude::*; pub use strum_macros::EnumIter; pub use syscall_numbers::mips::*; -use crate::{sync_backdoor::BackdoorArgs, CallingConvention}; +use crate::{sync_exit::BackdoorArgs, CallingConvention}; /// Registers for the MIPS instruction set. #[derive(IntoPrimitive, TryFromPrimitive, Debug, Clone, Copy, EnumIter)] diff --git a/libafl_qemu/src/arch/mod.rs b/libafl_qemu/src/arch/mod.rs new file mode 100644 index 0000000000..ff95a150be --- /dev/null +++ b/libafl_qemu/src/arch/mod.rs @@ -0,0 +1,34 @@ +#[cfg(cpu_target = "aarch64")] +pub mod aarch64; +#[cfg(all(cpu_target = "aarch64", not(feature = "clippy")))] +pub use aarch64::*; + +#[cfg(cpu_target = "arm")] +pub mod arm; +#[cfg(all(cpu_target = "arm", not(feature = "clippy")))] +pub use arm::*; + +#[cfg(cpu_target = "i386")] +pub mod i386; +#[cfg(all(cpu_target = "i386", not(feature = "clippy")))] +pub use i386::*; + +#[cfg(cpu_target = "x86_64")] +pub mod x86_64; +#[cfg(cpu_target = "x86_64")] +pub use x86_64::*; + +#[cfg(cpu_target = "mips")] +pub mod mips; +#[cfg(cpu_target = "mips")] +pub use mips::*; + +#[cfg(cpu_target = "ppc")] +pub mod ppc; +#[cfg(cpu_target = "ppc")] +pub use ppc::*; + +#[cfg(cpu_target = "hexagon")] +pub mod hexagon; +#[cfg(cpu_target = "hexagon")] +pub use hexagon::*; diff --git a/libafl_qemu/src/ppc.rs b/libafl_qemu/src/arch/ppc.rs similarity index 98% rename from libafl_qemu/src/ppc.rs rename to libafl_qemu/src/arch/ppc.rs index 9fdd4def74..53dd4c1a91 100644 --- a/libafl_qemu/src/ppc.rs +++ b/libafl_qemu/src/arch/ppc.rs @@ -7,7 +7,7 @@ use pyo3::prelude::*; pub use strum_macros::EnumIter; pub use syscall_numbers::powerpc::*; -use crate::{sync_backdoor::BackdoorArgs, CallingConvention}; +use crate::{sync_exit::BackdoorArgs, CallingConvention}; /// Registers for the MIPS instruction set. #[derive(IntoPrimitive, TryFromPrimitive, Debug, Clone, Copy, EnumIter)] diff --git a/libafl_qemu/src/x86_64.rs b/libafl_qemu/src/arch/x86_64.rs similarity index 98% rename from libafl_qemu/src/x86_64.rs rename to libafl_qemu/src/arch/x86_64.rs index d6ac5aac0d..bdeddc0f75 100644 --- a/libafl_qemu/src/x86_64.rs +++ b/libafl_qemu/src/arch/x86_64.rs @@ -8,7 +8,7 @@ use pyo3::prelude::*; pub use strum_macros::EnumIter; pub use syscall_numbers::x86_64::*; -use crate::{sync_backdoor::BackdoorArgs, CallingConvention}; +use crate::{sync_exit::BackdoorArgs, CallingConvention}; #[derive(IntoPrimitive, TryFromPrimitive, Debug, Clone, Copy, EnumIter)] #[repr(i32)] diff --git a/libafl_qemu/src/command.rs b/libafl_qemu/src/command.rs index c3b4e46a82..a064b93a6f 100644 --- a/libafl_qemu/src/command.rs +++ b/libafl_qemu/src/command.rs @@ -15,7 +15,7 @@ use num_enum::TryFromPrimitive; #[cfg(emulation_mode = "systemmode")] use crate::QemuInstrumentationPagingFilter; use crate::{ - executor::QemuExecutorState, sync_backdoor::SyncBackdoorError, EmuExitHandler, Emulator, + executor::QemuExecutorState, sync_exit::SyncBackdoorError, EmuExitHandler, Emulator, GuestAddrKind, GuestReg, HandlerError, HasInstrumentationFilter, InnerHandlerResult, IsFilter, IsSnapshotManager, Qemu, QemuHelperTuple, QemuInstrumentationAddressRangeFilter, Regs, StdEmuExitHandler, StdInstrumentationFilter, CPU, diff --git a/libafl_qemu/src/emu.rs b/libafl_qemu/src/emu/mod.rs similarity index 99% rename from libafl_qemu/src/emu.rs rename to libafl_qemu/src/emu/mod.rs index 7a0a5bacc8..103682c9d2 100644 --- a/libafl_qemu/src/emu.rs +++ b/libafl_qemu/src/emu/mod.rs @@ -360,7 +360,7 @@ pub const SKIP_EXEC_HOOK: u64 = u64::MAX; pub use libafl_qemu_sys::{CPUArchState, CPUState}; -use crate::sync_backdoor::{SyncBackdoor, SyncBackdoorError}; +use crate::sync_exit::{SyncBackdoor, SyncBackdoorError}; // syshook_ret #[repr(C)] diff --git a/libafl_qemu/src/emu/usermode.rs b/libafl_qemu/src/emu/usermode.rs index 241bcd28d5..8cf18bb927 100644 --- a/libafl_qemu/src/emu/usermode.rs +++ b/libafl_qemu/src/emu/usermode.rs @@ -13,7 +13,7 @@ use pyo3::prelude::*; use crate::{ emu::{HasExecutions, State}, - sync_backdoor::SyncBackdoorError, + sync_exit::SyncBackdoorError, EmuExitHandler, Emulator, HookData, NewThreadHookId, PostSyscallHookId, PreSyscallHookId, Qemu, QemuExitReason, QemuExitReasonError, QemuHelperTuple, SyscallHookResult, CPU, }; diff --git a/libafl_qemu/src/executor/mod.rs b/libafl_qemu/src/executor/mod.rs index 7055ff35f2..efb402d2fa 100644 --- a/libafl_qemu/src/executor/mod.rs +++ b/libafl_qemu/src/executor/mod.rs @@ -26,7 +26,7 @@ use libafl_bolts::os::unix_signals::{siginfo_t, ucontext_t, Signal}; #[cfg(feature = "fork")] use libafl_bolts::shmem::ShMemProvider; -use crate::{helper::QemuHelperTuple, hooks::QemuHooks, Qemu}; +use crate::{helpers::QemuHelperTuple, hooks::QemuHooks, Qemu}; /// A version of `QemuExecutor` with a state accessible from the harness. pub mod stateful; diff --git a/libafl_qemu/src/executor/stateful.rs b/libafl_qemu/src/executor/stateful.rs index 71dccaee8a..b6413eba71 100644 --- a/libafl_qemu/src/executor/stateful.rs +++ b/libafl_qemu/src/executor/stateful.rs @@ -22,7 +22,7 @@ use libafl::{ use crate::executor::inproc_qemu_crash_handler; #[cfg(emulation_mode = "systemmode")] use crate::executor::{inproc_qemu_timeout_handler, BREAK_ON_TMOUT}; -use crate::{executor::QemuExecutorState, helper::QemuHelperTuple, hooks::QemuHooks, Qemu}; +use crate::{executor::QemuExecutorState, helpers::QemuHelperTuple, hooks::QemuHooks, Qemu}; pub struct StatefulQemuExecutor<'a, H, OT, QT, S> where diff --git a/libafl_qemu/src/asan.rs b/libafl_qemu/src/helpers/asan.rs similarity index 99% rename from libafl_qemu/src/asan.rs rename to libafl_qemu/src/helpers/asan.rs index a2a9439c13..8faa39c854 100644 --- a/libafl_qemu/src/asan.rs +++ b/libafl_qemu/src/helpers/asan.rs @@ -17,11 +17,10 @@ use num_enum::{IntoPrimitive, TryFromPrimitive}; use rangemap::RangeMap; use crate::{ - calls::FullBacktraceCollector, emu::{EmuError, MemAccessInfo, SyscallHookResult}, - helper::{ - HasInstrumentationFilter, IsFilter, QemuHelper, QemuHelperTuple, - QemuInstrumentationAddressRangeFilter, + helpers::{ + calls::FullBacktraceCollector, HasInstrumentationFilter, IsFilter, QemuHelper, + QemuHelperTuple, QemuInstrumentationAddressRangeFilter, }, hooks::{Hook, QemuHooks}, snapshot::QemuSnapshotHelper, diff --git a/libafl_qemu/src/asan_guest.rs b/libafl_qemu/src/helpers/asan_guest.rs similarity index 99% rename from libafl_qemu/src/asan_guest.rs rename to libafl_qemu/src/helpers/asan_guest.rs index e7850221d1..df08b75f3e 100644 --- a/libafl_qemu/src/asan_guest.rs +++ b/libafl_qemu/src/helpers/asan_guest.rs @@ -13,7 +13,7 @@ use libafl::{inputs::UsesInput, HasMetadata}; use crate::sys::libafl_tcg_gen_asan; use crate::{ emu::{EmuError, MemAccessInfo, Qemu}, - helper::{ + helpers::{ HasInstrumentationFilter, IsFilter, QemuHelper, QemuHelperTuple, QemuInstrumentationAddressRangeFilter, }, diff --git a/libafl_qemu/src/calls.rs b/libafl_qemu/src/helpers/calls.rs similarity index 99% rename from libafl_qemu/src/calls.rs rename to libafl_qemu/src/helpers/calls.rs index 9cc87f7d77..b0fa7b1876 100644 --- a/libafl_qemu/src/calls.rs +++ b/libafl_qemu/src/helpers/calls.rs @@ -13,7 +13,7 @@ use thread_local::ThreadLocal; use crate::{ capstone, emu::ArchExtras, - helper::{ + helpers::{ HasInstrumentationFilter, IsFilter, QemuHelper, QemuHelperTuple, QemuInstrumentationAddressRangeFilter, }, diff --git a/libafl_qemu/src/cmplog.rs b/libafl_qemu/src/helpers/cmplog.rs similarity index 99% rename from libafl_qemu/src/cmplog.rs rename to libafl_qemu/src/helpers/cmplog.rs index 8c4a89904c..10290dea95 100644 --- a/libafl_qemu/src/cmplog.rs +++ b/libafl_qemu/src/helpers/cmplog.rs @@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize}; #[cfg(emulation_mode = "usermode")] use crate::{capstone, emu::ArchExtras, CallingConvention, Qemu}; use crate::{ - helper::{ + helpers::{ hash_me, HasInstrumentationFilter, IsFilter, QemuHelper, QemuHelperTuple, QemuInstrumentationAddressRangeFilter, }, diff --git a/libafl_qemu/src/drcov.rs b/libafl_qemu/src/helpers/drcov.rs similarity index 100% rename from libafl_qemu/src/drcov.rs rename to libafl_qemu/src/helpers/drcov.rs diff --git a/libafl_qemu/src/edges.rs b/libafl_qemu/src/helpers/edges.rs similarity index 99% rename from libafl_qemu/src/edges.rs rename to libafl_qemu/src/helpers/edges.rs index 1b82d504c0..56c4b6a72a 100644 --- a/libafl_qemu/src/edges.rs +++ b/libafl_qemu/src/helpers/edges.rs @@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize}; #[cfg(emulation_mode = "systemmode")] use crate::helper::QemuInstrumentationPagingFilter; use crate::{ - helper::{ + helpers::{ hash_me, HasInstrumentationFilter, QemuHelper, QemuHelperTuple, QemuInstrumentationAddressRangeFilter, }, diff --git a/libafl_qemu/src/injections.rs b/libafl_qemu/src/helpers/injections.rs similarity index 100% rename from libafl_qemu/src/injections.rs rename to libafl_qemu/src/helpers/injections.rs diff --git a/libafl_qemu/src/helper.rs b/libafl_qemu/src/helpers/mod.rs similarity index 86% rename from libafl_qemu/src/helper.rs rename to libafl_qemu/src/helpers/mod.rs index efdee20780..51104f2c3a 100644 --- a/libafl_qemu/src/helper.rs +++ b/libafl_qemu/src/helpers/mod.rs @@ -7,6 +7,37 @@ use libafl_qemu_sys::{GuestAddr, GuestPhysAddr}; use crate::{hooks::QemuHooks, Qemu}; +pub mod edges; +pub use edges::QemuEdgeCoverageHelper; + +pub mod calls; +pub use calls::QemuCallTracerHelper; + +#[cfg(not(any(cpu_target = "mips", cpu_target = "hexagon")))] +pub mod cmplog; +#[cfg(not(any(cpu_target = "mips", cpu_target = "hexagon")))] +pub use cmplog::QemuCmpLogHelper; + +#[cfg(all(emulation_mode = "usermode", feature = "injections"))] +pub mod injections; +#[cfg(all(emulation_mode = "usermode", feature = "injections"))] +pub use injections::QemuInjectionHelper; + +#[cfg(all(emulation_mode = "usermode", not(cpu_target = "hexagon")))] +pub mod snapshot; +#[cfg(all(emulation_mode = "usermode", not(cpu_target = "hexagon")))] +pub use snapshot::QemuSnapshotHelper; + +#[cfg(all(emulation_mode = "usermode", not(cpu_target = "hexagon")))] +pub mod asan; +#[cfg(all(emulation_mode = "usermode", not(cpu_target = "hexagon")))] +pub use asan::{init_qemu_with_asan, QemuAsanHelper}; + +#[cfg(all(emulation_mode = "usermode", not(cpu_target = "hexagon")))] +pub mod asan_guest; +#[cfg(all(emulation_mode = "usermode", not(cpu_target = "hexagon")))] +pub use asan_guest::{init_qemu_with_asan_guest, QemuAsanGuestHelper}; + /// A helper for `libafl_qemu`. // TODO remove 'static when specialization will be stable pub trait QemuHelper: 'static + Debug diff --git a/libafl_qemu/src/snapshot.rs b/libafl_qemu/src/helpers/snapshot.rs similarity index 99% rename from libafl_qemu/src/snapshot.rs rename to libafl_qemu/src/helpers/snapshot.rs index 994ee1831b..3ba592abd2 100644 --- a/libafl_qemu/src/snapshot.rs +++ b/libafl_qemu/src/helpers/snapshot.rs @@ -25,7 +25,7 @@ use crate::SYS_newfstatat; use crate::{ asan::QemuAsanHelper, emu::SyscallHookResult, - helper::{QemuHelper, QemuHelperTuple}, + helpers::{QemuHelper, QemuHelperTuple}, hooks::{Hook, QemuHooks}, Qemu, SYS_fstat, SYS_fstatfs, SYS_futex, SYS_getrandom, SYS_mprotect, SYS_mremap, SYS_munmap, SYS_pread64, SYS_read, SYS_readlinkat, SYS_statfs, diff --git a/libafl_qemu/src/hooks.rs b/libafl_qemu/src/hooks.rs index 604725a625..6b51ddda11 100644 --- a/libafl_qemu/src/hooks.rs +++ b/libafl_qemu/src/hooks.rs @@ -22,7 +22,7 @@ use libafl_qemu_sys::{CPUArchStatePtr, FatPtr, GuestAddr, GuestUsize}; pub use crate::emu::SyscallHookResult; use crate::{ emu::{MemAccessInfo, Qemu, SKIP_EXEC_HOOK}, - helper::QemuHelperTuple, + helpers::QemuHelperTuple, sys::TCGTemp, BackdoorHookId, BlockHookId, CmpHookId, EdgeHookId, HookId, InstructionHookId, ReadHookId, WriteHookId, diff --git a/libafl_qemu/src/lib.rs b/libafl_qemu/src/lib.rs index 9b7f43fa7c..de3ef10c88 100644 --- a/libafl_qemu/src/lib.rs +++ b/libafl_qemu/src/lib.rs @@ -33,81 +33,17 @@ use std::env; pub use libafl_qemu_sys as sys; pub use strum::IntoEnumIterator; -#[cfg(cpu_target = "aarch64")] -pub mod aarch64; -#[cfg(all(cpu_target = "aarch64", not(feature = "clippy")))] -pub use aarch64::*; - -#[cfg(cpu_target = "arm")] -pub mod arm; -#[cfg(all(cpu_target = "arm", not(feature = "clippy")))] -pub use arm::*; - -#[cfg(cpu_target = "i386")] -pub mod i386; -#[cfg(all(cpu_target = "i386", not(feature = "clippy")))] -pub use i386::*; - -#[cfg(cpu_target = "x86_64")] -pub mod x86_64; -#[cfg(cpu_target = "x86_64")] -pub use x86_64::*; - -#[cfg(cpu_target = "mips")] -pub mod mips; -#[cfg(cpu_target = "mips")] -pub use mips::*; - -#[cfg(cpu_target = "ppc")] -pub mod ppc; -#[cfg(cpu_target = "ppc")] -pub use ppc::*; - -#[cfg(cpu_target = "hexagon")] -pub mod hexagon; -#[cfg(cpu_target = "hexagon")] -pub use hexagon::*; +pub mod arch; +pub use arch::*; pub mod elf; -pub mod helper; -pub use helper::*; +pub mod helpers; +pub use helpers::*; + pub mod hooks; pub use hooks::*; -pub mod edges; -pub use edges::QemuEdgeCoverageHelper; - -#[cfg(not(any(cpu_target = "mips", cpu_target = "hexagon")))] -pub mod cmplog; -#[cfg(not(any(cpu_target = "mips", cpu_target = "hexagon")))] -pub use cmplog::QemuCmpLogHelper; - -#[cfg(all(emulation_mode = "usermode", feature = "injections"))] -pub mod injections; -#[cfg(all(emulation_mode = "usermode", feature = "injections"))] -pub use injections::QemuInjectionHelper; - -#[cfg(all(emulation_mode = "usermode", not(cpu_target = "hexagon")))] -pub mod snapshot; -#[cfg(all(emulation_mode = "usermode", not(cpu_target = "hexagon")))] -pub use snapshot::QemuSnapshotHelper; - -#[cfg(all(emulation_mode = "usermode", not(cpu_target = "hexagon")))] -pub mod asan; -#[cfg(all(emulation_mode = "usermode", not(cpu_target = "hexagon")))] -pub use asan::{init_qemu_with_asan, QemuAsanHelper}; - -#[cfg(all(emulation_mode = "usermode", not(cpu_target = "hexagon")))] -pub mod asan_guest; -#[cfg(all(emulation_mode = "usermode", not(cpu_target = "hexagon")))] -pub use asan_guest::{init_qemu_with_asan_guest, QemuAsanGuestHelper}; - -#[cfg(not(cpu_target = "hexagon"))] -pub mod calls; -#[cfg(not(cpu_target = "hexagon"))] -pub mod drcov; - pub mod executor; pub use executor::QemuExecutor; #[cfg(feature = "fork")] @@ -118,7 +54,7 @@ pub use emu::*; pub mod breakpoint; pub mod command; -pub mod sync_backdoor; +pub mod sync_exit; #[must_use] pub fn filter_qemu_args() -> Vec { diff --git a/libafl_qemu/src/sync_backdoor.rs b/libafl_qemu/src/sync_exit.rs similarity index 100% rename from libafl_qemu/src/sync_backdoor.rs rename to libafl_qemu/src/sync_exit.rs From ca553a1f3406479e8fb9bd251780e4cb39933cb3 Mon Sep 17 00:00:00 2001 From: Romain Malmain Date: Wed, 24 Apr 2024 17:46:31 +0200 Subject: [PATCH 3/6] fix hexagon --- libafl_qemu/src/helpers/drcov.rs | 2 +- libafl_qemu/src/helpers/mod.rs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/libafl_qemu/src/helpers/drcov.rs b/libafl_qemu/src/helpers/drcov.rs index 5ff2c70fef..c59cd4eb60 100644 --- a/libafl_qemu/src/helpers/drcov.rs +++ b/libafl_qemu/src/helpers/drcov.rs @@ -8,7 +8,7 @@ use rangemap::RangeMap; use serde::{Deserialize, Serialize}; use crate::{ - helper::{ + helpers::{ HasInstrumentationFilter, IsFilter, QemuHelper, QemuHelperTuple, QemuInstrumentationAddressRangeFilter, }, diff --git a/libafl_qemu/src/helpers/mod.rs b/libafl_qemu/src/helpers/mod.rs index 51104f2c3a..faf7c1bce6 100644 --- a/libafl_qemu/src/helpers/mod.rs +++ b/libafl_qemu/src/helpers/mod.rs @@ -10,9 +10,17 @@ use crate::{hooks::QemuHooks, Qemu}; pub mod edges; pub use edges::QemuEdgeCoverageHelper; +#[cfg(not(cpu_target = "hexagon"))] pub mod calls; +#[cfg(not(cpu_target = "hexagon"))] pub use calls::QemuCallTracerHelper; +#[cfg(not(cpu_target = "hexagon"))] +pub mod drcov; +#[cfg(not(cpu_target = "hexagon"))] +pub use drcov::QemuDrCovHelper; + + #[cfg(not(any(cpu_target = "mips", cpu_target = "hexagon")))] pub mod cmplog; #[cfg(not(any(cpu_target = "mips", cpu_target = "hexagon")))] From 57867c9560bec59c59e2b754826fe09499b65226 Mon Sep 17 00:00:00 2001 From: Romain Malmain Date: Wed, 24 Apr 2024 18:04:37 +0200 Subject: [PATCH 4/6] fix path --- libafl_qemu/src/helpers/edges.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libafl_qemu/src/helpers/edges.rs b/libafl_qemu/src/helpers/edges.rs index 56c4b6a72a..3debbe46a1 100644 --- a/libafl_qemu/src/helpers/edges.rs +++ b/libafl_qemu/src/helpers/edges.rs @@ -12,7 +12,7 @@ pub use libafl_targets::{ use serde::{Deserialize, Serialize}; #[cfg(emulation_mode = "systemmode")] -use crate::helper::QemuInstrumentationPagingFilter; +use crate::helpers::QemuInstrumentationPagingFilter; use crate::{ helpers::{ hash_me, HasInstrumentationFilter, QemuHelper, QemuHelperTuple, From 10446a4c2abf8723e535ecaca7bd96dde0e12d49 Mon Sep 17 00:00:00 2001 From: Romain Malmain Date: Wed, 24 Apr 2024 18:11:58 +0200 Subject: [PATCH 5/6] fmt --- libafl_qemu/src/helpers/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/libafl_qemu/src/helpers/mod.rs b/libafl_qemu/src/helpers/mod.rs index faf7c1bce6..2eaab7b140 100644 --- a/libafl_qemu/src/helpers/mod.rs +++ b/libafl_qemu/src/helpers/mod.rs @@ -20,7 +20,6 @@ pub mod drcov; #[cfg(not(cpu_target = "hexagon"))] pub use drcov::QemuDrCovHelper; - #[cfg(not(any(cpu_target = "mips", cpu_target = "hexagon")))] pub mod cmplog; #[cfg(not(any(cpu_target = "mips", cpu_target = "hexagon")))] From 772d819f576001ddb676f94e0add43d6389d7172 Mon Sep 17 00:00:00 2001 From: Romain Malmain Date: Wed, 24 Apr 2024 21:01:06 +0200 Subject: [PATCH 6/6] wrong import in fuzzer --- fuzzers/qemu_launcher/src/instance.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fuzzers/qemu_launcher/src/instance.rs b/fuzzers/qemu_launcher/src/instance.rs index 935522f459..0ffbb16a03 100644 --- a/fuzzers/qemu_launcher/src/instance.rs +++ b/fuzzers/qemu_launcher/src/instance.rs @@ -40,7 +40,7 @@ use libafl_bolts::{ use libafl_qemu::{ cmplog::CmpLogObserver, edges::{edges_map_mut_slice, MAX_EDGES_NUM}, - helper::QemuHelperTuple, + helpers::QemuHelperTuple, Qemu, QemuExecutor, QemuHooks, }; use typed_builder::TypedBuilder;