Skip to content

Commit 3afb25a

Browse files
Merge branch 'main' into mapping-mutator
2 parents 41de711 + 5b7d307 commit 3afb25a

File tree

42 files changed

+328
-312
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+328
-312
lines changed

.devcontainer/devcontainer.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
"customizations": {
1010
"vscode": {
1111
// Add the IDs of extensions you want installed when the container is created.
12-
"extensions": ["matklad.rust-analyzer", "microsoft.Docker"],
12+
"extensions": [
13+
"rust-lang.rust-analyzer",
14+
"microsoft.Docker"
15+
],
1316
// Set *default* container specific settings.json values on container create.
1417
"settings": {
1518
"rust-analyzer.cargo.noDefaultFeatures": true
@@ -20,7 +23,7 @@
2023
// "forwardPorts": [],
2124
// Uncomment the next line to run commands after the container is created - for example installing curl.
2225
// Install development components that shouldn't be in the main Dockerfile
23-
"postCreateCommand": "rustup component add --toolchain nightly rustfmt clippy llvm-tools-preview && cargo install --locked cargo-make",
26+
"postCreateCommand": "rustup component add --toolchain nightly rustfmt clippy llvm-tools-preview && cargo binstall --locked cargo-make",
2427
// Uncomment when using a ptrace-based debugger like C++, Go, and Rust
2528
"runArgs": [
2629
"--cap-add=SYS_PTRACE",
@@ -31,4 +34,4 @@
3134
// "mounts": [ "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" ],
3235
// Uncomment to connect as a non-root user if you've added one. See https://aka.ms/vscode-remote/containers/non-root.
3336
// "remoteUser": "vscode"
34-
}
37+
}

Dockerfile

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ FROM rust:1.76.0 AS libafl
33
LABEL "maintainer"="afl++ team <[email protected]>"
44
LABEL "about"="LibAFL Docker image"
55

6+
# Install cargo-binstall to download the sccache build
7+
RUN curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
68
# install sccache to cache subsequent builds of dependencies
7-
RUN cargo install --locked sccache
9+
RUN cargo binstall --no-confirm sccache
810

911
ENV HOME=/root
1012
ENV SCCACHE_CACHE_SIZE="1G"
@@ -22,12 +24,11 @@ RUN rustup component add rustfmt clippy
2224
# Install clang 18, common build tools
2325
ENV LLVM_VERSION=18
2426
RUN apt update && apt install -y build-essential gdb git wget python3-venv ninja-build lsb-release software-properties-common gnupg cmake
25-
# Workaround until https://github.com/llvm/llvm-project/issues/62475 is resolved
2627
RUN set -ex &&\
27-
echo "deb http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-${LLVM_VERSION} main" > /etc/apt/sources.list.d/apt.llvm.org.list &&\
28-
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc &&\
29-
apt update &&\
30-
apt-get install -y clang-${LLVM_VERSION} lldb-${LLVM_VERSION} lld-${LLVM_VERSION} clangd-${LLVM_VERSION} clang-tidy-${LLVM_VERSION} clang-format-${LLVM_VERSION} clang-tools-${LLVM_VERSION} llvm-${LLVM_VERSION}-dev lld-${LLVM_VERSION} lldb-${LLVM_VERSION} llvm-${LLVM_VERSION}-tools libomp-${LLVM_VERSION}-dev libc++-${LLVM_VERSION}-dev libc++abi-${LLVM_VERSION}-dev libclang-common-${LLVM_VERSION}-dev libclang-${LLVM_VERSION}-dev libclang-cpp${LLVM_VERSION}-dev libunwind-${LLVM_VERSION}-dev libclang-rt-${LLVM_VERSION}-dev libpolly-${LLVM_VERSION}-dev
28+
wget https://apt.llvm.org/llvm.sh &&\
29+
chmod +x llvm.sh &&\
30+
./llvm.sh ${LLVM_VERSION}
31+
3132

3233
# Copy a dummy.rs and Cargo.toml first, so that dependencies are cached
3334
WORKDIR /libafl
@@ -39,6 +40,10 @@ COPY scripts/dummy.rs libafl_derive/src/lib.rs
3940
COPY libafl/Cargo.toml libafl/build.rs libafl/README.md libafl/
4041
COPY scripts/dummy.rs libafl/src/lib.rs
4142

43+
# Set up LLVM aliases
44+
COPY scripts/createAliases.sh libafl/
45+
RUN bash libafl/createAliases.sh ${LLVM_VERSION}
46+
4247
COPY libafl_bolts/Cargo.toml libafl_bolts/build.rs libafl_bolts/README.md libafl_bolts/
4348
COPY libafl_bolts/examples libafl_bolts/examples
4449
COPY scripts/dummy.rs libafl_bolts/src/lib.rs

fuzzers/fuzzbench/fuzzbench/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,11 @@ fn fuzz(
310310
// A minimization+queue policy to get testcasess from the corpus
311311
let scheduler = IndexesLenTimeMinimizerScheduler::new(
312312
&edges_observer,
313-
StdWeightedScheduler::with_schedule(&mut state, &edges_observer, Some(PowerSchedule::FAST)),
313+
StdWeightedScheduler::with_schedule(
314+
&mut state,
315+
&edges_observer,
316+
Some(PowerSchedule::fast()),
317+
),
314318
);
315319

316320
// A fuzzer with feedbacks and a corpus scheduler

fuzzers/fuzzbench/fuzzbench_ctx/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,11 @@ fn fuzz(
320320
// A minimization+queue policy to get testcasess from the corpus
321321
let scheduler = IndexesLenTimeMinimizerScheduler::new(
322322
&edges_observer,
323-
StdWeightedScheduler::with_schedule(&mut state, &edges_observer, Some(PowerSchedule::FAST)),
323+
StdWeightedScheduler::with_schedule(
324+
&mut state,
325+
&edges_observer,
326+
Some(PowerSchedule::fast()),
327+
),
324328
);
325329

326330
// A fuzzer with feedbacks and a corpus scheduler

fuzzers/fuzzbench/fuzzbench_fork_qemu/src/fuzzer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ fn fuzz(
313313
// A minimization+queue policy to get testcasess from the corpus
314314
let scheduler = IndexesLenTimeMinimizerScheduler::new(
315315
&edges_observer,
316-
PowerQueueScheduler::new(&mut state, &edges_observer, PowerSchedule::FAST),
316+
PowerQueueScheduler::new(&mut state, &edges_observer, PowerSchedule::fast()),
317317
);
318318

319319
// A fuzzer with feedbacks and a corpus scheduler

fuzzers/fuzzbench/fuzzbench_forkserver/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ fn fuzz(
308308
StdWeightedScheduler::with_schedule(
309309
&mut state,
310310
&edges_observer,
311-
Some(PowerSchedule::EXPLORE),
311+
Some(PowerSchedule::explore()),
312312
),
313313
);
314314

fuzzers/fuzzbench/fuzzbench_forkserver_cmplog/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ fn fuzz(
308308
StdWeightedScheduler::with_schedule(
309309
&mut state,
310310
&edges_observer,
311-
Some(PowerSchedule::EXPLORE),
311+
Some(PowerSchedule::explore()),
312312
),
313313
);
314314

fuzzers/fuzzbench/fuzzbench_qemu/src/fuzzer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ fn fuzz(
319319
// A minimization+queue policy to get testcasess from the corpus
320320
let scheduler = IndexesLenTimeMinimizerScheduler::new(
321321
&edges_observer,
322-
PowerQueueScheduler::new(&mut state, &edges_observer, PowerSchedule::FAST),
322+
PowerQueueScheduler::new(&mut state, &edges_observer, PowerSchedule::fast()),
323323
);
324324

325325
// A fuzzer with feedbacks and a corpus scheduler

fuzzers/fuzzbench/fuzzbench_text/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ fn fuzz_binary(
380380
StdWeightedScheduler::with_schedule(
381381
&mut state,
382382
&edges_observer,
383-
Some(PowerSchedule::EXPLORE),
383+
Some(PowerSchedule::explore()),
384384
),
385385
);
386386

@@ -605,7 +605,7 @@ fn fuzz_text(
605605
StdWeightedScheduler::with_schedule(
606606
&mut state,
607607
&edges_observer,
608-
Some(PowerSchedule::EXPLORE),
608+
Some(PowerSchedule::explore()),
609609
),
610610
);
611611

fuzzers/libpng/libfuzzer_libpng/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,11 @@ fn fuzz(corpus_dirs: &[PathBuf], objective_dir: PathBuf, broker_port: u16) -> Re
150150
// A minimization+queue policy to get testcasess from the corpus
151151
let scheduler = IndexesLenTimeMinimizerScheduler::new(
152152
&edges_observer,
153-
StdWeightedScheduler::with_schedule(&mut state, &edges_observer, Some(PowerSchedule::FAST)),
153+
StdWeightedScheduler::with_schedule(
154+
&mut state,
155+
&edges_observer,
156+
Some(PowerSchedule::fast()),
157+
),
154158
);
155159

156160
// A fuzzer with feedbacks and a corpus scheduler

fuzzers/libpng/libfuzzer_libpng_cmin/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,11 @@ fn fuzz(corpus_dirs: &[PathBuf], objective_dir: PathBuf, broker_port: u16) -> Re
150150
// A minimization+queue policy to get testcasess from the corpus
151151
let scheduler = IndexesLenTimeMinimizerScheduler::new(
152152
&edges_observer,
153-
StdWeightedScheduler::with_schedule(&mut state, &edges_observer, Some(PowerSchedule::FAST)),
153+
StdWeightedScheduler::with_schedule(
154+
&mut state,
155+
&edges_observer,
156+
Some(PowerSchedule::fast()),
157+
),
154158
);
155159

156160
// A fuzzer with feedbacks and a corpus scheduler

fuzzers/libpng/libfuzzer_libpng_tcp_manager/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,11 @@ fn fuzz(corpus_dirs: &[PathBuf], objective_dir: PathBuf, broker_port: u16) -> Re
148148
// A minimization+queue policy to get testcasess from the corpus
149149
let scheduler = IndexesLenTimeMinimizerScheduler::new(
150150
&edges_observer,
151-
StdWeightedScheduler::with_schedule(&mut state, &edges_observer, Some(PowerSchedule::FAST)),
151+
StdWeightedScheduler::with_schedule(
152+
&mut state,
153+
&edges_observer,
154+
Some(PowerSchedule::fast()),
155+
),
152156
);
153157

154158
// A fuzzer with feedbacks and a corpus scheduler

fuzzers/others/cargo_fuzz/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
#[allow(clippy::collapsible_if)]
12
pub fn do_thing(data: &[u8]) {
2-
if data.get(0) == Some(&b'a') {
3+
if data.first() == Some(&b'a') {
34
if data.get(1) == Some(&b'b') {
45
if data.get(2) == Some(&b'c') {
56
if data.get(3) == Some(&b'd') {

fuzzers/others/dynamic_analysis/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,11 @@ fn fuzz(
316316
// A minimization+queue policy to get testcasess from the corpus
317317
let scheduler = IndexesLenTimeMinimizerScheduler::new(
318318
&edges_observer,
319-
StdWeightedScheduler::with_schedule(&mut state, &edges_observer, Some(PowerSchedule::FAST)),
319+
StdWeightedScheduler::with_schedule(
320+
&mut state,
321+
&edges_observer,
322+
Some(PowerSchedule::fast()),
323+
),
320324
);
321325

322326
// A fuzzer with feedbacks and a corpus scheduler

fuzzers/others/libafl-fuzz/src/fuzzer.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use libafl::{
1414
mutators::{havoc_mutations, tokens_mutations, AFLppRedQueen, StdScheduledMutator, Tokens},
1515
observers::{CanTrack, HitcountsMapObserver, StdMapObserver, TimeObserver},
1616
schedulers::{
17-
powersched::PowerSchedule, IndexesLenTimeMinimizerScheduler, QueueScheduler,
18-
StdWeightedScheduler,
17+
powersched::{BaseSchedule, PowerSchedule},
18+
IndexesLenTimeMinimizerScheduler, QueueScheduler, StdWeightedScheduler,
1919
},
2020
stages::{
2121
mutational::MultiMutationalStage, CalibrationStage, ColorizationStage, IfStage,
@@ -183,7 +183,7 @@ where
183183
)
184184
};
185185
let mutational_stage = TimeTrackingStageWrapper::<FuzzTime, _, _>::new(inner_mutational_stage);
186-
let strategy = opt.power_schedule.unwrap_or(PowerSchedule::EXPLORE);
186+
let strategy = opt.power_schedule.unwrap_or(BaseSchedule::EXPLORE);
187187

188188
// Create our ColorizationStage
189189
let colorization = ColorizationStage::new(&edges_observer);
@@ -195,8 +195,9 @@ where
195195
if opt.sequential_queue {
196196
scheduler = SupportedSchedulers::Queue(QueueScheduler::new(), PhantomData);
197197
} else {
198+
let ps = PowerSchedule::new(strategy);
198199
let mut weighted_scheduler =
199-
StdWeightedScheduler::with_schedule(&mut state, &edges_observer, Some(strategy));
200+
StdWeightedScheduler::with_schedule(&mut state, &edges_observer, Some(ps));
200201
if opt.cycle_schedules {
201202
weighted_scheduler = weighted_scheduler.cycling_scheduler();
202203
}

fuzzers/others/libafl-fuzz/src/hooks.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ pub struct LibAflFuzzEventHook {
1010
exit_on_solution: bool,
1111
}
1212

13-
impl LibAflFuzzEventHook {
14-
pub fn new(exit_on_solution: bool) -> Self {
15-
Self { exit_on_solution }
16-
}
17-
}
18-
1913
impl<S> EventManagerHook<S> for LibAflFuzzEventHook
2014
where
2115
S: State + Stoppable,

fuzzers/others/libafl-fuzz/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use fuzzer::run_client;
2525
use libafl::{
2626
events::{CentralizedLauncher, EventConfig},
2727
monitors::MultiMonitor,
28-
schedulers::powersched::PowerSchedule,
28+
schedulers::powersched::BaseSchedule,
2929
Error,
3030
};
3131
use libafl_bolts::{
@@ -126,7 +126,7 @@ struct Opt {
126126
rng_seed: Option<u64>,
127127
/// power schedules compute a seed's performance score: explore(default), fast, exploit, seek, rare, mmopt, coe, lin
128128
#[arg(short = 'p')]
129-
power_schedule: Option<PowerSchedule>,
129+
power_schedule: Option<BaseSchedule>,
130130
/// enable `CmpLog` by specifying a binary compiled for it.
131131
#[arg(short = 'c')]
132132
cmplog: Option<String>,

fuzzers/others/libfuzzer_windows_asan/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,11 @@ fn fuzz(corpus_dirs: &[PathBuf], objective_dir: PathBuf, broker_port: u16) -> Re
117117
// A minimization+queue policy to get testcasess from the corpus
118118
let scheduler = IndexesLenTimeMinimizerScheduler::new(
119119
&edges_observer,
120-
StdWeightedScheduler::with_schedule(&mut state, &edges_observer, Some(PowerSchedule::FAST)),
120+
StdWeightedScheduler::with_schedule(
121+
&mut state,
122+
&edges_observer,
123+
Some(PowerSchedule::fast()),
124+
),
121125
);
122126

123127
// A fuzzer with feedbacks and a corpus scheduler

fuzzers/others/tutorial/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ fn fuzz(corpus_dirs: &[PathBuf], objective_dir: PathBuf, broker_port: u16) -> Re
135135
// A minimization+queue policy to get testcasess from the corpus
136136
let scheduler = PacketLenMinimizerScheduler::new(
137137
&edges_observer,
138-
PowerQueueScheduler::new(&mut state, &edges_observer, PowerSchedule::FAST),
138+
PowerQueueScheduler::new(&mut state, &edges_observer, PowerSchedule::fast()),
139139
);
140140

141141
// A fuzzer with feedbacks and a corpus scheduler

fuzzers/qemu/qemu_launcher/src/instance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl<'a, M: Monitor> Instance<'a, M> {
127127
// A minimization+queue policy to get testcasess from the corpus
128128
let scheduler = IndexesLenTimeMinimizerScheduler::new(
129129
&edges_observer,
130-
PowerQueueScheduler::new(&mut state, &edges_observer, PowerSchedule::FAST),
130+
PowerQueueScheduler::new(&mut state, &edges_observer, PowerSchedule::fast()),
131131
);
132132

133133
let observers = tuple_list!(edges_observer, time_observer);

libafl/src/executors/forkserver.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ impl Forkserver {
309309
memlimit: u64,
310310
is_persistent: bool,
311311
is_deferred_frksrv: bool,
312+
coverage_map_size: Option<usize>,
312313
debug_output: bool,
313314
) -> Result<Self, Error> {
314315
Self::with_kill_signal(
@@ -320,6 +321,7 @@ impl Forkserver {
320321
memlimit,
321322
is_persistent,
322323
is_deferred_frksrv,
324+
coverage_map_size,
323325
debug_output,
324326
KILL_SIGNAL_DEFAULT,
325327
)
@@ -338,15 +340,20 @@ impl Forkserver {
338340
memlimit: u64,
339341
is_persistent: bool,
340342
is_deferred_frksrv: bool,
343+
coverage_map_size: Option<usize>,
341344
debug_output: bool,
342345
kill_signal: Signal,
343346
) -> Result<Self, Error> {
347+
let Some(coverage_map_size) = coverage_map_size else {
348+
return Err(Error::unknown("Coverage map size unknown. Use coverage_map_size() to tell the forkserver about the map size."));
349+
};
350+
344351
if env::var("AFL_MAP_SIZE").is_err() {
345352
log::warn!("AFL_MAP_SIZE not set. If it is unset, the forkserver may fail to start up");
346353
}
347354

348355
if env::var("__AFL_SHM_ID").is_err() {
349-
log::warn!("__AFL_SHM_ID not set. It is necessary to set this env, otherwise the forkserver cannot communicate with the fuzzer");
356+
return Err(Error::unknown("__AFL_SHM_ID not set. It is necessary to set this env, otherwise the forkserver cannot communicate with the fuzzer".to_string()));
350357
}
351358

352359
let mut st_pipe = Pipe::new().unwrap();
@@ -366,6 +373,8 @@ impl Forkserver {
366373
.stdout(stdout)
367374
.stderr(stderr);
368375

376+
command.env("AFL_MAP_SIZE", format!("{coverage_map_size}"));
377+
369378
// Persistent, deferred forkserver
370379
if is_persistent {
371380
command.env("__AFL_PERSISTENT", "1");
@@ -813,6 +822,7 @@ where
813822
0,
814823
self.is_persistent,
815824
self.is_deferred_frksrv,
825+
self.map_size,
816826
self.debug_child,
817827
self.kill_signal.unwrap_or(KILL_SIGNAL_DEFAULT),
818828
)?,
@@ -1515,6 +1525,7 @@ mod tests {
15151525
let executor = ForkserverExecutor::builder()
15161526
.program(bin)
15171527
.args(args)
1528+
.coverage_map_size(MAP_SIZE)
15181529
.debug_child(false)
15191530
.shmem_provider(&mut shmem_provider)
15201531
.build::<_, ()>(tuple_list!(edges_observer));

libafl/src/executors/inprocess_fork/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ pub mod child_signal_handlers {
366366
}
367367

368368
#[cfg(test)]
369+
#[cfg(all(feature = "std", feature = "fork", unix))]
369370
mod tests {
370371
use libafl_bolts::tuples::tuple_list;
371372
use serial_test::serial;
@@ -378,7 +379,6 @@ mod tests {
378379
#[test]
379380
#[serial]
380381
#[cfg_attr(miri, ignore)]
381-
#[cfg(all(feature = "std", feature = "fork", unix))]
382382
fn test_inprocessfork_exec() {
383383
use core::marker::PhantomData;
384384

libafl/src/monitors/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,11 @@ fn prettify_float(value: f64) -> String {
318318
value => (value, ""),
319319
};
320320
match value {
321+
value if value >= 1000000.0 => {
322+
format!("{value:.2}{suffix}")
323+
}
321324
value if value >= 1000.0 => {
322-
format!("{value}{suffix}")
325+
format!("{value:.1}{suffix}")
323326
}
324327
value if value >= 100.0 => {
325328
format!("{value:.1}{suffix}")

0 commit comments

Comments
 (0)