ocurrent / bun

tired of typing afl-fuzz? try bun!
MIT License
50 stars 10 forks source link

Clean up after leftover AFL processes #16

Open edwintorok opened 4 years ago

edwintorok commented 4 years ago

In permanent mode AFL leaves some processes behind: https://github.com/yomimono/ocaml-bun/issues/14#issuecomment-690761957

This is partly due to bun using proc#terminate (SIGKILL), but even with SIGTERM there are race conditions in AFL and some processes stay behind: https://groups.google.com/d/topic/afl-users/E37s4YDti7o

This can observed by just doing a 'dune runtest' in bun itself, and then ps -ef|grep short.exe on a multicore machine.

The permanent mode processes stop themselves with SIGSTOP and wait for their afl parent to unblock them, but their afl parent exits, so they stay around forever. Which wouldn't be a problem, except for afl-gotcpu which detect that these processes are around and refuses to start more fuzzing jobs. The processes' parent pid, gid and sid is unrelated to bun or the afl fuzzer processes (afl/forkserver does a setsid call), so we have no easy way of finding these processes.

Use cgroups when available to kill child processes reliably: this allows us to easily find all the pids of (grand)children.

Fixes https://github.com/yomimono/ocaml-bun/issues/14