xref: /aosp_15_r20/external/AFLplusplus/afl-system-config (revision 08b48e0b10e97b33e7b60c5b6e2243bd915777f2)
1#!/bin/sh
2test "$1" = "-h" -o "$1" = "-hh" -o "$1" = "--help" && {
3  echo 'afl-system-config by Marc Heuse <[email protected]>'
4  echo
5  echo $0
6  echo
7  echo afl-system-config has no command line options
8  echo
9  echo afl-system-config reconfigures the system to a high performance fuzzing state.
10  echo "WARNING: this reduces the security of the system!"
11  echo
12  echo Note that there is also afl-persistent-config which sets additional permanent
13  echo configuration options.
14  exit 0
15}
16if [ $# -ne 0 ]; then
17  echo "ERROR: Unknown option(s): $@"
18  exit 1
19fi
20
21DONE=
22PLATFORM=`uname -s`
23echo This reconfigures the system to have a better fuzzing performance.
24echo "WARNING: this reduces the security of the system!"
25echo
26if [ '!' "$EUID" = 0 ] && [ '!' `id -u` = 0 ] ; then
27	echo "Warning: you need to be root to run this!"
28	sleep 1
29	# we do not exit as other mechanisms exist that allows to do this than
30	# being root. let the errors speak for themselves.
31fi
32sleep 1
33if [ "$PLATFORM" = "Linux" ] ; then
34{
35  sysctl -w kernel.core_uses_pid=0
36  # Arch Linux requires core_pattern to be empty :(
37  test -e /etc/arch-release && sysctl -w kernel.core_pattern=
38  test -e /etc/arch-release || sysctl -w kernel.core_pattern=core
39  sysctl -w kernel.randomize_va_space=0
40  sysctl -w kernel.sched_child_runs_first=1
41  sysctl -w kernel.sched_autogroup_enabled=1
42  sysctl -w kernel.sched_migration_cost_ns=50000000 2>/dev/null
43  sysctl -w kernel.sched_latency_ns=250000000 2>/dev/null
44  echo never > /sys/kernel/mm/transparent_hugepage/enabled
45  test -e /sys/devices/system/cpu/cpufreq/scaling_governor && echo performance | tee /sys/devices/system/cpu/cpufreq/scaling_governor
46  test -e /sys/devices/system/cpu/cpufreq/policy0/scaling_governor && echo performance | tee /sys/devices/system/cpu/cpufreq/policy*/scaling_governor
47  test -e /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor && echo performance | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
48  test -e /sys/devices/system/cpu/intel_pstate/no_turbo && echo 0 > /sys/devices/system/cpu/intel_pstate/no_turbo
49  test -e /sys/devices/system/cpu/cpufreq/boost && echo 1 > /sys/devices/system/cpu/cpufreq/boost
50  test -e /sys/devices/system/cpu/intel_pstate/max_perf_pct && echo 100 > /sys/devices/system/cpu/intel_pstate/max_perf_pct
51  test -n "$(which auditctl)" && auditctl -a never,task >/dev/null 2>&1
52} > /dev/null
53  echo Settings applied.
54  echo
55  dmesg | grep -E -q 'noibrs pcid nopti' || {
56    echo It is recommended to boot the kernel with lots of security off - if you are running a machine that is in a secured network - so set this:
57    echo '  /etc/default/grub:GRUB_CMDLINE_LINUX_DEFAULT="ibpb=off ibrs=off kpti=0 l1tf=off mds=off mitigations=off no_stf_barrier noibpb noibrs pcid nopti nospec_store_bypass_disable nospectre_v1 nospectre_v2 pcid=on pti=off spec_store_bypass_disable=off spectre_v2=off stf_barrier=off srbds=off noexec=off noexec32=off tsx=on tsx_async_abort=off arm64.nopauth audit=0 hardened_usercopy=off ssbd=force-off"'
58    echo
59  }
60  echo If you run fuzzing instances in docker, run them with \"--security-opt seccomp=unconfined\" for more speed.
61  echo
62  DONE=1
63fi
64if [ "$PLATFORM" = "FreeBSD" ] ; then
65{
66  sysctl kern.elf32.aslr.enable=0
67  sysctl kern.elf64.aslr.enable=0
68} > /dev/null
69  echo Settings applied.
70  echo
71  cat <<EOF
72In order to suppress core file generation during fuzzing it is recommended to set
73me:\\
74	:coredumpsize=0:
75in the ~/.login_conf file for the user used for fuzzing.
76EOF
77  echo It is recommended to boot the kernel with lots of security off - if you are running a machine that is in a secured network - so set this:
78  echo '  sysctl hw.ibrs_disable=1'
79  echo 'Setting kern.pmap.pg_ps_enabled=0 into /boot/loader.conf might be helpful too.'
80  echo
81  DONE=1
82fi
83if [ "$PLATFORM" = "OpenBSD" ] ; then
84  doas sysctl vm.malloc_conf=
85  echo 'Freecheck on allocation in particular can be detrimental to performance.'
86  echo 'Also we might not want necessarily to abort at any allocation failure.'
87  echo 'System security features cannot be disabled on OpenBSD.'
88  echo
89  DONE=1
90fi
91if [ "$PLATFORM" = "DragonFly" ] ; then
92  #/sbin/sysctl kern.corefile=/dev/null
93  #echo Settings applied.
94  cat <<EOF
95In order to suppress core file generation during fuzzing it is recommended to set
96me:\\
97	:coredumpsize=0:
98in the ~/.login_conf file for the user used for fuzzing.
99EOF
100  echo
101  DONE=1
102fi
103if [ "$PLATFORM" = "NetBSD" ] ; then
104{
105  /sbin/sysctl -w security.models.extensions.user_set_cpu_affinity=1
106} > /dev/null
107  echo Settings applied.
108  echo
109  DONE=1
110fi
111if [ "$PLATFORM" = "Darwin" ] ; then
112  sysctl kern.sysv.shmmax=524288000
113  sysctl kern.sysv.shmmin=1
114  sysctl kern.sysv.shmseg=48
115  sysctl kern.sysv.shmall=131072000
116  echo Settings applied.
117  echo
118  if $(launchctl list 2>/dev/null | grep -q '\.ReportCrash\>') ; then
119    echo
120    echo Unloading the default crash reporter
121    SL=/System/Library; PL=com.apple.ReportCrash
122    sudo -u "$SUDO_USER" launchctl unload -w ${SL}/LaunchAgents/${PL}.plist
123    launchctl unload -w ${SL}/LaunchDaemons/${PL}.Root.plist
124    echo
125  fi
126  echo It is recommended to disable System Integrity Protection for increased performance.
127  echo See: https://developer.apple.com/documentation/security/disabling_and_enabling_system_integrity_protection
128  echo
129  DONE=1
130fi
131if [ "$PLATFORM" = "Haiku" ] ; then
132  DEBUG_SERVER_DIR=~/config/settings/system/debug_server
133  [ ! -d ${DEBUG_SERVER_DIR} ] && mkdir -p ${DEBUG_SERVER_DIR}
134  SETTINGS=${DEBUG_SERVER_DIR}/settings
135  [ -r ${SETTINGS} ] && grep -qE "default_action\s+kill" ${SETTINGS} && { echo "Nothing to do"; } || { \
136    echo We change the debug_server default_action from user to silently kill; \
137    [ ! -r ${SETTINGS} ] && echo "default_action kill" >${SETTINGS} || { mv ${SETTINGS} s.tmp; sed -e "s/default_action\s\s*user/default_action kill/" s.tmp > ${SETTINGS}; rm s.tmp; }; \
138    echo Settings applied.; echo; \
139  }
140  DONE=1
141fi
142test -z "$DONE" && echo Error: Unknown platform: $PLATFORM
143exit 0
144