Use GuestAddr in QemuInstrumentationFilter (#1085)

* Use GuestAddr in QemuInstrumentationFilter

* fix types
This commit is contained in:
Andrea Fioraldi 2023-02-21 16:19:43 +01:00 committed by GitHub
parent b7296db406
commit 1b0cdab3e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 18 deletions

View File

@ -561,7 +561,7 @@ impl QemuAsanHelper {
} }
#[must_use] #[must_use]
pub fn must_instrument(&self, addr: u64) -> bool { pub fn must_instrument(&self, addr: GuestAddr) -> bool {
self.filter.allowed(addr) self.filter.allowed(addr)
} }
@ -748,7 +748,7 @@ where
QT: QemuHelperTuple<S>, QT: QemuHelperTuple<S>,
{ {
let h = hooks.match_helper_mut::<QemuAsanHelper>().unwrap(); let h = hooks.match_helper_mut::<QemuAsanHelper>().unwrap();
if h.must_instrument(pc.into()) { if h.must_instrument(pc) {
Some(pc.into()) Some(pc.into())
} else { } else {
None None

View File

@ -26,7 +26,7 @@ impl QemuCallTracerHelper {
} }
#[must_use] #[must_use]
pub fn must_instrument(&self, addr: u64) -> bool { pub fn must_instrument(&self, addr: GuestAddr) -> bool {
self.filter.allowed(addr) self.filter.allowed(addr)
} }
@ -131,7 +131,7 @@ where
{ {
let emu = hooks.emulator(); let emu = hooks.emulator();
if let Some(h) = hooks.helpers().match_first_type::<QemuCallTracerHelper>() { if let Some(h) = hooks.helpers().match_first_type::<QemuCallTracerHelper>() {
if !h.must_instrument(pc.into()) { if !h.must_instrument(pc) {
return None; return None;
} }

View File

@ -42,7 +42,7 @@ impl QemuCmpLogHelper {
} }
#[must_use] #[must_use]
pub fn must_instrument(&self, addr: u64) -> bool { pub fn must_instrument(&self, addr: GuestAddr) -> bool {
self.filter.allowed(addr) self.filter.allowed(addr)
} }
} }
@ -83,7 +83,7 @@ impl QemuCmpLogChildHelper {
} }
#[must_use] #[must_use]
pub fn must_instrument(&self, addr: u64) -> bool { pub fn must_instrument(&self, addr: GuestAddr) -> bool {
self.filter.allowed(addr) self.filter.allowed(addr)
} }
} }
@ -127,7 +127,7 @@ where
QT: QemuHelperTuple<S>, QT: QemuHelperTuple<S>,
{ {
if let Some(h) = hooks.match_helper_mut::<QemuCmpLogHelper>() { if let Some(h) = hooks.match_helper_mut::<QemuCmpLogHelper>() {
if !h.must_instrument(pc.into()) { if !h.must_instrument(pc) {
return None; return None;
} }
} }
@ -159,7 +159,7 @@ where
QT: QemuHelperTuple<S>, QT: QemuHelperTuple<S>,
{ {
if let Some(h) = hooks.match_helper_mut::<QemuCmpLogChildHelper>() { if let Some(h) = hooks.match_helper_mut::<QemuCmpLogChildHelper>() {
if !h.must_instrument(pc.into()) { if !h.must_instrument(pc) {
return None; return None;
} }
} }

View File

@ -62,7 +62,7 @@ impl QemuDrCovHelper {
} }
#[must_use] #[must_use]
pub fn must_instrument(&self, addr: u64) -> bool { pub fn must_instrument(&self, addr: GuestAddr) -> bool {
self.filter.allowed(addr) self.filter.allowed(addr)
} }
} }
@ -178,7 +178,7 @@ where
.helpers() .helpers()
.match_first_type::<QemuDrCovHelper>() .match_first_type::<QemuDrCovHelper>()
.unwrap(); .unwrap();
if !drcov_helper.must_instrument(pc.into()) { if !drcov_helper.must_instrument(pc) {
return None; return None;
} }

View File

@ -56,7 +56,7 @@ impl QemuEdgeCoverageHelper {
} }
#[must_use] #[must_use]
pub fn must_instrument(&self, addr: u64) -> bool { pub fn must_instrument(&self, addr: GuestAddr) -> bool {
self.filter.allowed(addr) self.filter.allowed(addr)
} }
} }
@ -112,7 +112,7 @@ impl QemuEdgeCoverageChildHelper {
} }
#[must_use] #[must_use]
pub fn must_instrument(&self, addr: u64) -> bool { pub fn must_instrument(&self, addr: GuestAddr) -> bool {
self.filter.allowed(addr) self.filter.allowed(addr)
} }
} }
@ -162,7 +162,7 @@ where
QT: QemuHelperTuple<S>, QT: QemuHelperTuple<S>,
{ {
if let Some(h) = hooks.helpers().match_first_type::<QemuEdgeCoverageHelper>() { if let Some(h) = hooks.helpers().match_first_type::<QemuEdgeCoverageHelper>() {
if !h.must_instrument(src.into()) && !h.must_instrument(dest.into()) { if !h.must_instrument(src) && !h.must_instrument(dest) {
return None; return None;
} }
} }
@ -224,7 +224,7 @@ where
.helpers() .helpers()
.match_first_type::<QemuEdgeCoverageChildHelper>() .match_first_type::<QemuEdgeCoverageChildHelper>()
{ {
if !h.must_instrument(src.into()) && !h.must_instrument(dest.into()) { if !h.must_instrument(src) && !h.must_instrument(dest) {
return None; return None;
} }
} }

View File

@ -2,7 +2,10 @@ use core::{fmt::Debug, ops::Range};
use libafl::{bolts::tuples::MatchFirstType, executors::ExitKind, inputs::UsesInput}; use libafl::{bolts::tuples::MatchFirstType, executors::ExitKind, inputs::UsesInput};
use crate::{emu::Emulator, hooks::QemuHooks}; use crate::{
emu::{Emulator, GuestAddr},
hooks::QemuHooks,
};
/// A helper for `libafl_qemu`. /// A helper for `libafl_qemu`.
// TODO remove 'static when specialization will be stable // TODO remove 'static when specialization will be stable
@ -114,14 +117,14 @@ where
#[derive(Debug)] #[derive(Debug)]
pub enum QemuInstrumentationFilter { pub enum QemuInstrumentationFilter {
AllowList(Vec<Range<u64>>), AllowList(Vec<Range<GuestAddr>>),
DenyList(Vec<Range<u64>>), DenyList(Vec<Range<GuestAddr>>),
None, None,
} }
impl QemuInstrumentationFilter { impl QemuInstrumentationFilter {
#[must_use] #[must_use]
pub fn allowed(&self, addr: u64) -> bool { pub fn allowed(&self, addr: GuestAddr) -> bool {
match self { match self {
QemuInstrumentationFilter::AllowList(l) => { QemuInstrumentationFilter::AllowList(l) => {
for rng in l { for rng in l {