129 Commits

Author SHA1 Message Date
Andrea Fioraldi
bb773a74d1
Update QEMU version (fix #575) (#619) 2022-05-05 13:24:44 +02:00
Andrea Fioraldi
8cb41366ac
Snapshot QEMU mmap_next_start (#558) 2022-03-01 16:04:20 +01:00
Andrea Fioraldi
bf9d2b4c57
Fix snapshots in libafl_qemu (#556)
* afl_exec_sec feature, disabled by default

* Fix snapshots in libafl_qemu

* working memory snapshots
2022-02-28 21:23:20 +01:00
Evan Richter
679eadcc50
Prevent dropping variables in closure hooks (#549) 2022-02-24 10:18:46 +01:00
Andrea Fioraldi
95d3de0f4b
Closure hooks and on thread create hook (#542)
* Closure hooks and on thread create hook

* on thread once hook

* clippy

* fix

* fix
2022-02-21 18:30:02 +01:00
Evan Richter
7150ffc5e6
[libafl_qemu] EasyElf::resolve_symbol return GuestAddr (#540)
Also enforce Linux support at the crate level instead of item by item
2022-02-16 21:34:56 +01:00
Andrea Fioraldi
a03d733cf9
libafl_qemu decouple hooks from the executor and QemuForkExecutor (#528)
* QemuHooks

* option state hooks

* QemuForkExecutor

* enforce no side effects in QemuForkExecutor

* child hooks fixes

* fixes

* qemu_launcher

* examples and fixes

* fix sugar

* clippy

* fmt

* no timeout for fuzzbench_fork_qemu

* Update libafl_qemu/src/hooks.rs

Co-authored-by: Alwin Berger <50980804+alwinber@users.noreply.github.com>

* clippy

Co-authored-by: Alwin Berger <50980804+alwinber@users.noreply.github.com>
2022-02-15 22:11:24 +01:00
Dominik Maier
7dad2153e2
Clippy for Cargo (#532)
* Clippy for Cargo

* clippy fixes

* clippy fixes

* edition

* fix

* wrong self hidden

* fix

* more clippy
2022-02-11 14:34:01 +01:00
Andrea Fioraldi
63d89463a3
Improve libafl_qemu snapshots (#484)
* mprotect

* expose EnumIter

* thread safe mem snapshot

* update qemu hash

* clippy

* child helpers

* fixes

* fix build

* fix dep
2022-02-09 09:40:59 +01:00
Evan Richter
4e3e31df4e
[libafl_qemu] GuestAddr type (#501)
Guest addresses now represented by correct sized integers.

Previously u64 was used to represent guest addresses. This is great for
64-bit targets, but clunky for other architectures. This introduces a
GuestAddr type alias that is defined based on the selected emulation
architecture.

Note: This changes only the user-facing Rust interface. Before
traversing the FFI boundary, all GuestAddrs are sized back to u64.

Another Note: Guest addresses _from_ the FFI boundary are completely
trusted. Values that are too large are truncated to fit into a GuestAddr
using the `as GuestAddr` cast. This may not be ideal, as errors could be
masked. If desired and the performance is ok, a non-breaking update
could change all `as` casts to `.try_into().unwrap()` so that critical
failures in FFI are always checked.
2022-01-28 09:42:23 +01:00
Evan Richter
4a6616bdfe
[libafl_qemu] simplify emu::{read,write}_mem (#496)
Methods read_mem and write_mem now operate on &[u8], not &[T]

The generic T slice interface was prone to various footguns:
* i32 is the default Rust integer type, but buffers are often expected
  to hold u8. This means the following code writes 16 bytes to the
  guest, not 4:

      let buf = [0; 4];
      emu.write_mem(addr, &buf);

* If a buffer of 16-bit or larger integers (&[u64] for example) is
  needed to read/write, the user will need to consider host/guest
  endianness. The byte array methods in std are a good, explicit
  alternative.

  Perhaps libafl_qemu could expose/define "to/from guest endianness"
  helper functions or extension traits using the established cfg flags,
  so that guest endianness is always right by default.

* emu::read_mem causes insta-UB if a user did something like:

      let mut my_bool = false;
      emu.read_mem(addr, &mut my_bool);

  It's less surprising for users to just operate on plain-ol' bytes,
  which they can explicitly transmute if they wish.
2022-01-27 09:05:33 +01:00
Andrea Fioraldi
0223d8a0c6
Implement Grimoire (#487)
* GeneralizedInput

* GeneralizationStage

* generalization finished

* GrimoireExtensionMutator

* grimoire_mutated flag and propore HasTargetBytes

* use alloc

* working baby fuzzer for grimoire

* fmt

* GrimoireRecursiveReplacementMutator

* extend_with_random_generalized

* extend_with_random_generalized

* GrimoireStringReplacementMutator

* GrimoireRandomDeleteMutator

* clippy

* fuzzbench_text

* fix fuzzbench_text
2022-01-25 21:34:10 +01:00
Evan Richter
ab7d16347f
[libafl_qemu] map_fixed and mprotect target memory (#483) 2022-01-20 22:06:26 +01:00
Dominik Maier
ac43997950
Fixed additional new clippy lints for libafl_qemu, libafl_frida (#473)
* clippy for qemu

* getrlimit clippy
2022-01-17 16:24:40 +01:00
Andrea Fioraldi
bca1f392a7
Bump to 0.7.1 (#465)
* bump to 0.7.1

* bump libafl_qemu
2022-01-13 11:32:57 +01:00
Andrea Fioraldi
8870c50ff5 Do not build QEMU when generating docs 2022-01-10 11:27:53 +01:00
Andrea Fioraldi
e6f2f2d0b2 Merge branch 'main' of github.com:AFLplusplus/LibAFL into main 2022-01-07 11:53:54 +01:00
Andrea Fioraldi
181160d80b Clone only one specific commit on libafl_qemu build.rs 2022-01-07 11:53:34 +01:00
Evan Richter
250ec8d1e0
Reduce generics for various Has* traits (#456)
Specifically for Has{Rand,Corpus,Solutions,FeedbackStates}

The Has* family of traits offer getters and get-mut-ers. The previous
implementation had a fully generic return type:

    trait HasX<X: TraitX> {
        get_x(&self) -> &Self::X;
        get_mut_x(&mut self) -> &mut Self::X;
    }

meaning a single type could implement both `HasRand<Romu>` and
`HasRand<XorShift>`. The advantage of having multiple implementations is
not clear at this time, so it vastly simplifies the trait (and its
impls) to bring the return type in the body as an associated type:

    trait HasX {
        type X: TraitX;
        get_x(&self) -> &Self::X;
        get_mut_x(&mut self) -> &mut Self::X;
    }

This comes with the limitation that any type that impls these traits can
only do so once, choosing only one associated type.

* HasRand's only generic parameter (Rand) is now an associated type
* HasCorpus and HasSolutions are now only generic over the Input type
  they store
* HasFeedbackStates generic parameter now associated type
2022-01-06 10:41:02 +01:00
Evan Richter
9f6872ac68
[libafl_qemu] fix i386 Regs values (#444)
The `Regs` enum was defined out of order, leading to incorrect results from `emu.read_reg`. I found the correct ordering defined here: https://github.com/AFLplusplus/qemu-libafl-bridge/blob/master/target/i386/cpu.h#L46-L54
2022-01-03 10:41:29 +01:00
Dominik Maier
af3d321213
Derive debug for all structs in LibAFL (#442)
* documentation, warnings

* fixed docs

* docs

* no_std

* test

* windows

* nautilus docs

* more fixes

* more docs

* nits

* windows clippy

* docs, windows

* nits

* debug all the things

* derive debug for all core library components

* Docu for libafl_targets

* nits

* reordered generics

* add docs to frida, debug

* nits

* fixes

* more docu for frida, nits

* more docu

* more docu

* Sugar docs

* debug for qemu

* more debug

* import debug

* fmt

* debug

* anyap_debug feature no longer needed

* tidy up unused fn

* indicate if we left out values for struct debug

* implement Debug for sugar

* debug allthethings

* ci
2022-01-03 00:47:17 +01:00
Dominik Maier
efc804fe7d
Updated dependencies (#443)
* updated dependencies

* updated info in toml

* Windows fixes

* fixed immport

* u32 -> i32

* ignore i32 overflows in constants

* removed unused double allow
2022-01-02 17:52:44 +01:00
Evan Richter
9f76386668
[libafl_qemu] prevent unneeded build.rs runs (#441)
`libqasan/libqasan.so` never exists during a normal `cargo build` because the .so is built in the target_dir, not in the source directory. This was triggering cargo to rerun the build script every time a user of this library made an incremental change to their code.

pointing `rerun-if-changed` to a directory will make cargo rerun build.rs if any file in that directory changes.
2022-01-02 01:03:35 +01:00
Evan Richter
e47c3be3fd
[libafl_qemu] fix build.rs (#435)
I noticed qemu was only building on one core, so I debugged the jobs environment variable. Evidently cargo passes `CARGO_BUILD_JOBS` is passed to build.rs scripts as `NUM_JOBS`. Other env vars for build.rs can be found [here](https://web.mit.edu/rust-lang_v1.25/arch/amd64_ubuntu1404/share/doc/rust/html/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts)
2021-12-29 01:30:14 +01:00
Andrea Fioraldi
6274ad4594
Refactor libafl_qemu creating the Emulator struct and post syscall hooks (#430)
* working without asan.rs

* working asan

* update fuzzers

* mremap in snapshot

* sugar

* python

* fix python

* clippy

* fmt

* fuck you loader
2021-12-23 09:10:13 +01:00
Andrea Fioraldi
785cddc1f0 Fix meson.build issue updating QEMU git hash 2021-12-21 12:42:41 +01:00
Andrea Fioraldi
208d69342d Update QEMU git hash 2021-12-21 11:35:06 +01:00
Andrea Fioraldi
7c7c7e679f Merge branch 'main' of github.com:AFLplusplus/LibAFL into main 2021-12-08 16:32:36 +01:00
Andrea Fioraldi
5af2b4580e Update pyo3 to 0.15 2021-12-08 16:32:32 +01:00
Dominik Maier
83583a867f
QEMU target arch selector via feature flag (#405)
* QEMU target arch selector via feature flag

* fix ci

* fixing ci some mmore

* more ci fixes, defaulting to x86_64 always

* more ci

* i368 -> i386 typo fix

* revert forkserver changes

* trying to fix clippy

* docs

* fixed warnings

* more clippy action

* qemu example arch

* bring back deprecated function I don't know how to replace

* get rid of deprecated feature again'

* builds?i
2021-12-06 20:06:47 +01:00
Andrea Fioraldi
c3ea7a042c Update QEMU bridge revision hash 2021-12-06 10:04:59 +01:00
Andrea Fioraldi
37b8cb0d2f Bump to 0.7 2021-12-01 17:22:09 +01:00
Andrea Fioraldi
3ccf884d86 Hook cmp on arm/aarch64 in libafl_qemu 2021-11-19 14:37:59 +01:00
Andrea Fioraldi
d2fbc1040e
Qemu fixes and syscalls for every supported arch (#386)
* cpu_target

* report

* track mmap in x64 snapshots

* fixes in libafl_qemu and qemu bridge

* clippy

Co-authored-by: Dominik Maier <domenukk@gmail.com>
2021-11-18 09:33:26 +01:00
Dominik Maier
ba969108e3
Push stage trait (#380)
* rpush mutational trait

* tiny changes

* started PushStageAdapter

* fmt

* refactoring

* fix docs

* no_std

* formatted more
2021-11-17 12:51:14 +01:00
Andrea Fioraldi
fd5e793e57
libafl_qemu cpu_target cfg (#383)
* cpu_target

* report

* track mmap in x64 snapshots
2021-11-17 12:50:10 +01:00
Dominik Maier
4d24012245
Clippy fixes (#385)
* clippy fixes

* added missing use, switched to hashbrown

* fix

* more clippy
2021-11-17 12:49:58 +01:00
Andrea Fioraldi
00d38dc535
AddressSanitizer for libafl_qemu (#378)
* build libqasan

* asan runtime

* working simple asan

* init_with_asan

* fmt

* incomplete instr filter

* harden dealloc

* clippy
2021-11-16 13:53:28 +01:00
Andrea Fioraldi
87677be11d Update QEMU commit in libafl_qemu 2021-11-15 14:10:29 +01:00
Dominik Maier
62afed61e2
Renamed Stats to Monitors (#373)
* renamed stats to monitors

* added depreciation notices

* resorted generics alphaabetically

* added monitors

* fmt fuzzers

* added depreciation note for usermonitor

* fmt all fuzzers script

* more fmt

* renamed some monitor things back to stats

* fixed rename
2021-11-12 11:01:08 +01:00
Dominik Maier
fff7cbd90f
implemented MapMaxPow2Feedback (#371)
* implemented MapMaxPow2Feedback

* using num-traits for qemu as well

* moved back to Num for float fun

* OneOrFilled Feedback
2021-11-11 01:49:46 +01:00
Andrea Fioraldi
b4e15fe9f3
Bridge grammartec from Nautilus to libafl (#342)
* nautilus dep

* nautilus generation

* fix mutator

* start new mutator for nautilus

* other mutators

* baby

* ci

* NautilusFeedback

* fix unparse

* ci

* ci

* ci

* ci

* nigghtly clippy

* ci

* fix

* ci

* ci

* update construct automatata

* fix

* ci

* clippy

* clippy

* nightly clippy

* more clippy

* minor clippy

Co-authored-by: Dominik Maier <domenukk@gmail.com>
2021-11-06 02:21:53 +01:00
Andrea Fioraldi
28c5e59fb2 Fix Rust 2021 clippy 2021-11-04 10:55:54 +01:00
Andrea Fioraldi
e46bb8643a Fix try_into in PyAny::cast_as in libafl_qemu 2021-11-04 10:01:13 +01:00
Jordan McLeod
3d436b7519
Upgrade to Rust 2021 Edition (#340)
* Enable missing const_xxh3 feature

* Move to Rust 2021 Edition

* Fix clippy complaints

* Remove imports made unecessary in 2021 edition
2021-11-04 09:59:49 +01:00
Alexandru Geană
f5bed190e7
add support for aarch64 in libafl_qemu (#335) 2021-10-25 22:38:26 +02:00
julihoh
2e55d24f5a
update deps (#327)
* experimental update deps

* Reverted to rand-core 0.5.1 for Lain compatibility

* updated nix

* less strict libc dep

* remove deprecated errno conversion

Co-authored-by: Dominik Maier <domenukk@gmail.com>
2021-10-12 10:32:21 +02:00
Dominik Maier
44d844e1e2
32 bit arm regs (#315)
* aarch and arm regs

* fix arm, remove aarch64

* remove aarch64 mod
2021-10-11 22:20:19 +02:00
Andrea Fioraldi
131483410f Update QEMU git hash 2021-10-04 10:44:55 +02:00
Andrea Fioraldi
91ce28deac
Python generic qemu hook (#314)
* python generic hook and value

* python generic hook
2021-10-01 17:10:35 +02:00