← /blog

The sysctl settings that actually matter (and three that don't)

2026-10-11 · Linux hardening · 3 min read

I ran my own auditor (state-witness) on a machine I'd already hardened. It flagged four sysctl checks. Two were real. Two were noise. That gap is the whole point.

The two that matter

kernel.kptr_restrict = 0        # kernel pointers visible in /proc
kernel.yama.ptrace_scope = 0    # any process can ptrace another

kptr_restrict should be 1 (or 2). At 0, kernel addresses leak through /proc — free information for an exploit chain.

yama.ptrace_scope should be 1. At 0, any process with your UID can ptrace another: read its memory, steal secrets it holds, inject calls into it. Scope 1 restricts that to descendants of the caller, which is enough for debuggers and too little for a random process that lands on the box.

What it does not do — worth saying, because these posts usually stop at “set it to 1”: anything with CAP_SYS_PTRACE (root, or a container granted that capability) attaches regardless; it narrows the same-user path, not the privileged one. And it is not a containment boundary — a process that can read the files your agent uses does not need ptrace to abuse it.

This is why the SSH-agent example is worth taking seriously but not as a certainty: a compromised same-UID process can reach an agent socket it has permission to talk to, and ptrace makes the broader version of that easier. Whether your browser sandbox lets a tab get that far is a separate question with its own answer.

The two that are noise (on this box)

net.ipv4.ip_forward = 1        # "expected 0"
net.ipv4.conf.all.rp_filter = 0 # "expected 1"

Both were set by the virtualization stack on that host, not by me — libvirt needs forwarding for NAT networks, and container runtimes set it too. That is why I called them noise there: forwarding was load-bearing.

The rule is narrower than “Docker means it is fine”. Forwarding is correct if something on the host needs to route packets, and wrong if nothing does. A VM on a bridged network, or a host with no containers, does not need ip_forward=1; leaving it on is then extra surface. Same for rp_filter=0: container bridges and multi-homed routing sometimes need loose mode, but “a runtime is installed” is not evidence this host needs it today.

So the check is neither the number nor the presence of Docker. It is: what does this host route, and is the setting the one that configuration requires? On my box the answer was yes. On the next one it may not be — which is the whole reason the tool reports provenance instead of a verdict.

Fix the real ones

# /etc/sysctl.d/99-hardening.conf
kernel.kptr_restrict = 1
kernel.yama.ptrace_scope = 1

sudo sysctl -p /etc/sysctl.d/99-hardening.conf   # apply one file
sysctl -n kernel.kptr_restrict kernel.yama.ptrace_scope   # verify

It is tempting to run sysctl --system here. Know what it does first: it loads every file from /etc/sysctl.d, /run/sysctl.d, /usr/local/lib/sysctl.d, /usr/lib/sysctl.d, /lib/sysctl.d and /etc/sysctl.conf — in that order, per sysctl(8). So it does not just apply your file: it re-applies whatever every package on the box has shipped, and when two files set the same key the later one wins (a file with the same name in a later directory is ignored instead). Values you changed by hand at runtime get reset to whatever the files say. For one change, apply one file.

The takeaway

A hardening checklist that fires on everything is useless — you stop reading it. What you want is: what does this host actually enforce, and is that a real problem here? Two real fixes beat forty warnings.

Sources: kernel docs — Yama (ptrace_scope levels and their limits), sysctl(8) for --system file order and precedence, proc_sysctl/ip-sysctl docs for rp_filter modes.

Want your server checked? I run a read-only Server Health Check — what's exposed, severity, top 3 fixes. If I find nothing, you don't pay.