1.5.1 Ensure randomize_va_space is configured

Information

Address space layout randomization (ASLR) is an exploit mitigation technique which randomly arranges the address space of key data areas of a process.

Randomly placing virtual memory regions will make it difficult to write memory page exploits as the memory placement will be consistently shifting.

Solution

- Review all files ending in .conf in the /etc/sysctl.d directory and comment out or remove all kernel.randomize_va_space lines that are not kernel.randomize_va_spacee=2.

Example script:

#!/usr/bin/env bash

{
l_option="kernel.randomize_va_space" l_grep="${l_option//./\\.}" l_value="2"
while IFS= read -r -d $'\0' l_file; do
grep -Poi '\h*'"$l_option"'\h*=\h*\H+\b' "$l_file" \
| grep -Pivq '^\h*'"$l_grep"'\h*=\h*'"$l_value"'\b' && \
sed -ri '/^\s*kernel.yama.ptrace_scope\s*=/s/^/# /' "$l_file"
done < <(find /etc/sysctl.d/ -type f -name '*.conf' -print0)
}
- Create or edit a file in the /etc/sysctl.d/ directory ending in .conf and edit or add the following line:

kernel.randomize_va_space = 2

Example:

# [ ! -d "/etc/sysctl.d/" ] && mkdir -p /etc/sysctl.d/
# printf '%s\n' "" "kernel.randomize_va_space = 2" >> /etc/sysctl.d/60-kernel_sysctl.conf
- Run the following command to load all system configuration filles:

# sysctl --system

See Also

https://workbench.cisecurity.org/benchmarks/24330

Item Details

Category: SYSTEM AND INFORMATION INTEGRITY

References: 800-53|SI-16, CCI|CCI-002824, CSCv7|8.3, Rule-ID|SV-230280r1017093_rule, Rule-ID|SV-234862r958928_rule, Rule-ID|SV-257809r1044866_rule, Rule-ID|SV-260474r958928_rule, Rule-ID|SV-269452r1050335_rule, Rule-ID|SV-270772r1066805_rule, STIG-ID|ALMA-09-044900, STIG-ID|RHEL-08-010430, STIG-ID|RHEL-09-213070, STIG-ID|SLES-15-010550, STIG-ID|UBTU-22-213020, STIG-ID|UBTU-24-700310

Plugin: Unix

Control ID: 152b2bd976f59480f1a8c0296491f3040d96be61a32a5bb21e1d82a398f813e8