brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: kernel.dmesg_restrict keeps the kernel log away from normal users, a security sysctl

Security
~/tips/tip-security-dmesg-restrict

sysctl kernel.dmesg_restrict kernel.kptr_restrict

Stops unprivileged users from reading the kernel ring buffer with dmesg.

The kernel log holds memory addresses, hardware details and driver errors. That is useful to an attacker who already has a normal shell, so I don’t want every user reading it.

First see what you have now:

sysctl kernel.dmesg_restrict kernel.kptr_restrict

With dmesg_restrict set to 1, a user needs CAP_SYSLOG, in practice root, to run dmesg. Many distributions already ship it that way, but I’d check instead of assuming. To make it stick, put it in a file of its own:

printf 'kernel.dmesg_restrict = 1\nkernel.kptr_restrict = 1\n' | sudo tee /etc/sysctl.d/60-kernel-hardening.conf
sudo sysctl --system

The second setting is a companion. kptr_restrict = 1 replaces kernel pointers printed in places like /proc/kallsyms with zeros for anyone without CAP_SYSLOG. A value of 2 hides them from root as well.

Expect a small cost in convenience. Admins in the adm group who used to run dmesg without sudo will now get Operation not permitted. They can still use sudo dmesg, or journalctl -k if they have read access to the journal. Containers share the host kernel, so these values are set on the host, not inside a container.

Further reading: Linux kernel documentation: /proc/sys/kernel

More Security tips tcpdump -nn -r capture.pcap port 53 mkcert -install Strict-Transport-Security: max-age=0 Referrer-Policy: strict-origin-when-cross-origin wp super-admin list All Security tips (79) All topics

Link