TMAegisBeta
More rules for linux

Linux distributions

TMA-ROCKY9-1.5.1

Ensure fs.protected_hardlinks is configured

MediumLevel 1Automatedlinux

Description

fs.protected_hardlinks Controls the creation of hard links to files. More information about the kernel parameter configuration files, their location, and load preference is available in the section overview.

How it is checked

Audit method: Shell command

shell
chk() { p=$1; allowed=" $2 "; case $p in net.ipv6.*) [ -d /proc/sys/net/ipv6 ] || return 0;; esac; v=$(sysctl -n "$p" 2>/dev/null) || { echo "$p: not available"; return 1; }; case "$allowed" in *" $v "*) ;; *) echo "$p is $v (running)"; return 1;; esac; sd=$(readlink -e /lib/systemd/systemd-sysctl || readlink -e /usr/lib/systemd/systemd-sysctl); f=$("$sd" --cat-config 2>/dev/null | grep -Po "^\h*${p//./\.}\h*=\h*\K\H+" | tail -n1); [ -n "$f" ] || { echo "$p is not set in any sysctl configuration file"; return 1; }; case "$allowed" in *" $f "*) ;; *) echo "$p is $f in configuration"; return 1;; esac; }; if chk fs.protected_hardlinks 1; then echo compliant; fi
Expected output
compliant

How it is fixed

Fix method: Guidance or infrastructure patch

1. Review all files being used by systemd sysctl and comment out or remove all fs.protected_hardlinks lines that are not fs.protected_hardlinks=1. Example script: #!/usr/bin/env bash { l_option="fs.protected_hardlinks" l_value="1" l_grep="${l_option//./(\\.|\\/)}" a_files=() l_systemdsysctl="$(readlink -e /lib/systemd/systemd-sysctl \ || readlink -e /usr/lib/systemd/systemd-sysctl)" a_files+=("/etc/sysctl.conf") while IFS= read -r l_fname; do l_file="$(readlink -e "${l_fname//# /}")" [ -n "$l_file" ] && ! grep -Psiq -- '(^|\h+)'"$l_file"'\b' \ <<< "${a_files[*]}" && a_files+=("$l_file") done < <("$l_systemdsysctl" --cat-config | tac | \ grep -Psio -- '^\h*#\h*\/[^#\n\r\h]+\.conf\b') for l_fi…

Properties

Operating systems
rocky-9
Tags
cis-convertedkernellinuxsysctl
Reference
CIS Rocky Linux 9 Benchmark v3.0.0 - 1.5.1

Check this host

Run this on a machine you are allowed to audit. The scan is read-only.

shell
tmaegis scan --target linux