Skip to content

Commit b92a965

Browse files
committed
Implement AFL persistent exit for mips
This adds support for the AFL_QEMU_PERSISTENT_EXITS environment variable inside MIPS programs. The code mostly is taken from the other architecture's `cpu_loop.c` files. I've further added a test to see if the system call number is `TARGET_NR_exit`. The embedded target I've used AFL++ on does not use the more common `exit_group` system call. `exit()` in uclibc uses the exit system call. See the `uclibc-ng` version 1.0.6 source here: https://elixir.bootlin.com/uclibc-ng/v1.0.6/source/libc/sysdeps/linux/common/_exit.c#L28 I've tested this functionality by writing a C program that calls `exit(0)` at the end of its `main()` function. When you run afl-fuzz, it correctly recognizes the end of the loop and restarts. You can also run qemu with `AFL_QEMU_PERSISTENT_ADDR` and `AFL_QEMU_PERSISTENT_EXITS` set directly. QEMU returns to the starting point when the program calls `exit(0)`. This is a small C program, inspired by `test-instr.c` that you can use to verify the behavior: ``` int main(int argc, char **argv) { int cnt; char buff[8]; fgets(buff, sizeof(buff) - 1, stdin); buff[sizeof(buff) - 1] = 0; printf("Looks like a %s to me!\n", buff); exit(0); return 0; } ```
1 parent ef1cd9a commit b92a965

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

linux-user/mips/cpu_loop.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ void cpu_loop(CPUMIPSState *env)
8484

8585
switch(trapnr) {
8686
case EXCP_SYSCALL:
87+
if (
88+
persistent_exits &&
89+
(
90+
env->active_tc.gpr[2] == TARGET_NR_exit_group ||
91+
// uclibc may use the following signal instead of
92+
// exit_group:
93+
env->active_tc.gpr[2] == TARGET_NR_exit
94+
)
95+
) {
96+
env->active_tc.PC = afl_persistent_addr;
97+
continue;
98+
}
8799
env->active_tc.PC += 4;
88100
# ifdef TARGET_ABI_MIPSO32
89101
syscall_num = env->active_tc.gpr[2] - 4000;

0 commit comments

Comments
 (0)