398 Commits

Author SHA1 Message Date
Justus Perlwitz
ee480aeb7a Enable qemu persistent mode tests for mipsel
qemuafl now supports persistent mode for *mipsel* targets. This patch
changes the `SYS` variable tests and runs the persistent qemu_mode
tests for *mipsel* as well.

This also adds an optional environment variable called `CPU_TARGET_CC`
that you can pass to the `./test-qemu-mode.sh` test script.

This allows you to specify a cross-compiler for the target platform. The
test script then it uses to compile `test-instr.c` and `test-compcov.c`.

Example usage:

```
CPU_TARGET_CC=mipsel-linux-gnu-cc CPU_TARGET=mipsel ./test-qemu-mode.sh
```

The output should look something like this:

```
[*] Using environment variable CPU_TARGET=mipsel for SYS
[*] starting AFL++ test framework ...
[*] Testing: qemu_mode
[*] Using mipsel-linux-gnu-cc as compiler for target
[*] running afl-fuzz for qemu_mode, this will take approx 10 seconds
[+] afl-fuzz is working correctly with qemu_mode
[*] running afl-fuzz for qemu_mode AFL_ENTRYPOINT, this will take approx 6 seconds
[+] afl-fuzz is working correctly with qemu_mode AFL_ENTRYPOINT
[-] not an intel or arm platform, cannot test qemu_mode compcov
[-] not an intel or arm platform, cannot test qemu_mode cmplog
[*] running afl-fuzz for persistent qemu_mode, this will take approx 10 seconds
[+] afl-fuzz is working correctly with persistent qemu_mode
[+] persistent qemu_mode was noticeable faster than standard qemu_mode
[*] running afl-fuzz for persistent qemu_mode with AFL_QEMU_PERSISTENT_EXITS, this will take approx 10 seconds
[+] afl-fuzz is working correctly with persistent qemu_mode and AFL_QEMU_PERSISTENT_EXITS
[+] persistent qemu_mode with AFL_QEMU_PERSISTENT_EXITS was noticeable faster than standard qemu_mode
[-] we cannot test qemu_mode unsigaction library (32 bit) because it is not present
[+] qemu_mode unsigaction library (64 bit) ignores signals
[*] 1 test cases completed.
[-] not all test cases were executed
[+] all tests were successful :-)
```
2025-06-05 09:51:55 +09:00
Justus Perlwitz
91974bfae2 Clean up test-pre.sh bash syntax
shellcheck pointed out a few command substition (backtick vs. $(...))
and quoting issues. This patch fixes them.
2025-06-04 09:33:03 +09:00
Justus Perlwitz
8618fbc0c2 Let user pass their own CPU_TARGET in test-pre.sh
The target system might be different from the host system. For example,
you can fuzz Linux binaries compiled for *mipsel*, while your host is
*x86_64*.

Some of the tests depend on specific platforms to run correctly.
For example, the afl-fuzz qemu_mode cmplog test only works on Intel or
ARM systems. The `SYS` variable is populated using `uname -m` and the
test cases then consult this variable to decide whether to run the test
or not.

If you want to test afl-fuzz for qemu_mode on mipsel, you might
want to make sure that Intel or ARM tests don't run. With this
patch, you can supply your own `CPU_TARGET` environment variable and skip
platform specific tests. `SYS` then contains the value of `CPU_TARGET`.

This allows you to add tests for *mipsel* or other niche platforms in
the future as well.

Sample usage:

```
$ cd qemu_mode && env CPU_TARGET=mipsel ./build_qemu_support.sh
$ cd ../test && env CPU_TARGET=mipsel ./test-qemu-mode.sh
[*] Using environment variable CPU_TARGET=mipsel for SYS
[*] starting AFL++ test framework ...
[*] Testing: qemu_mode
...
```
2025-06-04 09:31:13 +09:00
Justus Perlwitz
b418a87340 Add test case for AFL_QEMU_PERSISTENT_EXITS
Add a test case to `test/test-qemu-mode.sh` and make sure that
AFL_QEMU_PERSISTENT_EXITS loops correctly.

This works only on platforms for which `afl-qemu-trace` detects exit
signals and resets the program counter.

This commit updates `test-instr.c` to optionally call `exit(n)` instead of
returning n to the operating system. This option can be activated using
the `EXIT_AT_END` flag. This way, we can test the
QEMU persistent exit mode without having to add a new test file.

You can compile and run `test-instr.c` with the exit mode like so:

```bash
gcc -o exit -DEXIT_AT_END test-instr.c
AFL_QEMU_DEBUG_MAPS= \
    AFL_DEBUG= \
    AFL_QEMU_PERSISTENT_ADDR=$(readelf -a exit | grep 'main$' | awk '{ printf "0x%s", $2 }') \
    AFL_QEMU_PERSISTENT_GPR=1 \
    AFL_QEMU_PERSISTENT_EXITS=1 \
    ./afl-qemu-trace exit
```

Press enter repeatedly and you will see an output like this:

```
...
Debug: Sending status 0xc201ffff

test-instr:

Neither one or zero? How quaint!

test-instr:

Neither one or zero? How quaint!

test-instr:

Neither one or zero? How quaint!

test-instr:

Neither one or zero? How quaint!

test-instr:

Neither one or zero? How quaint!
```

To make sure that persistent exits are detected correctly on x86_64, I've made
the following changes to qemuafl:

