Skip to content

Commit b320a8d

Browse files
authored
Add PC to QEMU's read / write callbacks + logger module (#2896)
* Logger module (only read/write for now) * add pc to rw callbacks * regen bindings
1 parent 133a0ff commit b320a8d

File tree

13 files changed

+586
-139
lines changed

13 files changed

+586
-139
lines changed

fuzzers/binary_only/qemu_coverage/Makefile.toml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,16 @@ mac_alias = "unsupported"
241241
windows_alias = "unsupported"
242242

243243
[tasks.run_unix]
244-
command = "${TARGET_DIR}/${PROFILE_DIR}/qemu_coverage-${CARGO_MAKE_PROFILE}"
245-
args = [
246-
"--coverage-path",
247-
"${TARGET_DIR}/cov.drcov",
248-
"--input-dir",
249-
"./corpus",
250-
"--",
251-
"${TARGET_DIR}/libpng-harness-${CARGO_MAKE_PROFILE}",
252-
]
244+
script_runner = "@shell"
245+
script = '''
246+
${TARGET_DIR}/${PROFILE_DIR}/qemu_coverage-${CARGO_MAKE_PROFILE} \
247+
--coverage-path \
248+
${TARGET_DIR}/cov.drcov \
249+
--input-dir \
250+
./corpus \
251+
-- \
252+
${TARGET_DIR}/libpng-harness-${CARGO_MAKE_PROFILE}
253+
'''
253254
dependencies = ["harness", "fuzzer"]
254255

