AFL_FORK_SERVER_KILL_SIGNAL backwards compatiblity

If `AFL_KILL_SIGNAL` is set, `AFL_FORK_SERVER_KILL_SIGNAL` is set
to the same value.
This commit is contained in:
Nils Bars
2022-10-24 17:52:04 +02:00
parent 7512316b46
commit 102b749c07
7 changed files with 40 additions and 16 deletions

View File

@ -418,6 +418,10 @@ checks or alter some of the more exotic semantics of the tool:
fork server when AFL++ is terminated. Unless you implement your fork server when AFL++ is terminated. Unless you implement your
fork server, you likely do not have to set it. By default, `SIGTERM` fork server, you likely do not have to set it. By default, `SIGTERM`
(`AFL_FORK_SERVER_KILL_SIGNAL=15`) will be delivered to the fork server. (`AFL_FORK_SERVER_KILL_SIGNAL=15`) will be delivered to the fork server.
If only `AFL_KILL_SIGNAL` is provided, `AFL_FORK_SERVER_KILL_SIGNAL` will
be set to same value as `AFL_KILL_SIGNAL` to provide backward compatibility.
If `AFL_FORK_SERVER_KILL_SIGNAL` is also set, it takes precedence.
NOTE: Uncatchable signals, such as `SIGKILL`, cause child processes of NOTE: Uncatchable signals, such as `SIGKILL`, cause child processes of
the fork server to be orphaned and leaves them in a zombie state. the fork server to be orphaned and leaves them in a zombie state.

View File

@ -32,6 +32,7 @@
#include <unistd.h> #include <unistd.h>
#include <sys/time.h> #include <sys/time.h>
#include <stdbool.h> #include <stdbool.h>
#include "forkserver.h"
#include "types.h" #include "types.h"
/* STRINGIFY_VAL_SIZE_MAX will fit all stringify_ strings. */ /* STRINGIFY_VAL_SIZE_MAX will fit all stringify_ strings. */
@ -73,6 +74,11 @@ u8 *find_afl_binary(u8 *own_loc, u8 *fname);
FATALs if `numeric_signal_as_str` is not a valid integer .*/ FATALs if `numeric_signal_as_str` is not a valid integer .*/
int parse_afl_kill_signal(u8 *numeric_signal_as_str, int default_signal); int parse_afl_kill_signal(u8 *numeric_signal_as_str, int default_signal);
/* Configure the signals that are used to kill the forkserver
and the forked childs. If `afl_kill_signal_env` or `afl_fsrv_kill_signal_env`
is NULL, the appropiate values are read from the environment. */
void configure_afl_kill_signals(afl_forkserver_t *fsrv, char* afl_kill_signal_env, char* afl_fsrv_kill_signal_env);
/* Read a bitmap from file fname to memory /* Read a bitmap from file fname to memory
This is for the -B option again. */ This is for the -B option again. */

View File

@ -1115,10 +1115,7 @@ int main(int argc, char **argv_orig, char **envp) {
} }
fsrv.child_kill_signal = configure_afl_kill_signals(&fsrv, NULL, NULL);
parse_afl_kill_signal(getenv("AFL_KILL_SIGNAL"), SIGKILL);
fsrv.fsrv_kill_signal =
parse_afl_kill_signal(getenv("AFL_FORK_SERVER_KILL_SIGNAL"), SIGTERM);
read_initial_file(); read_initial_file();

View File

@ -25,6 +25,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "forkserver.h"
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
#define _GNU_SOURCE #define _GNU_SOURCE
#endif #endif
@ -47,6 +48,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <signal.h>
u8 be_quiet = 0; u8 be_quiet = 0;
u8 *doc_path = ""; u8 *doc_path = "";
@ -476,6 +478,27 @@ int parse_afl_kill_signal(u8 *numeric_signal_as_str, int default_signal) {
return default_signal; return default_signal;
} }
void configure_afl_kill_signals(afl_forkserver_t *fsrv, char* afl_kill_signal_env, char* afl_fsrv_kill_signal_env) {
afl_kill_signal_env = afl_kill_signal_env ?
afl_kill_signal_env : getenv("AFL_KILL_SIGNAL");
afl_fsrv_kill_signal_env = afl_fsrv_kill_signal_env ?
afl_fsrv_kill_signal_env : getenv("AFL_FORK_SERVER_KILL_SIGNAL");
fsrv->child_kill_signal =
parse_afl_kill_signal(afl_kill_signal_env, SIGKILL);
if (afl_kill_signal_env && !afl_fsrv_kill_signal_env) {
/*
Set AFL_FORK_SERVER_KILL_SIGNAL to the value of AFL_KILL_SIGNAL for backwards
compatibility. However, if AFL_FORK_SERVER_KILL_SIGNAL is set, is takes precedence.
*/
afl_fsrv_kill_signal_env = afl_kill_signal_env;
}
fsrv->fsrv_kill_signal =
parse_afl_kill_signal(afl_fsrv_kill_signal_env, SIGTERM);
}
static inline unsigned int helper_min3(unsigned int a, unsigned int b, static inline unsigned int helper_min3(unsigned int a, unsigned int b,
unsigned int c) { unsigned int c) {

View File

@ -25,6 +25,7 @@
#include "afl-fuzz.h" #include "afl-fuzz.h"
#include "cmplog.h" #include "cmplog.h"
#include "common.h"
#include <limits.h> #include <limits.h>
#include <stdlib.h> #include <stdlib.h>
#ifndef USEMMAP #ifndef USEMMAP
@ -1358,10 +1359,9 @@ int main(int argc, char **argv_orig, char **envp) {
#endif #endif
afl->fsrv.child_kill_signal = configure_afl_kill_signals(&afl->fsrv,
parse_afl_kill_signal(afl->afl_env.afl_child_kill_signal, SIGKILL); afl->afl_env.afl_child_kill_signal,
afl->fsrv.fsrv_kill_signal = afl->afl_env.afl_fsrv_kill_signal);
parse_afl_kill_signal(afl->afl_env.afl_fsrv_kill_signal, SIGTERM);
setup_signal_handlers(); setup_signal_handlers();
check_asan_opts(afl); check_asan_opts(afl);

View File

@ -1260,10 +1260,7 @@ int main(int argc, char **argv_orig, char **envp) {
: 0); : 0);
be_quiet = save_be_quiet; be_quiet = save_be_quiet;
fsrv->child_kill_signal = configure_afl_kill_signals(fsrv, NULL, NULL);
parse_afl_kill_signal(getenv("AFL_KILL_SIGNAL"), SIGKILL);
fsrv->fsrv_kill_signal =
parse_afl_kill_signal(getenv("AFL_FORK_SERVER_KILL_SIGNAL"), SIGTERM);
if (new_map_size) { if (new_map_size) {

View File

@ -1197,10 +1197,7 @@ int main(int argc, char **argv_orig, char **envp) {
} }
fsrv->child_kill_signal = configure_afl_kill_signals(fsrv, NULL, NULL);
parse_afl_kill_signal(getenv("AFL_KILL_SIGNAL"), SIGKILL);
fsrv->fsrv_kill_signal =
parse_afl_kill_signal(getenv("AFL_FORK_SERVER_KILL_SIGNAL"), SIGTERM);
if (getenv("AFL_CRASH_EXITCODE")) { if (getenv("AFL_CRASH_EXITCODE")) {