```
 linux-user/i386/cpu_loop.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c
index 4509f46b95..46bdbaf94a 100644
--- a/linux-user/i386/cpu_loop.c
+++ b/linux-user/i386/cpu_loop.c
@@ -235,7 +235,7 @@ void cpu_loop(CPUX86State *env)
 #ifndef TARGET_ABI32
         case EXCP_SYSCALL:
             /* linux syscall from syscall instruction */
-            if (afl_fork_child && persistent_exits &&
+            if (persistent_exits &&
                 env->regs[R_EAX] == TARGET_NR_exit_group) {
               env->eip = afl_persistent_addr;
               continue;
```
2025-05-02 15:13:08 +09:00
David Robillard
7765d4ac33
Fix various spelling errors (#2293)
* Fix spelling errors in log messages

* Fix doc comment syntax

* Fix spelling errors in Markdown documentation

* Fix spelling errors in comments
2025-02-10 00:32:42 +01:00
vanhauser-thc
635cd7374e fix unicorn test 2025-01-16 15:48:04 +01:00
vanhauser-thc
f2f417325f fix gcc plugin test 2024-12-15 18:06:02 +01:00
vanhauser-thc
7b24f4a329 remove afl-gcc/afl-clang 2024-11-21 14:31:36 +01:00
vanhauser-thc
701e89bbcd fixes 2024-11-21 10:39:49 +01:00
Samuel Moelius
6a28502191 Adjust cmplog test to use AFL_SHA1_FILENAMES=1 2024-09-12 10:05:23 -04:00
aarnav
db84f75a81 remove deprecated -d option in unicorn CI test 2024-08-14 13:45:10 +02:00
aarnav
9111035495 fix incorrect check for unicorn CI 2024-08-14 13:44:44 +02:00
vanhauser-thc
d1a7b6988c update timeout for custom mutator tests 2024-07-08 09:46:51 +02:00
vanhauser-thc
0a16ea7487 better cmplog ci test for low memory machines 2024-05-15 10:57:46 +02:00
vanhauser-thc
a87ea96913 make slow systems pass our test suite 2024-05-14 12:58:45 +02:00
vanhauser-thc
b282ce999d post_process after trim 2024-05-13 13:42:58 +02:00
vanhauser-thc
07bc202e0a fixes 2024-02-09 13:51:05 +01:00
vanhauser-thc
c77709cdd9 add U256/32byte support 2024-02-04 16:03:12 +01:00
vanhauser-thc
5ba66a8860 final touches for skipdet 2024-02-01 15:22:51 +01:00
vanhauser-thc
d8e8d34c4e fix ci 2024-02-01 14:34:07 +01:00
vanhauser-thc
96ada75bd9 debug ci 2024-02-01 14:18:36 +01:00
vanhauser-thc
5549212d9e clean test script 2024-02-01 12:59:37 +01:00
vanhauser-thc
236fb9b145 debug ci 2024-02-01 12:03:02 +01:00
vanhauser-thc
97ba817aa7 debug ci 2024-02-01 09:56:31 +01:00
vanhauser-thc
6e6d91b6b0 debug ci 2024-02-01 09:23:01 +01:00
vanhauser-thc
123ec5d136 debug ci 2024-02-01 09:06:34 +01:00
vanhauser-thc
5da5d6e0df debug ci 2024-02-01 08:48:41 +01:00
vanhauser-thc
970e0b14ce debug ci 2024-02-01 08:13:52 +01:00
vanhauser-thc
3768933c92 debug ci 2024-01-31 17:43:37 +01:00
vanhauser-thc
da5d3d63e2 test error output 2024-01-31 17:00:04 +01:00
vanhauser-thc
9604fe922e nyx test for CI 2024-01-30 15:06:34 +01:00
vanhauser-thc
227c1a7002 improve compiler test script 2024-01-23 19:55:35 +01:00
vanhauser-thc
de561b730a add compiler test script 2024-01-19 12:20:33 +01:00
vanhauser-thc
a518c4d75c macos 2024-01-19 11:53:44 +01:00
mark0
bd1648e707 fix the file descriptor without determining null 2023-07-28 17:32:59 +08:00
vanhauser-thc
a46d27fad5 nits 2023-07-10 18:29:21 +02:00
vanhauser-thc
6e5ca0c78c higher tuples for afl-clang and afl-gcc in tests 2023-07-06 14:28:37 +02:00
vanhauser-thc
f0ccca123a fix ci 2023-06-06 17:32:32 +02:00
vanhauser-thc
62bacf4fc8 better cmplog ci 2023-06-06 16:45:20 +02:00
vanhauser-thc
ee2cab73ac reduce false positive ci failures 2023-06-06 16:42:52 +02:00
vanhauser-thc
6cad585bdc nits 2023-04-27 18:57:28 +02:00
vanhauser-thc
3e84d6a2ae afl++ -> AFL++ 2023-04-27 11:49:00 +02:00
Yaakov Saxon
50678ed369
Fixing typo: & (background) to && (and) 2023-04-14 11:24:10 -04:00
vanhauser-thc
01236f47bc nits 2023-03-28 16:50:05 +02:00
vanhauser-thc
19f9612910 fix frida mode 2023-03-26 12:14:35 +02:00
vanhauser-thc
9bc5abc4ec reduce CI resources 2023-03-25 12:14:08 +01:00
vanhauser-thc
478f0bbc1e ci test 2023-03-21 16:23:51 +01:00
vanhauser-thc
4c7c78d926 enhance tests for macos 2023-03-10 10:59:52 +01:00
vanhauser-thc
aabfe781fd enhance tests for macos 2023-03-10 10:22:35 +01:00
vanhauser-thc
e0866f51c7 support LLVMFuzzerTestOneInput -1 return 2023-03-09 13:57:03 +01:00