255256
[tasks.test]
@@ -297,11 +298,9 @@ cargo run --manifest-path ../../../utils/drcov_utils/Cargo.toml --bin drcov_merg
297298
-i ${TARGET_DIR}/cov-000.drcov ${TARGET_DIR}/cov-001.drcov ${TARGET_DIR}/cov-002.drcov ${TARGET_DIR}/cov-003.drcov \
298299
--output ${TARGET_DIR}/cov-merged.drcov || exit 1
299300
300-
TMP=$(cargo run --manifest-path ../../../utils/drcov_utils/Cargo.toml --bin drcov_dump_addrs -- \
301+
NB_BLOCKS=$(cargo run --manifest-path ../../../utils/drcov_utils/Cargo.toml --bin drcov_dump_addrs -- \
301302
-i ${TARGET_DIR}/cov-merged.drcov -a | wc -l || exit 1)
302303
303-
NB_BLOCKS=$((TMP - 1))
304-
305304
echo "Nb blocks found: $NB_BLOCKS"
306305
307306
if [ $NB_BLOCKS -ge 1700 ]; then

fuzzers/binary_only/qemu_coverage/src/fuzzer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ pub fn fuzz() {
136136

137137
let emulator_modules = tuple_list!(
138138
DrCovModule::builder().filename(cov_path.clone()).build(),
139-
SnapshotModule::new()
139+
SnapshotModule::new(),
140140
);
141141

142142
let emulator = Emulator::empty()

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 = "2b5e4bfcff875571b2813a9494de8b2e4c56120e";
14+
pub const QEMU_REVISION: &str = "7e0dc68430c509ad50c6b0c9887f7e642a4bba2d";
1515

1616
pub struct BuildResult {
1717
pub qemu_path: PathBuf,

libafl_qemu/libafl_qemu_sys/src/bindings/x86_64_stub_bindings.rs

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/* 1.85.0-nightly */
2-
/* qemu git hash: 81e52dc60f83c3ae191c1a07b39bb255e633c234 */
1+
/* 1.86.0-nightly */
2+
/* qemu git hash: 3f7b2d86635aaf03818aaec1d285dba88255f831 */
33
/* automatically generated by rust-bindgen 0.71.1 */
44

55
use libc::siginfo_t;
@@ -8025,6 +8025,8 @@ unsafe extern "C" {
80258025
unsafe extern "C" {
80268026
pub fn libafl_qemu_hook_edge_run();
80278027
}
8028+
pub type libafl_instruction_cb =
8029+
::std::option::Option<unsafe extern "C" fn(data: u64, pc: target_ulong)>;
80288030
#[repr(C)]
80298031
#[derive(Debug, Copy, Clone)]
80308032
pub struct libafl_instruction_hook {
@@ -8063,7 +8065,7 @@ impl Default for libafl_instruction_hook {
80638065
unsafe extern "C" {
80648066
pub fn libafl_qemu_add_instruction_hooks(
80658067
pc: target_ulong,
8066-
callback: ::std::option::Option<unsafe extern "C" fn(data: u64, pc: target_ulong)>,
8068+
callback: libafl_instruction_cb,
80678069
data: u64,
80688070
invalidate: ::std::os::raw::c_int,
80698071
) -> usize;
@@ -8086,12 +8088,19 @@ unsafe extern "C" {
80868088
unsafe extern "C" {
80878089
pub fn libafl_qemu_hook_instruction_run(pc_next: vaddr);
80888090
}
8091+
pub type libafl_rw_gen_cb = ::std::option::Option<
8092+
unsafe extern "C" fn(data: u64, pc: target_ulong, addr: *mut TCGTemp, oi: MemOpIdx) -> u64,
8093+
>;
8094+
pub type libafl_rw_exec_cb = ::std::option::Option<
8095+
unsafe extern "C" fn(data: u64, id: u64, pc: target_ulong, addr: target_ulong),
8096+
>;
8097+
pub type libafl_rw_execN_cb = ::std::option::Option<
8098+
unsafe extern "C" fn(data: u64, id: u64, pc: target_ulong, addr: target_ulong, size: usize),
8099+
>;
80898100
#[repr(C)]
80908101
#[derive(Debug, Copy, Clone)]
80918102
pub struct libafl_rw_hook {
8092-
pub gen: ::std::option::Option<
8093-
unsafe extern "C" fn(data: u64, pc: target_ulong, addr: *mut TCGTemp, oi: MemOpIdx) -> u64,
8094-
>,
8103+
pub gen: libafl_rw_gen_cb,
80958104
pub data: u64,
80968105
pub num: usize,
80978106
pub helper_info1: TCGHelperInfo,
@@ -8132,48 +8141,30 @@ impl Default for libafl_rw_hook {
81328141
}
81338142
}
81348143
unsafe extern "C" {
8135-
pub fn libafl_gen_read(addr: *mut TCGTemp, oi: MemOpIdx);
8144+
pub fn libafl_gen_read(pc: *mut TCGTemp, addr: *mut TCGTemp, oi: MemOpIdx);
81368145
}
81378146
unsafe extern "C" {
8138-
pub fn libafl_gen_write(addr: *mut TCGTemp, oi: MemOpIdx);
8147+
pub fn libafl_gen_write(pc: *mut TCGTemp, addr: *mut TCGTemp, oi: MemOpIdx);
81398148
}
81408149
unsafe extern "C" {
81418150
pub fn libafl_add_read_hook(
8142-
gen: ::std::option::Option<
8143-
unsafe extern "C" fn(
8144-
data: u64,
8145-
pc: target_ulong,
8146-
addr: *mut TCGTemp,
8147-
oi: MemOpIdx,
8148-
) -> u64,
8149-
>,
8150-
exec1: ::std::option::Option<unsafe extern "C" fn(data: u64, id: u64, addr: target_ulong)>,
8151-
exec2: ::std::option::Option<unsafe extern "C" fn(data: u64, id: u64, addr: target_ulong)>,
8152-
exec4: ::std::option::Option<unsafe extern "C" fn(data: u64, id: u64, addr: target_ulong)>,
8153-
exec8: ::std::option::Option<unsafe extern "C" fn(data: u64, id: u64, addr: target_ulong)>,
8154-
execN: ::std::option::Option<
8155-
unsafe extern "C" fn(data: u64, id: u64, addr: target_ulong, size: usize),
8156-
>,
8151+
gen: libafl_rw_gen_cb,
8152+
exec1: libafl_rw_exec_cb,
8153+
exec2: libafl_rw_exec_cb,
8154+
exec4: libafl_rw_exec_cb,
8155+
exec8: libafl_rw_exec_cb,
8156+
execN: libafl_rw_execN_cb,
81578157
data: u64,
81588158
) -> usize;
81598159
}
81608160
unsafe extern "C" {
81618161
pub fn libafl_add_write_hook(
8162-
gen: ::std::option::Option<
8163-
unsafe extern "C" fn(
8164-
data: u64,
8165-
pc: target_ulong,
8166-
addr: *mut TCGTemp,
8167-
oi: MemOpIdx,
8168-
) -> u64,
8169-
>,
8170-
exec1: ::std::option::Option<unsafe extern "C" fn(data: u64, id: u64, addr: target_ulong)>,
8171-
exec2: ::std::option::Option<unsafe extern "C" fn(data: u64, id: u64, addr: target_ulong)>,
8172-
exec4: ::std::option::Option<unsafe extern "C" fn(data: u64, id: u64, addr: target_ulong)>,
8173-
exec8: ::std::option::Option<unsafe extern "C" fn(data: u64, id: u64, addr: target_ulong)>,
8174-
execN: ::std::option::Option<
8175-
unsafe extern "C" fn(data: u64, id: u64, addr: target_ulong, size: usize),
8176-
>,
8162+
gen: libafl_rw_gen_cb,
8163+
exec1: libafl_rw_exec_cb,
8164+
exec2: libafl_rw_exec_cb,
8165+
exec4: libafl_rw_exec_cb,
8166+
exec8: libafl_rw_exec_cb,
8167+
execN: libafl_rw_execN_cb,
81778168
data: u64,
81788169
) -> usize;
81798170
}

libafl_qemu/runtime/libafl_qemu_stub_bindings.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/* 1.85.0-nightly */
2-
/* qemu git hash: 81e52dc60f83c3ae191c1a07b39bb255e633c234 */
1+
/* 1.86.0-nightly */
2+
/* qemu git hash: 3f7b2d86635aaf03818aaec1d285dba88255f831 */
33
/* automatically generated by rust-bindgen 0.71.1 */
44

55
pub const LIBAFL_SYNC_EXIT_OPCODE: u32 = 1727150607;

libafl_qemu/runtime/nyx_stub_bindings.rs

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/* 1.85.0-nightly */
2-
/* qemu git hash: 81e52dc60f83c3ae191c1a07b39bb255e633c234 */
1+
/* 1.86.0-nightly */
2+
/* qemu git hash: 3f7b2d86635aaf03818aaec1d285dba88255f831 */
33
/* automatically generated by rust-bindgen 0.71.1 */
44

55
#[repr(C)]
@@ -1078,33 +1078,35 @@ pub type intmax_t = __intmax_t;
10781078
pub type uintmax_t = __uintmax_t;
10791079
#[repr(C)]
10801080
#[derive(Debug, Default)]
1081-
pub struct kAFL_payload {
1081+
pub struct _bindgen_ty_1 {
10821082
pub size: i32,
10831083
pub data: __IncompleteArrayField<u8>,
10841084
}
10851085
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
10861086
const _: () = {
1087-
["Size of kAFL_payload"][::std::mem::size_of::<kAFL_payload>() - 4usize];
1088-
["Alignment of kAFL_payload"][::std::mem::align_of::<kAFL_payload>() - 4usize];
1089-
["Offset of field: kAFL_payload::size"][::std::mem::offset_of!(kAFL_payload, size) - 0usize];
1090-
["Offset of field: kAFL_payload::data"][::std::mem::offset_of!(kAFL_payload, data) - 4usize];
1087+
["Size of _bindgen_ty_1"][::std::mem::size_of::<_bindgen_ty_1>() - 4usize];
1088+
["Alignment of _bindgen_ty_1"][::std::mem::align_of::<_bindgen_ty_1>() - 4usize];
1089+
["Offset of field: _bindgen_ty_1::size"][::std::mem::offset_of!(_bindgen_ty_1, size) - 0usize];
1090+
["Offset of field: _bindgen_ty_1::data"][::std::mem::offset_of!(_bindgen_ty_1, data) - 4usize];
10911091
};
1092+
pub type kAFL_payload = _bindgen_ty_1;
10921093
#[repr(C)]
10931094
#[derive(Debug, Default, Copy, Clone)]
1094-
pub struct kAFL_ranges {
1095+
pub struct _bindgen_ty_2 {
10951096
pub ip: [u64; 4usize],
10961097
pub size: [u64; 4usize],
10971098
pub enabled: [u8; 4usize],
10981099
}
10991100
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
11001101
const _: () = {
1101-
["Size of kAFL_ranges"][::std::mem::size_of::<kAFL_ranges>() - 72usize];
1102-
["Alignment of kAFL_ranges"][::std::mem::align_of::<kAFL_ranges>() - 8usize];
1103-
["Offset of field: kAFL_ranges::ip"][::std::mem::offset_of!(kAFL_ranges, ip) - 0usize];
1104-
["Offset of field: kAFL_ranges::size"][::std::mem::offset_of!(kAFL_ranges, size) - 32usize];
1105-
["Offset of field: kAFL_ranges::enabled"]
1106-
[::std::mem::offset_of!(kAFL_ranges, enabled) - 64usize];
1102+
["Size of _bindgen_ty_2"][::std::mem::size_of::<_bindgen_ty_2>() - 72usize];
1103+
["Alignment of _bindgen_ty_2"][::std::mem::align_of::<_bindgen_ty_2>() - 8usize];
1104+
["Offset of field: _bindgen_ty_2::ip"][::std::mem::offset_of!(_bindgen_ty_2, ip) - 0usize];
1105+
["Offset of field: _bindgen_ty_2::size"][::std::mem::offset_of!(_bindgen_ty_2, size) - 32usize];
1106+
["Offset of field: _bindgen_ty_2::enabled"]
1107+
[::std::mem::offset_of!(_bindgen_ty_2, enabled) - 64usize];
11071108
};
1109+
pub type kAFL_ranges = _bindgen_ty_2;
11081110
#[repr(C, packed)]
11091111
#[derive(Debug, Default, Copy, Clone)]
11101112
pub struct host_config_t {
@@ -1134,7 +1136,7 @@ const _: () = {
11341136
};
11351137
#[repr(C, packed)]
11361138
#[derive(Debug, Default, Copy, Clone)]
1137-
pub struct agent_config_t {
1139+
pub struct _bindgen_ty_3 {
11381140
pub agent_magic: u32,
11391141
pub agent_version: u32,
11401142
pub agent_timeout_detection: u8,
@@ -1149,31 +1151,32 @@ pub struct agent_config_t {
11491151
}
11501152
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
11511153
const _: () = {
1152-
["Size of agent_config_t"][::std::mem::size_of::<agent_config_t>() - 37usize];
1153-
["Alignment of agent_config_t"][::std::mem::align_of::<agent_config_t>() - 1usize];
1154-
["Offset of field: agent_config_t::agent_magic"]
1155-
[::std::mem::offset_of!(agent_config_t, agent_magic) - 0usize];
1156-
["Offset of field: agent_config_t::agent_version"]
1157-
[::std::mem::offset_of!(agent_config_t, agent_version) - 4usize];
1158-
["Offset of field: agent_config_t::agent_timeout_detection"]
1159-
[::std::mem::offset_of!(agent_config_t, agent_timeout_detection) - 8usize];
1160-
["Offset of field: agent_config_t::agent_tracing"]
1161-
[::std::mem::offset_of!(agent_config_t, agent_tracing) - 9usize];
1162-
["Offset of field: agent_config_t::agent_ijon_tracing"]
1163-
[::std::mem::offset_of!(agent_config_t, agent_ijon_tracing) - 10usize];
1164-
["Offset of field: agent_config_t::agent_non_reload_mode"]
1165-
[::std::mem::offset_of!(agent_config_t, agent_non_reload_mode) - 11usize];
1166-
["Offset of field: agent_config_t::trace_buffer_vaddr"]
1167-
[::std::mem::offset_of!(agent_config_t, trace_buffer_vaddr) - 12usize];
1168-
["Offset of field: agent_config_t::ijon_trace_buffer_vaddr"]
1169-
[::std::mem::offset_of!(agent_config_t, ijon_trace_buffer_vaddr) - 20usize];
1170-
["Offset of field: agent_config_t::coverage_bitmap_size"]
1171-
[::std::mem::offset_of!(agent_config_t, coverage_bitmap_size) - 28usize];
1172-
["Offset of field: agent_config_t::input_buffer_size"]
1173-
[::std::mem::offset_of!(agent_config_t, input_buffer_size) - 32usize];
1174-
["Offset of field: agent_config_t::dump_payloads"]
1175-
[::std::mem::offset_of!(agent_config_t, dump_payloads) - 36usize];
1154+
["Size of _bindgen_ty_3"][::std::mem::size_of::<_bindgen_ty_3>() - 37usize];
1155+
["Alignment of _bindgen_ty_3"][::std::mem::align_of::<_bindgen_ty_3>() - 1usize];
1156+
["Offset of field: _bindgen_ty_3::agent_magic"]
1157+
[::std::mem::offset_of!(_bindgen_ty_3, agent_magic) - 0usize];
1158+
["Offset of field: _bindgen_ty_3::agent_version"]
1159+
[::std::mem::offset_of!(_bindgen_ty_3, agent_version) - 4usize];
1160+
["Offset of field: _bindgen_ty_3::agent_timeout_detection"]
1161+
[::std::mem::offset_of!(_bindgen_ty_3, agent_timeout_detection) - 8usize];
1162+
["Offset of field: _bindgen_ty_3::agent_tracing"]
1163+
[::std::mem::offset_of!(_bindgen_ty_3, agent_tracing) - 9usize];
1164+
["Offset of field: _bindgen_ty_3::agent_ijon_tracing"]
1165+
[::std::mem::offset_of!(_bindgen_ty_3, agent_ijon_tracing) - 10usize];
1166+
["Offset of field: _bindgen_ty_3::agent_non_reload_mode"]
1167+
[::std::mem::offset_of!(_bindgen_ty_3, agent_non_reload_mode) - 11usize];
1168+
["Offset of field: _bindgen_ty_3::trace_buffer_vaddr"]
1169+
[::std::mem::offset_of!(_bindgen_ty_3, trace_buffer_vaddr) - 12usize];
1170+
["Offset of field: _bindgen_ty_3::ijon_trace_buffer_vaddr"]
1171+
[::std::mem::offset_of!(_bindgen_ty_3, ijon_trace_buffer_vaddr) - 20usize];
1172+
["Offset of field: _bindgen_ty_3::coverage_bitmap_size"]
1173+
[::std::mem::offset_of!(_bindgen_ty_3, coverage_bitmap_size) - 28usize];
1174+
["Offset of field: _bindgen_ty_3::input_buffer_size"]
1175+
[::std::mem::offset_of!(_bindgen_ty_3, input_buffer_size) - 32usize];
1176+
["Offset of field: _bindgen_ty_3::dump_payloads"]
1177+
[::std::mem::offset_of!(_bindgen_ty_3, dump_payloads) - 36usize];
11761178
};
1179+
pub type agent_config_t = _bindgen_ty_3;
11771180
#[repr(C, packed)]
11781181
#[derive(Debug, Default, Copy, Clone)]
11791182
pub struct kafl_dump_file_t {

0 commit comments

Comments
 (0)