Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LibAFL_QEMU: Don't require extra_tokens. #2576

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions fuzzers/binary_only/qemu_launcher/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ impl<'a> Client<'a> {
}
});

let extra_tokens = injection_module.as_ref().map(|h| h.tokens.clone());

qemu.entry_break(start_pc);

let ret_addr: GuestAddr = qemu
Expand All @@ -169,7 +167,12 @@ impl<'a> Client<'a> {
.address_filter(self.coverage_filter(&qemu)?)
.build();

let instance = Instance::builder()
let extra_tokens = injection_module
.as_ref()
.map(|h| h.tokens.clone())
.unwrap_or_default();

let instance_builder = Instance::builder()
.options(self.options)
.qemu(&qemu)
.mgr(mgr)
Expand All @@ -178,7 +181,7 @@ impl<'a> Client<'a> {

if is_asan && is_cmplog {
if let Some(injection_module) = injection_module {
instance.build().run(
instance_builder.build().run(
tuple_list!(
edge_coverage_module,
CmpLogModule::default(),
Expand All @@ -188,7 +191,7 @@ impl<'a> Client<'a> {
state,
)
} else {
instance.build().run(
instance_builder.build().run(
tuple_list!(
edge_coverage_module,
CmpLogModule::default(),
Expand All @@ -199,7 +202,7 @@ impl<'a> Client<'a> {
}
} else if is_asan_guest && is_cmplog {
if let Some(injection_module) = injection_module {
instance.build().run(
instance_builder.build().run(
tuple_list!(
edge_coverage_module,
CmpLogModule::default(),
Expand All @@ -209,7 +212,7 @@ impl<'a> Client<'a> {
state,
)
} else {
instance.build().run(
instance_builder.build().run(
tuple_list!(
edge_coverage_module,
CmpLogModule::default(),
Expand All @@ -220,7 +223,7 @@ impl<'a> Client<'a> {
}
} else if is_asan {
if let Some(injection_module) = injection_module {
instance.build().run(
instance_builder.build().run(
tuple_list!(
edge_coverage_module,
AsanModule::default(asan.take().unwrap()),
Expand All @@ -229,7 +232,7 @@ impl<'a> Client<'a> {
state,
)
} else {
instance.build().run(
instance_builder.build().run(
tuple_list!(
edge_coverage_module,
AsanModule::default(asan.take().unwrap()),
Expand All @@ -242,10 +245,10 @@ impl<'a> Client<'a> {
edge_coverage_module,
AsanGuestModule::default(&qemu, asan_lib.take().unwrap())
);
instance.build().run(modules, state)
instance_builder.build().run(modules, state)
} else if is_cmplog {
if let Some(injection_module) = injection_module {
instance.build().run(
instance_builder.build().run(
tuple_list!(
edge_coverage_module,
CmpLogModule::default(),
Expand All @@ -254,17 +257,17 @@ impl<'a> Client<'a> {
state,
)
} else {
instance.build().run(
instance_builder.build().run(
tuple_list!(edge_coverage_module, CmpLogModule::default()),
state,
)
}
} else if let Some(injection_module) = injection_module {
instance
instance_builder
.build()
.run(tuple_list!(edge_coverage_module, injection_module), state)
} else {
instance
instance_builder
.build()
.run(tuple_list!(edge_coverage_module), state)
}
Expand Down
11 changes: 5 additions & 6 deletions fuzzers/binary_only/qemu_launcher/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ pub struct Instance<'a, M: Monitor> {
qemu: &'a Qemu,
mgr: ClientMgr<M>,
core_id: CoreId,
extra_tokens: Option<Vec<String>>,
#[builder(default)]
extra_tokens: Vec<String>,
#[builder(default=PhantomData)]
phantom: PhantomData<M>,
}
Expand Down Expand Up @@ -134,11 +135,9 @@ impl<'a, M: Monitor> Instance<'a, M> {

let mut tokens = Tokens::new();

if let Some(extra_tokens) = &self.extra_tokens {
for token in extra_tokens {
let bytes = token.as_bytes().to_vec();
let _ = tokens.add_token(&bytes);
}
for token in &self.extra_tokens {
let bytes = token.as_bytes().to_vec();
let _ = tokens.add_token(&bytes);
}

if let Some(tokenfile) = &self.options.tokens {
Expand Down
2 changes: 2 additions & 0 deletions libafl_qemu/src/modules/edges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ pub struct EdgeCoverageModuleBuilder<AF, PF, V> {
pub struct EdgeCoverageModule<AF, PF, V> {
variant: V,
address_filter: AF,
// we only use it in system mode at the moment.
#[cfg_attr(not(emulation_mode = "systemmode"), allow(dead_code))]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more like it doesn't make sense to have this member in usermode.
i don't think we will ever need a page filter for normal processes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we should remove the entry here completely

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes.
didn't do it yet because i think we'll have to do code duplication because of this

page_filter: PF,
use_hitcounts: bool,
use_jit: bool,
Expand Down
Loading