Skip to content

Commit d67296f

Browse files
authored
Soft recovery from crashes in libafl qemu usermode (#3073)
* soft recovery from crashes in qemu * regen bindings for clippy * configurable crash behaviour
1 parent d4a86cd commit d67296f

File tree

15 files changed

+1028
-925
lines changed

15 files changed

+1028
-925
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ log = "0.4.22"
103103
meminterval = "0.4.1"
104104
mimalloc = { version = "0.1.43", default-features = false }
105105
nix = { version = "0.29.0", default-features = false }
106+
num-derive = { version = "0.4.2", default-features = false }
106107
num_enum = { version = "0.7.3", default-features = false }
107108
num-traits = { version = "0.2.19", default-features = false }
108109
paste = "1.0.15"

fuzzers/binary_only/fuzzbench_qemu/src/fuzzer.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ use libafl_qemu::{
5353
edges::StdEdgeCoverageModule,
5454
},
5555
Emulator, GuestReg, MmapPerms, QemuExecutor, QemuExitError, QemuExitReason, QemuShutdownCause,
56-
Regs,
56+
Regs, TargetSignalHandling,
5757
};
5858
use libafl_targets::{edges_map_mut_ptr, EDGES_MAP_ALLOCATED_SIZE, MAX_EDGES_FOUND};
5959
#[cfg(unix)]
@@ -194,6 +194,10 @@ fn fuzz(
194194
.modules(modules)
195195
.build()?;
196196

197+
// return to harness instead of crashing the process.
198+
// greatly speeds up crash recovery.
199+
emulator.set_target_crash_handling(&TargetSignalHandling::RaiseSignal);
200+
197201
let qemu = emulator.qemu();
198202

199203
let mut elf_buffer = Vec::new();
@@ -359,13 +363,15 @@ fn fuzz(
359363
qemu.write_reg(Regs::Rip, test_one_input_ptr).unwrap();
360364
qemu.write_reg(Regs::Rsp, stack_ptr).unwrap();
361365

362-
match qemu.run() {
366+
let qemu_ret = qemu.run();
367+
368+
match qemu_ret {
363369
Ok(QemuExitReason::Breakpoint(_)) => {}
364-
Ok(QemuExitReason::End(QemuShutdownCause::HostSignal(signal))) => {
365-
signal.handle();
366-
}
370+
Ok(QemuExitReason::Crash) => return ExitKind::Crash,
371+
Ok(QemuExitReason::Timeout) => return ExitKind::Timeout,
372+
367373
Err(QemuExitError::UnexpectedExit) => return ExitKind::Crash,
368-
_ => panic!("Unexpected QEMU exit."),
374+
_ => panic!("Unexpected QEMU exit: {qemu_ret:?}"),
369375
}
370376
}
371377

libafl_qemu/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ hashbrown = { workspace = true, default-features = true, features = [
109109
"serde",
110110
] } # A faster hashmap, nostd compatible
111111
num-traits = { workspace = true, default-features = true }
112-
num-derive = "0.4.2"
112+
num-derive = { workspace = true }
113113
num_enum = { workspace = true, default-features = true }
114114
goblin = "0.9.2"
115115
libc = { workspace = true }
@@ -133,6 +133,7 @@ bytes-utils = "0.1.4"
133133
typed-builder = { workspace = true }
134134
memmap2 = "0.9.5"
135135
getset = "0.1.3"
136+
136137
# Document all features of this crate (for `cargo doc`)
137138
document-features = { workspace = true, optional = true }
138139

libafl_qemu/libafl_qemu_build/src/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::cargo_add_rpath;
1111

1212
pub const QEMU_URL: &str = "https://github.com/AFLplusplus/qemu-libafl-bridge";
1313
pub const QEMU_DIRNAME: &str = "qemu-libafl-bridge";
14-
pub const QEMU_REVISION: &str = "3c60ef9b83107a160021075b485831edecb5a1c3";
14+
pub const QEMU_REVISION: &str = "fea68856b9410ca6f0076a6bf9ccc4b4b11aa09c";
1515

1616
pub struct BuildResult {
1717
pub qemu_path: PathBuf,

0 commit comments

Comments
 (0)