Kernel parameters decide how much an attacker with a local foothold can learn about the kernel, which processes they can attach to, and whether they can load code into ring 0, yet most fleets run whatever the distribution shipped. Distribution defaults differ, some protective settings are one-way switches that cannot be undone without a reboot, and a few break debuggers, containers or screen readers. This guide sets out the settings that matter (kptr_restrict, dmesg_restrict, Yama ptrace_scope, unprivileged BPF and user namespaces, file system protections, module signing and kernel lockdown), what each value does according to the kernel documentation, how to deploy them through sysctl.d and the boot command line, and how to monitor drift. It is for Linux platform owners and security engineers. The wider host baseline is in the Linux Server Hardening Guide.
Key takeaways
- Start with information leaks and ptrace.
kernel.kptr_restrict,kernel.dmesg_restrictandkernel.yama.ptrace_scopedeny an attacker the kernel addresses and process memory that most local exploits and credential theft rely on. - One-way switches need a plan.
modules_disabled=1,kexec_load_disabled=1,unprivileged_bpf_disabled=1andptrace_scope=3cannot be reverted on the running kernel. Pilot them; use reversible values first where they exist. - Module signing and lockdown protect the kernel from root. sysctls limit unprivileged users; signed module enforcement and lockdown stop a compromised root account loading rootkits or reading kernel memory.
- Know your distribution's defaults. Ubuntu ships
kptr_restrict=1,dmesg_restrict=1and lockdown in integrity mode under Secure Boot; other distributions and custom kernels differ. Measure, do not assume. - Persistence lives in sysctl.d ordering. The file that sorts last wins, so a vendor or application file can silently undo your baseline.
How kernel settings shape what a local user can do
Kernel hardening settings fall into three groups. Runtime sysctls under /proc/sys change behaviour immediately and are persisted through sysctl.d. Boot parameters on the kernel command line (visible in /proc/cmdline) change how the kernel initialises, such as which LSMs load and whether lockdown is active. Build options (CONFIG_*) decide which features exist at all. A sysctl cannot remove a feature the kernel was built without, and a build option often sets the sysctl default, as with CONFIG_SECURITY_DMESG_RESTRICT for dmesg_restrict and BPF_UNPRIV_DEFAULT_OFF for unprivileged BPF.
Reference: core security sysctls
| Setting | Values (kernel documentation) | KSPP recommendation | Compatibility notes |
|---|---|---|---|
kernel.kptr_restrict | 0 hashed addresses; 1 %pK pointers zeroed unless CAP_SYSLOG; 2 always zeroed | 2 (1 if root needs addresses) | Some profilers need 1 for root |
kernel.dmesg_restrict | 0 unrestricted; 1 needs CAP_SYSLOG | 1 | Users lose dmesg; use the journal with group access |
kernel.yama.ptrace_scope | 0 same UID; 1 descendants only; 2 CAP_SYS_PTRACE only; 3 no attach, cannot be changed | 3 (1 if ptrace must work) | 1 breaks attaching gdb or strace to an existing process as a normal user; 3 also blocks root |
kernel.unprivileged_bpf_disabled | 0 allowed; 1 disabled, no recovery; 2 disabled, admin may re-enable | 1 | Agents with CAP_BPF unaffected |
kernel.perf_event_paranoid | -1 to 2 upstream (default 2: profiling needs CAP_PERFMON) | 3 (needs a distribution patch) | Developer profiling on shared hosts |
kernel.kexec_load_disabled | 1 disables kexec_load and kexec_file_load, one-way | 1 | Breaks kdump unless loaded first |
kernel.modules_disabled | 1 blocks module load and unload, one-way | Not listed | Only after all needed modules load at boot |
kernel.randomize_va_space | 0 off; 1 mmap, stack, VDSO; 2 also heap | Not listed (2 is the usual default) | Value 0 is a finding |
kernel.io_uring_disabled | 0 all; 1 only CAP_SYS_ADMIN or io_uring_group; 2 none | Not listed | Breaks applications that use io_uring for I/O |
user.max_user_namespaces | Maximum user namespaces per user | 0 | Breaks rootless containers and browser sandboxes |
net.core.bpf_jit_harden | Hardening of the BPF JIT | 2 | Small JIT performance cost |
dev.tty.legacy_tiocsti | Controls TIOCSTI keystroke injection | 0 | KSPP notes this breaks screen readers |
vm.unprivileged_userfaultfd | Unprivileged userfaultfd use | 0 | Rarely needed outside live migration |
File system and core dump protections
fs.protected_symlinks=1andfs.protected_hardlinks=1: block the classic/tmpsymlink and hardlink races. Symlinks in sticky world-writable directories are followed only when owner rules match; hardlinks need ownership or read-write access to the source.fs.protected_fifos=2andfs.protected_regular=2: stopO_CREATopens of FIFOs and files an attacker pre-created in sticky directories, including group-writable ones at level 2. KSPP advises checking workloads first.fs.suid_dumpable=0: processes that changed privilege are not dumped. Value 1 is described by the kernel as insecure and for debugging only; value 2 dumps only to a pipe handler or absolute path.
Network sysctls on servers
Hosts that are not routers should keep net.ipv4.ip_forward=0, set accept_redirects and send_redirects to 0, keep accept_source_route=0 (the host default), enable rp_filter (1 strict or 2 loose per RFC 3704; use 2 on multi-homed hosts with asymmetric routing), keep tcp_syncookies=1 and icmp_echo_ignore_broadcasts=1, and set log_martians=1. Container and Kubernetes nodes need forwarding on; set it deliberately on those roles rather than estate wide.
Privileged access: limiting what root and capabilities can reach
Several settings exist because root is not trusted absolutely. A compromised service running as root, a stolen admin session or a malicious agent update should still not be able to load arbitrary kernel code or read kernel memory.
- Yama ptrace scope: at 0, any process can attach to other processes of the same UID, so one compromised process under a user or service account can read the memory, tokens and keys of every sibling. At 1 only ancestors can attach; at 2 only CAP_SYS_PTRACE holders. This is one of the cheapest defences against in-memory credential theft from long running service accounts.
- Capabilities that matter here: CAP_SYSLOG reveals kernel addresses when
kptr_restrict=1; CAP_SYS_MODULE loads modules; CAP_SYS_PTRACE overrides Yama below level 3; CAP_BPF and CAP_PERFMON govern BPF and tracing. Keep them out of service units and containers; see the Linux Capabilities Guide. - Kernel lockdown: lockdown blocks
/dev/mem,/dev/kmem,/dev/kcore, BPF and kprobes, MSR writes and debugfs, and allows only signed modules and kexec images. It needsCONFIG_SECURITY_LOCKDOWN_LSMandlockdownin thelsm=list. Ubuntu enables integrity mode when UEFI Secure Boot is on. The stricter confidentiality mode also blocks features that read kernel memory, which affects some tracing and EDR tools. Check the active mode in/sys/kernel/security/lockdown. - Interactive admin sessions: keep tracing and kernel debugging tools behind logged sudo rules; see the sudo and sudoers Security Guide.
Kernel modules, kexec, eBPF and third party agents
The main routes for adding code to a running kernel are loadable modules, kexec into a new kernel, and BPF programs. Each has a legitimate use, often by a vendor agent (EDR, storage, GPU, backup) that runs with a machine identity and an update channel.
| Route | Control | Effect | Trade-off |
|---|---|---|---|
| Loadable modules | CONFIG_MODULE_SIG_FORCE or boot parameter module.sig_enforce=1 | Only modules signed with a trusted key load; in permissive mode unsigned modules load but taint the kernel with "E" | Out of tree drivers (DKMS) must be signed with an enrolled key |
| Loadable modules | kernel.modules_disabled=1 after boot | No further load or unload until reboot | Hot-plug hardware and new file systems fail |
| Rare protocol modules | Denylist in /etc/modprobe.d/ | Ubuntu denylists ax25, netrom, x25, rose, decnet, econet, rds and af_802154 by default | Very low |
| kexec | kernel.kexec_load_disabled=1; lockdown requires signed images | Prevents booting an attacker kernel without firmware checks | kdump image must be loaded before disabling |
| BPF | unprivileged_bpf_disabled, bpf_jit_harden=2, lockdown | Limits who can load programs and hardens JIT output | See the eBPF Security Guide |
Signing keys are privileged machine credentials. The kernel build generates certs/signing_key.pem by default, and the documentation advises deleting or securely storing the private key once the public key is built in, never leaving it in the source tree. Organisations that sign their own DKMS modules for Secure Boot hold a key that can authorise kernel code on every enrolled host: keep it in an HSM or a signing service, restrict who can request signatures, and log every use. See the Linux Secure Boot and Shim Guide and the Code Signing Security Guide.
Logging and detection
- Lockdown denials: the kernel logs "Lockdown: X: Y is restricted, see man kernel_lockdown.7", naming the process and feature. On a production server that is either a misbehaving tool or an attacker probing; alert on it.
- Taint flags:
/proc/sys/kernel/taintedis non-zero when, among other reasons, an unsigned or out of tree module loaded. Collect it fleet wide; a host that becomes tainted outside a change window needs a look (ATT&CK T1547.006 Kernel Modules and Extensions, T1014 Rootkit). - Module loads: audit
init_module,finit_moduleanddelete_modulewith auditd and forward the records; see the Linux Logging and auditd for Defenders Guide. - Runtime drift: a weekly job comparing
sysctl -aoutput and/proc/cmdlinewith the baseline catches settings changed at runtime or by a latersysctl.dfile. A write to a security sysctl by an interactive shell is a tampering signal (T1685 Disable or Modify Tools). - ptrace and exploitation signals: EDR events for ptrace attach and process memory reads, and kernel oops or panic messages, often precede or accompany local privilege escalation (T1068) and process injection (T1055).
Metrics
- Baseline conformance: percentage of hosts where every baseline sysctl matches the approved value.
- Ptrace exposure: percentage of hosts with
ptrace_scopeof 1 or higher (target 100%). - Kernel integrity: percentage of hosts with lockdown active or signed module enforcement on.
- Tainted kernels: number of hosts with an unexpected taint value, trending to zero.
- Exceptions: count of documented per-role deviations, each with an owner and review date.
Hardening baseline
Deploying with sysctl.d
Per sysctl.d(5), files are read from /etc/sysctl.d/, /run/sysctl.d/, /usr/local/lib/sysctl.d/ and /usr/lib/sysctl.d/; all .conf files are sorted by name across directories and the last one to set a key wins. Name the baseline file with a high prefix such as /etc/sysctl.d/90-security-baseline.conf, mask a vendor file by symlinking its name in /etc/sysctl.d/ to /dev/null, and remember that keys belonging to modules loaded after systemd-sysctl.service runs will not be applied unless the module loads early.
Rollout plan
- Measure: collect
sysctl -a,/proc/cmdline,/sys/kernel/security/lsm,/sys/kernel/security/lockdownand the taint value from every host. Record distribution defaults per OS version. - Tier 1, low risk (all hosts):
kptr_restrict1 or 2,dmesg_restrict=1,ptrace_scope=1,protected_symlinks=1,protected_hardlinks=1,suid_dumpable=0,randomize_va_space=2,unprivileged_bpf_disabled=2, server network settings. - Tier 2, role based:
ptrace_scope=2on production servers,protected_fifos=2andprotected_regular=2,kexec_load_disabled=1,bpf_jit_harden=2,io_uring_disabledwhere no application uses it, user namespace limits where no rootless containers run. - Tier 3, kernel integrity: Secure Boot with lockdown, or
module.sig_enforce=1;modules_disabled=1on fixed function hosts. Validate EDR, storage and GPU drivers first. - Test in rings: apply each tier to a pilot ring for at least a full patch cycle, watching application errors, failed module loads and Lockdown messages.
- Rollback: reversible settings are rolled back by removing the file and running
sysctl --system; one-way settings need the file removed and a reboot. Boot parameters are changed in the bootloader configuration. Keep an out of band console for Tier 3 changes.
Decision guidance
- Small estates: apply Tier 1 everywhere and keep Secure Boot on; that alone closes the common leaks.
- Large estates: define per-role profiles (web, database, container node, build agent, developer workstation) because user namespaces, forwarding, io_uring and ptrace needs genuinely differ by role. Scan them with SCAP profiles; see the OpenSCAP and Linux Compliance Scanning Guide.
- User namespaces: setting
user.max_user_namespaces=0removes a large attack surface but breaks rootless containers and browser sandboxes. On Ubuntu, AppArmor based restriction is a finer alternative; see the AppArmor Guide.
Framework mapping
| Framework | Reference | How the settings apply |
|---|---|---|
| NIST SP 800-53 Rev. 5 | CM-6 Configuration Settings; CM-7 Least Functionality | sysctl and boot baseline; disabling kexec, unneeded modules and namespaces |
| NIST SP 800-53 Rev. 5 | SI-16 Memory Protection; SI-7 Software, Firmware, and Information Integrity; AC-6 Least Privilege | ASLR, ptrace limits, signed modules and lockdown |
| NIST CSF 2.0 | PR.PS-01 | Configuration management practices established and applied |
| CIS Controls v8.1 | Control 4 Secure Configuration of Enterprise Assets and Software | CIS Benchmarks for Linux include ASLR, core dump and network parameter checks |
| ISO/IEC 27001:2022 | Annex A 8.9 Configuration management | Documented, reviewed kernel baseline |
| MITRE ATT&CK v20 | T1068, T1055, T1547.006, T1014 | Settings raise the cost of local exploitation, injection and kernel persistence |
Common misconfigurations
- Baseline overridden by a later file: an application package drops
99-app.confthat re-enables forwarding or lowersptrace_scope, and it wins because it sorts last. - One-way setting without a pilot:
modules_disabled=1pushed estate wide, and the next USB, storage or VPN driver load fails until reboot. - ptrace_scope left at 0 on multi-service hosts: any compromised process can read the memory of every other process running under the same service account, including tokens and keys.
- Lockdown silently off: Secure Boot disabled in firmware during troubleshooting and never re-enabled, so Ubuntu hosts lose lockdown with no configuration change in the OS.
- Unprotected module signing key: the DKMS or kernel signing private key left on build servers, giving anyone with that server the ability to sign rootkits trusted by every host. The MSI Signing Keys Leak 2023 showed the firmware equivalent: signing keys stored alongside source code rather than in an HSM were leaked after a ransomware intrusion.
- Settings applied at runtime only:
sysctl -wduring an incident, never persisted, gone at the next reboot.
Practitioner checklist
- Inventory current sysctl values, boot parameters, active LSMs, lockdown mode and taint state on every host.
- Deploy a named
/etc/sysctl.d/90-baseline through configuration management and check for later files that override it. - Set
kptr_restrict,dmesg_restrict,ptrace_scope(1 or higher), file system protections andsuid_dumpable=0everywhere. - Disable unprivileged BPF and set
bpf_jit_harden=2. - Decide per role on user namespaces, io_uring, forwarding and kexec, and document exceptions.
- Enable Secure Boot with lockdown or enforce module signatures, after validating third party drivers.
- Protect module signing keys in an HSM or signing service with logged use.
- Alert on Lockdown messages, unexpected taint, module loads and runtime sysctl changes.
- Pilot one-way settings in a ring and keep console access for rollback.
Standards and references
- Linux kernel documentation: Documentation for /proc/sys/kernel/
- Linux kernel documentation: Documentation for /proc/sys/fs/
- Linux kernel documentation: Yama
- Linux kernel documentation: Kernel module signing facility
- Linux man-pages: kernel_lockdown(7)
- Linux man-pages: sysctl.d(5)
- Kernel Self Protection Project: Recommended Settings
- Ubuntu: Kernel protections
Related NHI Mgmt Group resources: Linux Server Hardening Guide · Linux Privilege Escalation Techniques Guide · eBPF Security Guide · SELinux Guide