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

The agent reads five kernel settings and warns when one of them is off:

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

Why it matters

These settings do not stop anyone from getting in. They make the next step harder for someone who already runs code as an unprivileged user, through a web application bug or 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 tricks with symlinks and hard links 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; and 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.

unprivileged_bpf_disabled = 1 cannot be changed back without a reboot. If you prefer to keep that option open, use 2, which the check accepts as well.

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

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

Sources