AFLplusplus / LibAFL

Advanced Fuzzing Library - Slot your Fuzzer together in Rust! Scales across cores and machines. For Windows, Android, MacOS, Linux, no_std, ...
Other
2.03k stars 319 forks source link

Avoid using feature flags and env variable to set the same parameter pt.1 emulation_mode #2512

Closed Marcondiro closed 3 weeks ago

Marcondiro commented 2 months ago

This PR follows discussion https://github.com/AFLplusplus/LibAFL/discussions/2505 TLDR: Using only the feature flag simplifies things a bit and allows the usage of optional dependencies

Marcondiro commented 2 months ago

WIP, for now I've done it just for emulation_mode, any feedback is welcome

Marcondiro commented 2 months ago

Ubuntu-clippy CI fails because it is run with --all-features. Upstream doesn't fail because it silently defaults to usermode, clippy is not run for systemmode

domenukk commented 2 months ago

--all-features should enabled a clippy feature which makes it work magically. Maybe just build usermode always?

Marcondiro commented 2 months ago

@domenukk I'm not sure I fully understood your message :smile: How about avoiding --all-features for libafl_qemu? I don't like this solution very much and maybe in the future the incompatible features thing could be reconsidered

domenukk commented 2 months ago

@domenukk I'm not sure I fully understood your message 😄 How about avoiding --all-features for libafl_qemu? I don't like this solution very much and maybe in the future the incompatible features thing could be reconsidered

running clippy --all-features (IMHO) should just work(tm)

domenukk commented 2 months ago

Like, why make this so much harder than it needs to be?

Marcondiro commented 2 months ago

The thing is that in libafl_qemu some features are incompatible (usermode and systemmode for instance), running with --all-features should fail.

So far the build script decided which feature to actually use and which silently ignore when running with --all-features. In my opinion having --all-features just working but actually not enabling all features is not ideal. Looking at the clippy script it looks like every feature of libafl_qemu is checked with clippy while it is not.

I thought this change would simplify and clean things a bit (no hidden defaults, fallback env vars, just plain feature), but if it looks more convoluted to you I'll just drop this PR no problem :)

domenukk commented 2 months ago

Features should be additive (see: https://doc.rust-lang.org/nightly/cargo/reference/features.html#feature-unification ) so I think we should either

I'm not sure what other crates do that have mutual exclusive dependencies, like crypto libs with backends etc?

Marcondiro commented 2 months ago

Right below the link you've posted there is also: https://doc.rust-lang.org/nightly/cargo/reference/features.html#mutually-exclusive-features

This should be avoided if possible and yes features should be additive, this is why I was saying

I don't like this solution very much and maybe in the future the incompatible features thing could be reconsidered

About

specify a default for what happens when both features are set

It is more or less what is done now, IMHO this should fail at compile time (also according to the above link)

take away the usermode feature and make it the default. Note that this is likely not possible for architectures, so...

As you say feature are meant to be additive, here again we would also remove/replace stuff

domenukk commented 2 months ago

The link you posted literally states:

Instead of using mutually exclusive features, consider some other options: ...

In this case it's easy - we default to usermode and x86_64, that's what we've done so far

domenukk commented 2 months ago

BTW I don't care either way, @rmalmain and/or @andreafioraldi should say how they want it

andreafioraldi commented 2 months ago

if there is a conflict i would fail with an error, as we already do for x86+big endian for instance

domenukk commented 2 months ago

Fine by me - but maybe if we still have the clippy feature that makes things "just work" --all will still do the right thing here?

rmalmain commented 2 months ago

we can also adapt clippy flags in the clippy script is the CI variable is on. i don't think it makes sense to change this kind of general behaviour only to have clippy --all working.
i think we shouldn't use env variables to set / unset features in general, it is confusing otherwise. btw @Marcondiro, i think you shouldn't use unreachable! but panic! instead with an error message, it should be more clear to understand the problem.

domenukk commented 3 weeks ago

What's the status here? Needs a rebase and then needs to get reviewed/merged @rmalmain

Marcondiro commented 3 weeks ago

@rmalmain should be ready for review

rmalmain commented 3 weeks ago

it's hard to tell if your pr is gonna break something at the moment, half of the CI is broken