Disallow magic SysRq key
An XCCDF Rule
Description
To set the runtime status of the kernel.sysrq
kernel parameter, run the following command:
$ sudo sysctl -w kernel.sysrq=0To make sure that the setting is persistent, add the following line to a file in the directory
/etc/sysctl.d
: kernel.sysrq = 0
Rationale
The Magic SysRq key allows sending certain commands directly to the running kernel. It can dump various system and process information, potentially revealing sensitive information. It can also reboot or shutdown the machine, disturbing its availability.
- ID
- xccdf_org.ssgproject.content_rule_sysctl_kernel_sysrq
- Severity
- Medium
- References
- Updated
Remediation - Ansible
- name: List /etc/sysctl.d/*.conf files
find:
paths:
- /etc/sysctl.d/
- /run/sysctl.d/
- /usr/local/lib/sysctl.d/
Remediation - Shell Script
# Remediation is applicable only in certain platforms
if [ ! -f /.dockerenv ] && [ ! -f /run/.containerenv ]; then
# Comment out any occurrences of kernel.sysrq from /etc/sysctl.d/*.conf files
for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf; do