Skip to content

Commit 4c0e01c

Browse files
Fix memopidx bug in libafl_qemu r/w hooks and update QEMU (#1500)
1 parent 9645dca commit 4c0e01c

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

libafl_qemu/build_linux.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ pub fn build() {
7070
if (emulation_mode == "usermode") && build_libqasan {
7171
let qasan_dir = Path::new("libqasan");
7272
let qasan_dir = fs::canonicalize(qasan_dir).unwrap();
73+
println!("cargo:rerun-if-changed={}", qasan_dir.display());
7374

7475
assert!(Command::new("make")
7576
.current_dir(out_dir_path)

libafl_qemu/libafl_qemu_build/src/bindings.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ use bindgen::{BindgenError, Bindings};
44

55
const WRAPPER_HEADER: &str = r#"
66
7+
// https://github.com/rust-lang/rust-bindgen/issues/2500
8+
#define __AVX512VLFP16INTRIN_H
9+
#define __AVX512FP16INTRIN_H
10+
711
// QEMU_BUILD_BUG* cause an infinite recursion in bindgen when target is arm
812
#include "qemu/compiler.h"
913

libafl_qemu/libafl_qemu_build/src/build.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use which::which;
88

99
const QEMU_URL: &str = "https://github.com/AFLplusplus/qemu-libafl-bridge";
1010
const QEMU_DIRNAME: &str = "qemu-libafl-bridge";
11-
const QEMU_REVISION: &str = "659539eaceb7acf242f2f6a573b705e1be1befb6";
11+
const QEMU_REVISION: &str = "ff5bc3d934044a5a5466759525f0371ccf86152e";
1212

1313
fn build_dep_check(tools: &[&str]) {
1414
for tool in tools {
@@ -60,6 +60,7 @@ pub fn build(
6060

6161
build_dep_check(&["git", "make"]);
6262

63+
let cc_compiler = cc::Build::new().cpp(false).get_compiler();
6364
let cpp_compiler = cc::Build::new().cpp(true).get_compiler();
6465

6566
let qemu_path = if let Some(qemu_dir) = custum_qemu_dir.as_ref() {
@@ -139,11 +140,16 @@ pub fn build(
139140
cmd.current_dir(&qemu_path)
140141
//.arg("--as-static-lib")
141142
.env("__LIBAFL_QEMU_BUILD_OUT", build_dir.join("linkinfo.json"))
143+
.env("__LIBAFL_QEMU_BUILD_CC", cc_compiler.path())
142144
.env("__LIBAFL_QEMU_BUILD_CXX", cpp_compiler.path())
143145
.arg(&format!(
144-
"--cxx={}",
146+
"--cc={}",
145147
qemu_path.join("linker_interceptor.py").display()
146148
))
149+
.arg(&format!(
150+
"--cxx={}",
151+
qemu_path.join("linker_interceptor++.py").display()
152+
))
147153
.arg("--as-shared-lib")
148154
.arg(&format!("--target-list={cpu_target}-{target_suffix}"))
149155
.args([
@@ -161,11 +167,16 @@ pub fn build(
161167
cmd.current_dir(&qemu_path)
162168
//.arg("--as-static-lib")
163169
.env("__LIBAFL_QEMU_BUILD_OUT", build_dir.join("linkinfo.json"))
170+
.env("__LIBAFL_QEMU_BUILD_CC", cc_compiler.path())
164171
.env("__LIBAFL_QEMU_BUILD_CXX", cpp_compiler.path())
165172
.arg(&format!(
166-
"--cxx={}",
173+
"--cc={}",
167174
qemu_path.join("linker_interceptor.py").display()
168-
)) // TODO set __LIBAFL_QEMU_BUILD_CXX
175+
))
176+
.arg(&format!(
177+
"--cxx={}",
178+
qemu_path.join("linker_interceptor++.py").display()
179+
))
169180
.arg("--as-shared-lib")
170181
.arg(&format!("--target-list={cpu_target}-{target_suffix}"))
171182
.arg(if cfg!(feature = "slirp") {

libafl_qemu/libqasan/malloc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ void *__libqasan_malloc(size_t size) {
193193
else
194194
QASAN_POISON((char *)&p[1] + size, REDZONE_SIZE, ASAN_HEAP_RIGHT_RZ);
195195

196-
__builtin_memset(&p[1], 0xff, size);
196+
__libqasan_memset(&p[1], 0xff, size);
197197

198198
return &p[1];
199199
}
@@ -249,7 +249,7 @@ void *__libqasan_calloc(size_t nmemb, size_t size) {
249249
char *p = __libqasan_malloc(size);
250250
if (!p) return NULL;
251251

252-
__builtin_memset(p, 0, size);
252+
__libqasan_memset(p, 0, size);
253253

254254
return p;
255255
}
@@ -263,7 +263,7 @@ void *__libqasan_realloc(void *ptr, size_t size) {
263263
size_t n = ((struct chunk_begin *)ptr)[-1].requested_size;
264264
if (size < n) n = size;
265265

266-
__builtin_memcpy(p, ptr, n);
266+
__libqasan_memcpy(p, ptr, n);
267267

268268
__libqasan_free(ptr);
269269
return p;
@@ -306,7 +306,7 @@ int __libqasan_posix_memalign(void **ptr, size_t align, size_t len) {
306306
else
307307
QASAN_POISON(data + len, REDZONE_SIZE, ASAN_HEAP_RIGHT_RZ);
308308

309-
__builtin_memset(data, 0xff, len);
309+
__libqasan_memset(data, 0xff, len);
310310

311311
*ptr = data;
312312

0 commit comments

Comments
 (0)