Checks / Host

Kernel hardening settings are off

Check
sysctl.hardening
Severity
low
Runs
on the server, in the daily run of the agent
Looks at
kernel.kptr_restrict, kernel.dmesg_restrict, kernel.unprivileged_bpf_disabled, fs.protected_symlinks, fs.protected_hardlinks
Updated 26 Nov 2026

What the check looks at

Five kernel settings. The check warns when one of them is below the expected value:

Setting Expected
kernel.kptr_restrict 1 or 2
kernel.dmesg_restrict 1
kernel.unprivileged_bpf_disabled 1 or 2
fs.protected_symlinks 1
fs.protected_hardlinks 1

Risk

These settings make the next step harder for someone who already runs code as an unprivileged user, through a bug in a web application or from a compromised container (containers share the kernel of the host). Kernel addresses and the kernel log help to build a kernel exploit, unprivileged BPF has been the entry point of several kernel privilege escalations, and the link protections stop old symlink and hard link tricks in /tmp against programs that run as root.

Defaults differ. On a stock Debian 12 or 13, kptr_restrict is 0; on Rocky Linux 9, dmesg_restrict is 0; on Rocky Linux 9 and 10, no shipped file sets the two link protections. The sysctl guide has the table per distribution.

How to fix it

The same file works on every distribution:

sudo tee /etc/sysctl.d/90-hardening.conf >/dev/null <<'EOF'
kernel.kptr_restrict = 1
kernel.dmesg_restrict = 1
kernel.unprivileged_bpf_disabled = 1
fs.protected_symlinks = 1
fs.protected_hardlinks = 1
EOF

Apply it.

Debian, Ubuntu, RHEL, Rocky Linux and AlmaLinux

sudo sysctl --system

Alpine

sudo sysctl -p /etc/sysctl.d/90-hardening.conf

The OpenRC service sysctl applies the file at the next boot.

After unprivileged_bpf_disabled = 1, only a reboot changes the value back. To keep that option open, use 2, which the check accepts too.

How to check the fix

sysctl kernel.kptr_restrict kernel.dmesg_restrict kernel.unprivileged_bpf_disabled \
       fs.protected_symlinks fs.protected_hardlinks

As a normal user, dmesg must fail with Operation not permitted. If a value does not stick after a reboot, a file with a later name sets it back; systemd-analyze cat-config sysctl.d shows all files in the order they apply.

When a warning is fine

Kernel debugging and some monitoring agents read kernel addresses or the kernel log. Tracing tools based on BPF need root on current distributions anyway. If such a tool runs on the server, set the one value it needs and keep the others.

Sources