<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Linux Archives - Hécate Regnier - Neurozone</title>
	<atom:link href="https://hecate.neurozone.fr/tag/linux/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>DBA, DevOps &#38; Sysadmin</description>
	<lastBuildDate>Mon, 02 Nov 2026 17:10:46 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.5</generator>

<image>
	<url>https://hecate.neurozone.fr/wp-content/uploads/2026/10/cropped-avatar_Instagram-150x150.webp</url>
	<title>Linux Archives - Hécate Regnier - Neurozone</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">258172890</site>	<item>
		<title>Systemd kernel protection: ProtectKernelTunables, PrivateDevices and the other kernel and device directives</title>
		<link>https://hecate.neurozone.fr/2026/11/28/systemd-kernel-protection-directives-tunables-modules-devices/</link>
					<comments>https://hecate.neurozone.fr/2026/11/28/systemd-kernel-protection-directives-tunables-modules-devices/#respond</comments>
		
		<dc:creator><![CDATA[Hécate Regnier]]></dc:creator>
		<pubDate>Sat, 28 Nov 2026 09:00:00 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Sysadmin notebook]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[hardening]]></category>
		<category><![CDATA[Rocky Linux]]></category>
		<category><![CDATA[systemd]]></category>
		<guid isPermaLink="false">https://hecate.neurozone.fr/?p=3476</guid>

					<description><![CDATA[<p>Systemd kernel protection, directive by directive: tunables, modules, logs, clock, cgroups, devices, /proc and hostname, each tested on a real bench.</p>
<p>The post <a href="https://hecate.neurozone.fr/2026/11/28/systemd-kernel-protection-directives-tunables-modules-devices/">Systemd kernel protection: ProtectKernelTunables, PrivateDevices and the other kernel and device directives</a> appeared first on <a href="https://hecate.neurozone.fr">Hécate Regnier - Neurozone</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Systemd kernel protection is the family of directives that stop a service from reaching the parts of the kernel it never needs: the settings under <code>/proc/sys</code>, kernel modules, the kernel log, the clock, the control groups, the device files, the process view in <code>/proc</code> and the hostname. This is part 4 of a series of 8 on systemd hardening, directive by directive. In this part, I explain what each of these directives does, what it usually breaks, how to test it safely and what it means for the kind of stack I run.</p>



<p class="wp-block-paragraph">I wrote this article so that a beginner sysadmin can follow it. Therefore, every directive comes with a complete drop-in file, the exact commands in the order to run them and a hands-on lab: a harmless demo script shows the effect of each directive in a few seconds. Every statement about a directive comes from the official systemd manual pages, listed at the end.</p>



<figure class="wp-block-image size-full"><a href="https://hecate.neurozone.fr/wp-content/uploads/2026/11/systemd-kernel-protection-directives_en.webp"><img fetchpriority="high" decoding="async" width="1720" height="900" src="https://hecate.neurozone.fr/wp-content/uploads/2026/11/systemd-kernel-protection-directives_en.webp" alt="Systemd kernel protection diagram: the kernel interface each directive closes and the directive that locks it" class="wp-image-3473" srcset="https://hecate.neurozone.fr/wp-content/uploads/2026/11/systemd-kernel-protection-directives_en.webp 1720w, https://hecate.neurozone.fr/wp-content/uploads/2026/11/systemd-kernel-protection-directives_en-300x157.webp 300w, https://hecate.neurozone.fr/wp-content/uploads/2026/11/systemd-kernel-protection-directives_en-1024x536.webp 1024w, https://hecate.neurozone.fr/wp-content/uploads/2026/11/systemd-kernel-protection-directives_en-768x402.webp 768w, https://hecate.neurozone.fr/wp-content/uploads/2026/11/systemd-kernel-protection-directives_en-1536x804.webp 1536w" sizes="(max-width: 800px) 100vw, 760px" /></a><figcaption class="wp-element-caption">Each kernel interface of a service and the directive that closes it.</figcaption></figure>



<h2 class="wp-block-heading">Before you start</h2>



<p class="wp-block-paragraph">Systemd kernel protection is easy to learn if you prepare the ground first. Read this short checklist before you touch any service.</p>



<ul class="wp-block-list"><li><strong>Use a test machine.</strong> A virtual machine or a throwaway Linux host is ideal. The lab commands are harmless, but a typo in a drop-in can stop a service.</li><li><strong>Check your systemd version.</strong> Run <code>systemctl --version</code>. According to the manual, PrivateDevices arrived in version 209, ProtectKernelTunables, ProtectKernelModules and ProtectControlGroups in 232, ProtectHostname in 242, ProtectKernelLogs in 244, ProtectClock in 245, and ProtectProc and ProcSubset in 247.</li><li><strong>Have root access and a way back.</strong> You need <code>sudo</code>.</li><li><strong>Know how to undo.</strong> <code>sudo systemctl revert myapp.service</code> removes the drop-ins you created for that unit.</li><li><strong>Change one directive at a time</strong> on a non-critical service, then read the journal before you go on.</li></ul>



<p class="wp-block-paragraph"><strong>Where I tested.</strong> Every output in this article is real. I ran the commands on Rocky Linux 10.2 with systemd 257 and the kernel 6.18.54.1-microsoft-standard-WSL2, as root, with SELinux disabled. WSL2 is not a standard server: SELinux is not available there, and some kernel interfaces differ. Therefore, treat each result as what happened on this bench, not as a universal truth. I also read the current manual, which documents options that systemd 257 does not know yet. I point out each difference.</p>



<h2 class="wp-block-heading">A short glossary for beginners</h2>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>Term</th><th>Plain meaning</th></tr></thead><tbody><tr><td>Kernel</td><td>The core of the operating system. Programs ask it, through system calls, to open files, use the network or change settings.</td></tr><tr><td>System call</td><td>A request from a program to the kernel, for example &quot;open this file&quot; or &quot;set the clock&quot;.</td></tr><tr><td>sysctl or kernel tunable</td><td>A kernel setting you can read and change while the machine runs. The kernel shows it as a file under <code>/proc/sys</code>; for example <code>vm.swappiness</code> is <code>/proc/sys/vm/swappiness</code>.</td></tr><tr><td>/proc</td><td>A virtual directory where the kernel shows one numbered directory per process, plus system information such as <code>cpuinfo</code>.</td></tr><tr><td>/sys</td><td>A virtual directory where the kernel shows devices, drivers and some settings.</td></tr><tr><td>Kernel module</td><td>A piece of kernel code (a driver, a firewall extension, a file system) that the kernel loads when needed.</td></tr><tr><td>Capability</td><td>A slice of root&#8217;s powers, such as loading modules or setting the clock. A process can keep some and lose others.</td></tr><tr><td>Bounding set</td><td>The list of capabilities a process and its children can never exceed.</td></tr><tr><td>Control group (cgroup)</td><td>The kernel feature that systemd uses to group a service&#8217;s processes and to account for or limit their resources.</td></tr><tr><td>Device node</td><td>A special file in <code>/dev</code>, such as <code>/dev/null</code>, that stands for a device or a pseudo device.</td></tr><tr><td>Namespace</td><td>A private view of a system resource (the mounts, the hostname&#8230;) that the kernel gives to a group of processes.</td></tr><tr><td>Unit and drop-in</td><td>A unit is something systemd manages, such as a service. A drop-in is a small <code>.conf</code> file in a directory named after the unit (<code>myapp.service.d/</code>) that adds settings without touching the original unit file.</td></tr></tbody></table></figure>



<h2 class="wp-block-heading">Systemd kernel protection at a glance</h2>



<p class="wp-block-paragraph">The table below summarises the ten directives of systemd kernel protection. The last column tells you what each one means for my own stack. I only claim what my notes and articles say. Everything else reads as &quot;if you run X, expect&#8230;&quot;.</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>Directive</th><th>What it does</th><th>Risk of breaking</th><th>Impact on my stack</th></tr></thead><tbody><tr><td><code>ProtectKernelTunables=</code></td><td>Makes <code>/proc/sys</code>, <code>/sys</code> and a few more paths read-only, and hides <code>/proc/kallsyms</code> and <code>/proc/kcore</code></td><td>A service that writes a sysctl at start fails</td><td>None of my documented drop-ins uses it; my hardening role already sets kernel sysctls for the whole host</td></tr><tr><td><code>ProtectKernelModules=</code></td><td>Blocks explicit module loading, removes <code>CAP_SYS_MODULE</code>, hides <code>/usr/lib/modules</code></td><td>A start script that runs <code>modprobe</code> fails</td><td>My Suricata role loads its modules itself, outside the service</td></tr><tr><td><code>ProtectKernelLogs=</code></td><td>Removes <code>CAP_SYSLOG</code>, hides <code>/dev/kmsg</code> and <code>/proc/kmsg</code></td><td>Tools that read <code>dmesg</code> fail</td><td>Adds a per-service lock to the host-wide <code>dmesg_restrict</code> of my hardening role</td></tr><tr><td><code>ProtectClock=</code></td><td>Removes <code>CAP_SYS_TIME</code> and <code>CAP_WAKE_ALARM</code> and filters clock calls</td><td>A time daemon cannot set the clock</td><td>Must stay off for chrony, which runs on my hosts</td></tr><tr><td><code>ProtectControlGroups=</code></td><td>Makes <code>/sys/fs/cgroup</code> read-only</td><td>Container runtimes and cgroup managers fail</td><td>Not tested on my Podman virtual machine</td></tr><tr><td><code>PrivateDevices=</code></td><td>Gives the service a minimal <code>/dev</code></td><td>Anything that needs real hardware fails</td><td>Would hide the GPU that my media server uses for hardware transcoding</td></tr><tr><td><code>DevicePolicy=</code> and <code>DeviceAllow=</code></td><td>Choose which device nodes the service may open</td><td><code>strict</code> denies even <code>/dev/null</code> until you allow it</td><td>The way to give the media server only its GPU</td></tr><tr><td><code>ProtectProc=</code></td><td>Hides other users&#8217; processes in <code>/proc</code></td><td>Needs <code>User=</code>; process listing tools lose data</td><td>Check any agent that inventories processes</td></tr><tr><td><code>ProcSubset=</code></td><td>Shows only the process files in <code>/proc</code></td><td>Programs that read <code>/proc/cpuinfo</code> or <code>/proc/meminfo</code> fail</td><td>For simple services only</td></tr><tr><td><code>ProtectHostname=</code></td><td>Blocks changes of the hostname</td><td>Almost nothing in practice</td><td>My notes mention no service that sets a hostname</td></tr></tbody></table></figure>



<h2 class="wp-block-heading">How to apply and undo one systemd kernel protection safely</h2>



<p class="wp-block-paragraph">Systemd reads a service&#8217;s settings from its unit file. However, you should never edit the file that your package installed, because an update would replace your change. Instead, you add a drop-in. For <code>myapp.service</code>, the drop-in directory is <code>myapp.service.d/</code>. The manual says that systemd reads every <code>.conf</code> file in that directory in alphanumeric order, and that drop-ins in <code>/etc/systemd/system</code> take precedence over those in <code>/run</code> and <code>/usr/lib</code>. Therefore, I name my files <code>10-something.conf</code>, so that I can add <code>20-something.conf</code> later.</p>



<p class="wp-block-paragraph">Here is the complete cycle that I repeat for every directive in this article. The comments explain each line in plain language.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell"># 1. Create a drop-in directory named after your service (replace myapp.service by your own unit)
sudo mkdir -p /etc/systemd/system/myapp.service.d
# 2. Write the drop-in. The [Service] header is required and the file name must end in .conf
sudo tee /etc/systemd/system/myapp.service.d/10-kernel-protection.conf &gt; /dev/null &lt;&lt;'EOF'
[Service]
# Example: make the kernel settings read-only for this service.
ProtectKernelTunables=yes
EOF
# 3. Make systemd re-read its configuration, then restart the service
sudo systemctl daemon-reload
sudo systemctl restart myapp.service
# 4. Check that the setting is active, that the service runs and what it logged
systemctl show -p ProtectKernelTunables --value myapp.service
systemctl is-active myapp.service
sudo journalctl -u myapp.service -n 20 --no-pager
# 5. Undo everything: remove the drop-ins you created, reload and restart
sudo systemctl revert myapp.service
sudo systemctl daemon-reload
sudo systemctl restart myapp.service</pre>



<p class="wp-block-paragraph">You can also run <code>sudo systemctl edit myapp.service</code>. It opens an editor on a drop-in named <code>override.conf</code> and, according to the manual, reloads the configuration when you save. The manual does not say that <code>systemctl revert</code> reloads systemd, so the cycle above runs <code>daemon-reload</code> after it.</p>



<p class="wp-block-paragraph">To see how exposed a service is, run <code>systemd-analyze security --no-pager myapp.service</code>. The manual explains that it gives an overall exposure level from 0.0 to 10.0, where a high value means little sandboxing. It only measures what systemd itself implements. It does not cover what a service can ask other services to do over IPC. I use it as a guide, not as a proof.</p>



<h2 class="wp-block-heading">Build the lab: a harmless demo script</h2>



<p class="wp-block-paragraph">The lab uses one small script. Each argument tests one group of directives and prints one to five short lines. Nothing in it is dangerous: it writes the current value of a kernel setting back to itself, reads and counts, and touches the clock or the hostname only when you explicitly ask for it. Copy the whole block below as it is.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell">sudo tee /usr/local/bin/demo-hardening-lab.sh &gt; /dev/null &lt;&lt;'EOF'
#!/bin/sh
# demo-hardening-lab.sh: each argument tests ONE group of directives and prints short result lines.
case "$1" in
  tunables)
    # Write the CURRENT value of a kernel setting back to itself: harmless if the write works.
    value=$(cat /proc/sys/vm/swappiness)
    if { echo "$value" &gt; /proc/sys/vm/swappiness; } 2&gt;/dev/null; then echo "tunables: write allowed"; else echo "tunables: write blocked"; fi
    # Try to read one byte of the kernel symbol table: 1 means readable, 0 means empty or blocked.
    echo "kallsyms: $(head -c 1 /proc/kallsyms 2&gt;/dev/null | wc -c) byte read"
    ;;
  modules)
    # Count the entries that /usr/lib/modules shows (one directory per installed kernel).
    echo "modules directory: $(ls /usr/lib/modules 2&gt;/dev/null | wc -l) entries"
    ;;
  logs)
    # Try to read the kernel log.
    if dmesg &gt; /dev/null 2&gt;&amp;1; then echo "kernel log: readable"; else echo "kernel log: blocked"; fi
    ;;
  clock)
    # Sets the clock to the current second. Runs only when LAB_ALLOW_CLOCK=1 is passed.
    if [ "$LAB_ALLOW_CLOCK" != "1" ]; then echo "clock: skipped (pass LAB_ALLOW_CLOCK=1)"; exit 0; fi
    if date -s "@$(date +%s)" &gt; /dev/null 2&gt;&amp;1; then echo "clock: set allowed"; else echo "clock: set blocked"; fi
    ;;
  cgroups)
    # Test write access to the control group tree.
    if [ -w /sys/fs/cgroup ]; then echo "cgroup tree: writable"; else echo "cgroup tree: read-only"; fi
    ;;
  devices)
    # Count the entries of /dev and look for four physical or special devices.
    echo "entries in /dev: $(ls /dev | wc -l)"
    for d in /dev/mem /dev/kmsg /dev/rtc0 /dev/kvm; do
      if [ -e "$d" ]; then echo "$d: present"; else echo "$d: absent"; fi
    done
    ;;
  policy)
    # Try to read one byte from two pseudo devices.
    for d in /dev/zero /dev/urandom; do
      if head -c 1 "$d" &gt; /dev/null 2&gt;&amp;1; then echo "$d: readable"; else echo "$d: blocked"; fi
    done
    ;;
  proc)
    # Count the process directories visible in /proc, and look for a kernel information file.
    echo "process directories in /proc: $(ls /proc | grep -c '^[0-9][0-9]*$')"
    n=0
    for d in /proc/[0-9]*; do if head -c 1 "$d/status" &gt; /dev/null 2&gt;&amp;1; then n=$((n+1)); fi; done
    echo "process status files readable: $n"
    if [ -e /proc/cpuinfo ]; then echo "/proc/cpuinfo: present"; else echo "/proc/cpuinfo: absent"; fi
    ;;
  host)
    # Changes the hostname. Runs only when LAB_ALLOW_HOST=1 is passed, and only with ProtectHostname set.
    if [ "$LAB_ALLOW_HOST" != "1" ]; then echo "host: skipped (pass LAB_ALLOW_HOST=1)"; exit 0; fi
    if hostname demo-hardening-host 2&gt;/dev/null; then echo "hostname: change allowed, the unit now sees $(hostname)"; else echo "hostname: change blocked"; fi
    ;;
  caps)
    # Show which of six capabilities remain in the bounding set, and how many seccomp filters are installed.
    value=$((0x$(awk '/^CapBnd/ {print $2}' /proc/self/status)))
    for pair in CAP_SYS_MODULE:16 CAP_SYS_RAWIO:17 CAP_SYS_TIME:25 CAP_MKNOD:27 CAP_SYSLOG:34 CAP_WAKE_ALARM:35; do
      name=${pair%%:*}; bit=${pair##*:}
      if [ $(( (value &gt;&gt; bit) &amp; 1 )) -eq 1 ]; then echo "$name: kept"; else echo "$name: removed"; fi
    done
    echo "seccomp filters: $(awk '/^Seccomp_filters/ {print $2}' /proc/self/status)"
    ;;
  *)
    echo "usage: $0 tunables|modules|logs|clock|cgroups|devices|policy|proc|host|caps"
    exit 2
    ;;
esac
EOF
sudo chmod 755 /usr/local/bin/demo-hardening-lab.sh</pre>



<p class="wp-block-paragraph">Then run it through <code>systemd-run</code>, which starts a transient service that disappears when it ends. The manual describes the options: <code>--quiet</code> hides the informational messages, <code>--pipe</code> connects the output of the service to your terminal, <code>--wait</code> waits until the unit stops, <code>--collect</code> unloads the unit afterwards, and <code>-p</code> sets a property in the same format as <code>systemctl set-property</code>. First, run a baseline without any directive:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell">sudo systemd-run --quiet --pipe --wait --collect /usr/local/bin/demo-hardening-lab.sh tunables</pre>



<p class="wp-block-paragraph">Real output on the test bench:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="yaml">tunables: write allowed
kallsyms: 1 byte read</pre>



<p class="wp-block-paragraph">Now you know the baseline. In each section below, you add a directive with <code>-p</code>, compare the output and, if you want to keep it, copy the matching drop-in to a real service. When the lab is over, delete the script with <code>sudo rm /usr/local/bin/demo-hardening-lab.sh</code>; the transient units leave nothing behind.</p>



<h2 class="wp-block-heading">Kernel settings, modules and logs</h2>



<h3 class="wp-block-heading">ProtectKernelTunables</h3>



<p class="wp-block-paragraph"><code>ProtectKernelTunables=</code> makes the kernel&#8217;s settings read-only for the service. The manual lists <code>/proc/sys/</code>, <code>/sys/</code>, <code>/proc/sysrq-trigger</code>, <code>/proc/latency_stats</code>, <code>/proc/acpi</code>, <code>/proc/timer_stats</code>, <code>/proc/fs</code> and <code>/proc/irq</code> as read-only, and <code>/proc/kallsyms</code> and <code>/proc/kcore</code> as inaccessible. It also implies <code>MountAPIVFS=yes</code>. It exists since version 232 and it is off by default. The manual warns that it does not block indirect changes through other processes, and that <code>InaccessiblePaths=</code> can help.</p>



<p class="wp-block-paragraph">What breaks? A service that writes a sysctl when it starts, for example from an <code>ExecStartPre=</code> script, fails with a read-only file system error. A program that reads the kernel symbol table loses access to it.</p>



<p class="wp-block-paragraph">Try it in the lab, with and without the directive:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell">sudo systemd-run --quiet --pipe --wait --collect -p ProtectKernelTunables=yes /usr/local/bin/demo-hardening-lab.sh tunables</pre>



<p class="wp-block-paragraph">Real output on the test bench, first the baseline, then with the directive:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="yaml">tunables: write allowed
kallsyms: 1 byte read

# with ProtectKernelTunables=yes
tunables: write blocked
kallsyms: 0 byte read</pre>



<p class="wp-block-paragraph">The write is refused, as the manual says. The second line deserves an explanation. At first, my test only checked that the file could be opened, and it said &quot;readable&quot; in both cases. Actually, systemd hides <code>/proc/kallsyms</code> by mounting an empty file with mode 000 on top of it, and root can still open such a file; it just reads nothing. The evidence below comes from inside the protected service:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="ini"># inside the protected service, shortened by cutting whole lines
---------- 1 root root 0 Nov  2 14:53 /proc/kallsyms
---------- 1 root root 0 Nov  2 14:53 /proc/kcore
[...]
813 809 0:63 /systemd/inaccessible/reg /proc/kallsyms ro,nosuid,nodev,noexec shared:502 master:18 - tmpfs none rw,mode=755
814 809 0:63 /systemd/inaccessible/reg /proc/kcore ro,nosuid,nodev,noexec shared:503 master:18 - tmpfs none rw,mode=755
816 809 0:87 /sys /proc/sys ro,nosuid,nodev,noexec,relatime shared:505 - proc proc rw</pre>



<p class="wp-block-paragraph">Therefore, measure what a service can read, not whether it can open a file. That is why the lab prints the number of bytes read.</p>



<p class="wp-block-paragraph">Here is the complete drop-in for a real service:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell"># 1. Create a drop-in directory named after your service (replace myapp.service by your own unit)
sudo mkdir -p /etc/systemd/system/myapp.service.d
# 2. Write the drop-in. The [Service] header is required and the file name must end in .conf
sudo tee /etc/systemd/system/myapp.service.d/10-protect-kernel-tunables.conf &gt; /dev/null &lt;&lt;'EOF'
[Service]
# Make /proc/sys, /sys and other kernel settings read-only for this service.
ProtectKernelTunables=yes
EOF
# 3. Make systemd re-read its configuration, then restart the service
sudo systemctl daemon-reload
sudo systemctl restart myapp.service
# 4. Check that the setting is active, that the service runs and what it logged
systemctl show -p ProtectKernelTunables --value myapp.service
systemctl is-active myapp.service
sudo journalctl -u myapp.service -n 20 --no-pager
# 5. Undo everything: remove the drop-ins you created, reload and restart
sudo systemctl revert myapp.service
sudo systemctl daemon-reload
sudo systemctl restart myapp.service</pre>



<p class="wp-block-paragraph"><strong>Effect on my stack.</strong> My hardening role already writes kernel sysctls for the whole host, as my wiki lists: <code>kptr_restrict</code> and <code>dmesg_restrict</code>, a <code>ptrace_scope</code> of 1, a <code>perf_event_paranoid</code> of 3, no unprivileged user namespaces and no SUID core dumps. That protects the machine. As systemd kernel protection, <code>ProtectKernelTunables=</code> adds a lock for a single service, so that a compromised service cannot change those values at run time. None of the drop-ins I have documented uses it yet. If you run a reverse proxy, PHP-FPM, a database or a Go application, expect them not to write to <code>/proc/sys</code>. If one of your units applies a sysctl itself, expect it to fail.</p>



<h3 class="wp-block-heading">ProtectKernelModules</h3>



<p class="wp-block-paragraph"><code>ProtectKernelModules=</code> denies explicit loading and unloading of kernel modules. According to the manual, it removes <code>CAP_SYS_MODULE</code> from the bounding set, installs a system call filter for the module-related calls and makes <code>/usr/lib/modules</code> inaccessible. It exists since version 232. The manual also warns that limited automatic module loading can still happen, and that the <code>kernel.modules_disabled</code> sysctl disables that.</p>



<p class="wp-block-paragraph">What breaks? A start script that calls <code>modprobe</code> or <code>insmod</code> fails, and so does any tool that lists the installed modules.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell">sudo systemd-run --quiet --pipe --wait --collect -p ProtectKernelModules=yes /usr/local/bin/demo-hardening-lab.sh modules</pre>



<p class="wp-block-paragraph">Real output on the test bench:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell">modules directory: 4 entries

# with ProtectKernelModules=yes
modules directory: 0 entries</pre>



<p class="wp-block-paragraph">Again, the directory is not gone: it shows no entry. The evidence from inside the service shows a directory with mode 000, mounted from systemd&#8217;s own empty directory:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="ini"># shortened by cutting whole lines
[...]
d--------- 2 root root 40 Nov  2 14:53 /lib/modules
d--------- 2 root root 40 Nov  2 14:53 /usr/lib/modules
804 771 0:63 /systemd/inaccessible/dir /usr/lib/modules ro,nosuid,nodev,noexec shared:495 master:18 - tmpfs none rw,mode=755</pre>



<p class="wp-block-paragraph">The capability is gone as well. The lab script has a <code>caps</code> mode that prints six capabilities and the number of seccomp filters:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell">sudo systemd-run --quiet --pipe --wait --collect -p ProtectKernelModules=yes /usr/local/bin/demo-hardening-lab.sh caps</pre>



<pre class="EnlighterJSRAW" data-enlighter-language="yaml">CAP_SYS_MODULE: kept
CAP_SYS_RAWIO: kept
CAP_SYS_TIME: kept
CAP_MKNOD: kept
CAP_SYSLOG: kept
CAP_WAKE_ALARM: kept
seccomp filters: 1

# with ProtectKernelModules=yes
CAP_SYS_MODULE: removed
CAP_SYS_RAWIO: kept
CAP_SYS_TIME: kept
CAP_MKNOD: kept
CAP_SYSLOG: kept
CAP_WAKE_ALARM: kept
seccomp filters: 4</pre>



<pre class="EnlighterJSRAW" data-enlighter-language="shell"># 1. Create a drop-in directory named after your service (replace myapp.service by your own unit)
sudo mkdir -p /etc/systemd/system/myapp.service.d
# 2. Write the drop-in. The [Service] header is required and the file name must end in .conf
sudo tee /etc/systemd/system/myapp.service.d/10-protect-kernel-modules.conf &gt; /dev/null &lt;&lt;'EOF'
[Service]
# Forbid loading and unloading kernel modules from this service.
ProtectKernelModules=yes
EOF
# 3. Make systemd re-read its configuration, then restart the service
sudo systemctl daemon-reload
sudo systemctl restart myapp.service
# 4. Check that the setting is active, that the service runs and what it logged
systemctl show -p ProtectKernelModules --value myapp.service
systemctl is-active myapp.service
sudo journalctl -u myapp.service -n 20 --no-pager
# 5. Undo everything: remove the drop-ins you created, reload and restart
sudo systemctl revert myapp.service
sudo systemctl daemon-reload
sudo systemctl restart myapp.service</pre>



<p class="wp-block-paragraph"><strong>Effect on my stack.</strong> I already block modules for the whole host with <code>modprobe.d</code> files: unused file systems, the protocols dccp, sctp, rds and tipc, USB storage, and the modules of a ZDI-CAN-33367 mitigation (esp4, esp6, nlmon and act_pedit). That is a different mechanism from systemd kernel protection: it acts on the host. For Suricata in IPS mode, my role installs <code>kernel-modules-extra</code> for the running kernel and loads <code>nfnetlink_queue</code> and <code>xt_NFQUEUE</code> itself, before the service starts. Therefore, <code>ProtectKernelModules=</code> on the Suricata unit should not interfere with that step, but I have not tested it. A unit whose own <code>ExecStartPre=</code> loads modules would fail.</p>



<h3 class="wp-block-heading">ProtectKernelLogs</h3>



<p class="wp-block-paragraph"><code>ProtectKernelLogs=</code> keeps a service away from the kernel&#8217;s message buffer. The manual says that it removes <code>CAP_SYSLOG</code> from the bounding set, blocks the <code>syslog(2)</code> system call (not the <code>syslog(3)</code> function of the C library, which applications use to write their own logs), and makes <code>/dev/kmsg</code> and <code>/proc/kmsg</code> inaccessible. It exists since version 244.</p>



<p class="wp-block-paragraph">What breaks? Tools and agents that read <code>dmesg</code> or follow kernel messages lose that source. Applications that log through <code>syslog(3)</code> are not affected.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell">sudo systemd-run --quiet --pipe --wait --collect -p ProtectKernelLogs=yes /usr/local/bin/demo-hardening-lab.sh logs</pre>



<p class="wp-block-paragraph">Real output on the test bench:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell">kernel log: readable

# with ProtectKernelLogs=yes
kernel log: blocked</pre>



<pre class="EnlighterJSRAW" data-enlighter-language="shell"># 1. Create a drop-in directory named after your service (replace myapp.service by your own unit)
sudo mkdir -p /etc/systemd/system/myapp.service.d
# 2. Write the drop-in. The [Service] header is required and the file name must end in .conf
sudo tee /etc/systemd/system/myapp.service.d/10-protect-kernel-logs.conf &gt; /dev/null &lt;&lt;'EOF'
[Service]
# Hide the kernel log from this service.
ProtectKernelLogs=yes
EOF
# 3. Make systemd re-read its configuration, then restart the service
sudo systemctl daemon-reload
sudo systemctl restart myapp.service
# 4. Check that the setting is active, that the service runs and what it logged
systemctl show -p ProtectKernelLogs --value myapp.service
systemctl is-active myapp.service
sudo journalctl -u myapp.service -n 20 --no-pager
# 5. Undo everything: remove the drop-ins you created, reload and restart
sudo systemctl revert myapp.service
sudo systemctl daemon-reload
sudo systemctl restart myapp.service</pre>



<p class="wp-block-paragraph"><strong>Effect on my stack.</strong> My hardening role sets <code>dmesg_restrict</code> for the whole host, so that ordinary users cannot read the kernel log. Systemd kernel protection goes one step further: it also locks out a service that runs as root. If your SIEM agent or monitoring exporter collects kernel messages, expect it to lose that source.</p>



<h2 class="wp-block-heading">The clock</h2>



<h3 class="wp-block-heading">ProtectClock</h3>



<p class="wp-block-paragraph"><code>ProtectClock=</code> stops a service from changing the clock. The manual says that it removes <code>CAP_SYS_TIME</code> and <code>CAP_WAKE_ALARM</code> from the bounding set and installs a system call filter that blocks the calls able to set the clock. That filter blocks those calls entirely, even when a program only wants to read the clock state. The manual also says that it implies <code>DeviceAllow=char-rtc r</code>, so the real-time clock devices become read-only. It exists since version 245, and the manual recommends it for most services that do not need to change or check the clock.</p>



<p class="wp-block-paragraph">What breaks? Any program that sets the time, first of all time daemons such as chrony or ntpd.</p>



<p class="wp-block-paragraph">The lab sets the clock to the current second, so it only runs when you pass <code>LAB_ALLOW_CLOCK=1</code> with <code>-E</code>. It can move the clock back by less than one second, which is why you run it on a test machine only:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell">sudo systemd-run --quiet --pipe --wait --collect -E LAB_ALLOW_CLOCK=1 -p ProtectClock=yes /usr/local/bin/demo-hardening-lab.sh clock</pre>



<p class="wp-block-paragraph">Real output on the test bench:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="yaml">clock: set allowed

# with ProtectClock=yes
clock: set blocked</pre>



<p class="wp-block-paragraph">The capabilities confirm the manual. Only the changed lines are shown here; I cut the others and marked the cut:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="ini"># with ProtectClock=yes
[...]
CAP_SYS_TIME: removed
CAP_WAKE_ALARM: removed
seccomp filters: 4

# baseline
[...]
CAP_SYS_TIME: kept
CAP_WAKE_ALARM: kept
seccomp filters: 1</pre>



<p class="wp-block-paragraph">One detail surprised me. I also tried to open the real-time clock <code>/dev/rtc0</code> for writing. With <code>ProtectClock=yes</code> alone, the open still worked. With <code>ProtectClock=yes</code> and <code>DevicePolicy=closed</code>, reading worked and writing failed:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell"># ProtectClock=yes alone
open for reading: allowed
open for writing: allowed

# ProtectClock=yes and DevicePolicy=closed
open for reading: allowed
/bin/sh: line 2: /dev/rtc0: Operation not permitted</pre>



<p class="wp-block-paragraph">This agrees with the definition of the default policy: <code>DevicePolicy=auto</code> allows all devices while no explicit <code>DeviceAllow=</code> line exists. However, the entry of <code>ProtectClock=</code> does not mention it. Therefore, pair <code>ProtectClock=yes</code> with <code>DevicePolicy=closed</code> if you want the clock device itself to be read-only.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell"># 1. Create a drop-in directory named after your service (replace myapp.service by your own unit)
sudo mkdir -p /etc/systemd/system/myapp.service.d
# 2. Write the drop-in. The [Service] header is required and the file name must end in .conf
sudo tee /etc/systemd/system/myapp.service.d/10-protect-clock.conf &gt; /dev/null &lt;&lt;'EOF'
[Service]
# Forbid changing the system clock and the hardware clock from this service.
ProtectClock=yes
# Optional: closed makes the implied read-only access to the clock device effective.
DevicePolicy=closed
EOF
# 3. Make systemd re-read its configuration, then restart the service
sudo systemctl daemon-reload
sudo systemctl restart myapp.service
# 4. Check that the setting is active, that the service runs and what it logged
systemctl show -p ProtectClock --value myapp.service
systemctl is-active myapp.service
sudo journalctl -u myapp.service -n 20 --no-pager
# 5. Undo everything: remove the drop-ins you created, reload and restart
sudo systemctl revert myapp.service
sudo systemctl daemon-reload
sudo systemctl restart myapp.service</pre>



<p class="wp-block-paragraph"><strong>Effect on my stack.</strong> Chrony runs on my hosts, as my notes say, and a time daemon is exactly the service that must keep <code>ProtectClock=</code> off, because it has to set the clock. For a reverse proxy, a database or an application server, I would expect systemd kernel protection of the clock to be safe there, but test it first.</p>



<h2 class="wp-block-heading">Control groups</h2>



<h3 class="wp-block-heading">ProtectControlGroups</h3>



<p class="wp-block-paragraph"><code>ProtectControlGroups=</code> protects the control group file system. The manual says that <code>yes</code> makes <code>/sys/fs/cgroup/</code> read-only. The current manual also documents two more values: <code>private</code>, which runs the unit in a cgroup namespace with a private writable <code>/sys/fs/cgroup/</code>, and <code>strict</code>, which does the same with a read-only tree. Both fall back to <code>no</code> and <code>yes</code> when the system lacks the unified hierarchy or cgroup namespaces. The directive implies <code>MountAPIVFS=yes</code>, it exists since version 232, and it applies to system services only.</p>



<p class="wp-block-paragraph">What breaks? Container runtimes and any service that creates or edits control groups, because they write into that tree.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell">sudo systemd-run --quiet --pipe --wait --collect -p ProtectControlGroups=yes /usr/local/bin/demo-hardening-lab.sh cgroups</pre>



<p class="wp-block-paragraph">Real output on the test bench:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell">cgroup tree: writable

# with ProtectControlGroups=yes
cgroup tree: read-only</pre>



<p class="wp-block-paragraph">Next, I tried the two newer values. My systemd 257 does not know them yet:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell">sudo systemd-run --quiet --pipe --wait --collect -p ProtectControlGroups=private /usr/local/bin/demo-hardening-lab.sh cgroups

# real output on the test bench:
Failed to parse ProtectControlGroups: private</pre>



<p class="wp-block-paragraph">The manual does not give a separate version number for these values. Therefore, check <code>systemctl --version</code> and the manual of your own version before you use them. <code>strict</code> failed in the same way on my bench.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell"># 1. Create a drop-in directory named after your service (replace myapp.service by your own unit)
sudo mkdir -p /etc/systemd/system/myapp.service.d
# 2. Write the drop-in. The [Service] header is required and the file name must end in .conf
sudo tee /etc/systemd/system/myapp.service.d/10-protect-control-groups.conf &gt; /dev/null &lt;&lt;'EOF'
[Service]
# Make the control group tree read-only for this service.
ProtectControlGroups=yes
EOF
# 3. Make systemd re-read its configuration, then restart the service
sudo systemctl daemon-reload
sudo systemctl restart myapp.service
# 4. Check that the setting is active, that the service runs and what it logged
systemctl show -p ProtectControlGroups --value myapp.service
systemctl is-active myapp.service
sudo journalctl -u myapp.service -n 20 --no-pager
# 5. Undo everything: remove the drop-ins you created, reload and restart
sudo systemctl revert myapp.service
sudo systemctl daemon-reload
sudo systemctl restart myapp.service</pre>



<p class="wp-block-paragraph"><strong>Effect on my stack.</strong> I run Stamus Clear NDR with Podman in a virtual machine. I have not tried systemd kernel protection there. If one of your units starts containers with Podman or Docker, expect it to fail, because those tools manage control groups.</p>



<h2 class="wp-block-heading">Devices</h2>



<figure class="wp-block-image size-full"><a href="https://hecate.neurozone.fr/wp-content/uploads/2026/11/systemd-kernel-protection-device-policy_en.webp"><img decoding="async" width="1720" height="760" src="https://hecate.neurozone.fr/wp-content/uploads/2026/11/systemd-kernel-protection-device-policy_en.webp" alt="Systemd kernel protection of devices: the three levels of DevicePolicy and the minimal /dev of PrivateDevices" class="wp-image-3475" srcset="https://hecate.neurozone.fr/wp-content/uploads/2026/11/systemd-kernel-protection-device-policy_en.webp 1720w, https://hecate.neurozone.fr/wp-content/uploads/2026/11/systemd-kernel-protection-device-policy_en-300x133.webp 300w, https://hecate.neurozone.fr/wp-content/uploads/2026/11/systemd-kernel-protection-device-policy_en-1024x452.webp 1024w, https://hecate.neurozone.fr/wp-content/uploads/2026/11/systemd-kernel-protection-device-policy_en-768x339.webp 768w, https://hecate.neurozone.fr/wp-content/uploads/2026/11/systemd-kernel-protection-device-policy_en-1536x679.webp 1536w" sizes="(max-width: 800px) 100vw, 760px" /></a><figcaption class="wp-element-caption">The three levels of DevicePolicy and what PrivateDevices changes in /dev.</figcaption></figure>



<h3 class="wp-block-heading">PrivateDevices</h3>



<p class="wp-block-paragraph"><code>PrivateDevices=</code> gives the service a new, minimal <code>/dev/</code>. According to the manual, that directory contains only the pseudo devices of the API, such as <code>/dev/null</code>, <code>/dev/zero</code> and <code>/dev/random</code>, plus the pseudo terminals. Physical devices such as <code>/dev/sda</code>, <code>/dev/mem</code> and <code>/dev/port</code> are not there. The private <code>/dev/</code> is read-only and <code>noexec</code>. The directive also installs a filter that blocks the <code>@raw-io</code> system calls, removes <code>CAP_MKNOD</code> and <code>CAP_SYS_RAWIO</code>, and sets <code>DevicePolicy=closed</code>. It exists since version 209. The manual warns that programs which map memory through <code>/dev/zero</code> instead of <code>MAP_ANON</code> may break, and that the directive may be impossible to implement on some systems, so you should not rely on it alone.</p>



<p class="wp-block-paragraph">What breaks? Anything that needs real hardware: a GPU, a disk read as a block device, a USB serial adapter or <code>/dev/kvm</code>.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell">sudo systemd-run --quiet --pipe --wait --collect -p PrivateDevices=yes /usr/local/bin/demo-hardening-lab.sh devices</pre>



<p class="wp-block-paragraph">Real output on the test bench:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell"># baseline
entries in /dev: 190
/dev/mem: present
/dev/kmsg: present
/dev/rtc0: present
/dev/kvm: present

# with PrivateDevices=yes
entries in /dev: 18
/dev/mem: absent
/dev/kmsg: absent
/dev/rtc0: absent
/dev/kvm: absent</pre>



<p class="wp-block-paragraph">The number of entries in <code>/dev</code> drops from 190 to 18, and the four special devices disappear. The lab also confirms the capabilities and the implied policy:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="ini"># capabilities, with PrivateDevices=yes (other lines cut)
[...]
CAP_SYS_RAWIO: removed
CAP_MKNOD: removed

# systemctl show on a running unit that also sets PrivateDevices=yes (other lines cut)
[...]
DevicePolicy=closed
PrivateDevices=yes</pre>



<pre class="EnlighterJSRAW" data-enlighter-language="shell"># 1. Create a drop-in directory named after your service (replace myapp.service by your own unit)
sudo mkdir -p /etc/systemd/system/myapp.service.d
# 2. Write the drop-in. The [Service] header is required and the file name must end in .conf
sudo tee /etc/systemd/system/myapp.service.d/10-private-devices.conf &gt; /dev/null &lt;&lt;'EOF'
[Service]
# Give this service a minimal /dev without physical devices.
PrivateDevices=yes
EOF
# 3. Make systemd re-read its configuration, then restart the service
sudo systemctl daemon-reload
sudo systemctl restart myapp.service
# 4. Check that the setting is active, that the service runs and what it logged
systemctl show -p PrivateDevices --value myapp.service
systemctl is-active myapp.service
sudo journalctl -u myapp.service -n 20 --no-pager
# 5. Undo everything: remove the drop-ins you created, reload and restart
sudo systemctl revert myapp.service
sudo systemctl daemon-reload
sudo systemctl restart myapp.service</pre>



<p class="wp-block-paragraph"><strong>Effect on my stack.</strong> My media server uses NVENC hardware transcoding when an NVIDIA card is present. Such a service needs the device nodes of the GPU, so <code>PrivateDevices=yes</code> would hide them. Use <code>DeviceAllow=</code> instead. List the device group names of your machine with <code>grep -i nvidia /proc/devices</code> and check them against the manual. A database, a reverse proxy or a PHP-FPM pool normally needs only files and sockets, so expect <code>PrivateDevices=yes</code> to be a good candidate there.</p>



<h3 class="wp-block-heading">DevicePolicy and DeviceAllow</h3>



<p class="wp-block-paragraph">These two directives work together. The manual says that <code>DevicePolicy=</code> accepts <code>auto</code>, <code>closed</code> and <code>strict</code>, and that each value adds to the one before it. <code>strict</code> allows only the access types that you list. <code>closed</code> also allows the standard pseudo devices such as <code>/dev/null</code>, <code>/dev/zero</code>, <code>/dev/full</code>, <code>/dev/random</code> and <code>/dev/urandom</code>. <code>auto</code>, the default, also allows every device while no explicit <code>DeviceAllow=</code> line exists. A <code>+</code> prefix on the executable path does not bypass the policy. Both directives exist since version 208.</p>



<p class="wp-block-paragraph"><code>DeviceAllow=</code> takes two strings: a device specifier, then a combination of <code>r</code> (read), <code>w</code> (write) and <code>m</code> (create the node). The specifier is either a path that starts with <code>/dev/</code> (without wildcards) or <code>char-</code> or <code>block-</code> followed by a group name from <code>/proc/devices</code>, such as <code>char-pts</code> or <code>block-loop</code>, where <code>*</code> and <code>?</code> are allowed. The manual says that the groups must be resolvable when the unit starts, and it suggests <code>Wants=modprobe@xyz.service</code> with <code>After=modprobe@xyz.service</code> to load the module first. It implements the filter with eBPF.</p>



<p class="wp-block-paragraph">What breaks? With <code>strict</code>, everything you forget to list, starting with <code>/dev/null</code>.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell">sudo systemd-run --quiet --pipe --wait --collect -p DevicePolicy=strict -p 'DeviceAllow=/dev/null rw' -p 'DeviceAllow=/dev/zero r' /usr/local/bin/demo-hardening-lab.sh policy</pre>



<p class="wp-block-paragraph">Real output on the test bench, for the default policy, for <code>closed</code> and for <code>strict</code> with a two-line allow list:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell"># baseline (DevicePolicy=auto)
/dev/zero: readable
/dev/urandom: readable

# DevicePolicy=closed
/dev/zero: readable
/dev/urandom: readable

# DevicePolicy=strict, allow /dev/null (rw) and /dev/zero (r)
/dev/zero: readable
/dev/urandom: blocked</pre>



<p class="wp-block-paragraph">The allow list works: <code>/dev/zero</code> stays readable and <code>/dev/urandom</code> is refused. Next, the classic mistake. Without any <code>DeviceAllow=</code>, <code>strict</code> even refuses <code>/dev/null</code>, which almost every program opens:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell">/bin/sh: line 1: /dev/null: Operation not permitted
redirect to /dev/null: blocked

# the same test with DeviceAllow=/dev/null rw
redirect to /dev/null: allowed</pre>



<pre class="EnlighterJSRAW" data-enlighter-language="shell"># 1. Create a drop-in directory named after your service (replace myapp.service by your own unit)
sudo mkdir -p /etc/systemd/system/myapp.service.d
# 2. Write the drop-in. The [Service] header is required and the file name must end in .conf
sudo tee /etc/systemd/system/myapp.service.d/10-device-policy.conf &gt; /dev/null &lt;&lt;'EOF'
[Service]
# Allow only the devices that this service really needs.
DevicePolicy=strict
DeviceAllow=/dev/null rw
DeviceAllow=/dev/zero r
DeviceAllow=/dev/urandom r
EOF
# 3. Make systemd re-read its configuration, then restart the service
sudo systemctl daemon-reload
sudo systemctl restart myapp.service
# 4. Check that the setting is active, that the service runs and what it logged
systemctl show -p DevicePolicy --value myapp.service
systemctl is-active myapp.service
sudo journalctl -u myapp.service -n 20 --no-pager
# 5. Undo everything: remove the drop-ins you created, reload and restart
sudo systemctl revert myapp.service
sudo systemctl daemon-reload
sudo systemctl restart myapp.service</pre>



<p class="wp-block-paragraph"><strong>Effect on my stack.</strong> In systemd kernel protection, this pair is the right tool for the GPU of my media server: keep the device policy tight and add one <code>DeviceAllow=</code> line per device group of the card. Start from <code>closed</code>, then add the groups that the journal says are missing.</p>



<h2 class="wp-block-heading">The /proc view</h2>



<figure class="wp-block-image size-full"><a href="https://hecate.neurozone.fr/wp-content/uploads/2026/11/systemd-kernel-protection-proc-view_en.webp"><img decoding="async" width="1720" height="620" src="https://hecate.neurozone.fr/wp-content/uploads/2026/11/systemd-kernel-protection-proc-view_en.webp" alt="Systemd kernel protection of the /proc view: process directories and readable status files with ProtectProc and ProcSubset" class="wp-image-3474" srcset="https://hecate.neurozone.fr/wp-content/uploads/2026/11/systemd-kernel-protection-proc-view_en.webp 1720w, https://hecate.neurozone.fr/wp-content/uploads/2026/11/systemd-kernel-protection-proc-view_en-300x108.webp 300w, https://hecate.neurozone.fr/wp-content/uploads/2026/11/systemd-kernel-protection-proc-view_en-1024x369.webp 1024w, https://hecate.neurozone.fr/wp-content/uploads/2026/11/systemd-kernel-protection-proc-view_en-768x277.webp 768w, https://hecate.neurozone.fr/wp-content/uploads/2026/11/systemd-kernel-protection-proc-view_en-1536x554.webp 1536w" sizes="(max-width: 800px) 100vw, 760px" /></a><figcaption class="wp-element-caption">What a service running as nobody sees in /proc, measured on the test bench.</figcaption></figure>



<h3 class="wp-block-heading">ProtectProc</h3>



<p class="wp-block-paragraph"><code>ProtectProc=</code> sets the <code>hidepid=</code> mount option of the service&#8217;s own <code>/proc</code>. The manual lists four values: <code>default</code> (no restriction), <code>noaccess</code> (the service loses access to most of the process metadata of other users), <code>invisible</code> (processes of other users disappear) and <code>ptraceable</code> (it hides the processes the service cannot <code>ptrace()</code>). It implies <code>MountAPIVFS=yes</code> and exists since version 247. The manual adds three conditions. Root is not affected, so you must combine the directive with <code>User=</code> or <code>DynamicUser=yes</code>. It has no effect if the service holds <code>CAP_SYS_PTRACE</code>. And it does nothing if the kernel lacks per-mount <code>hidepid=</code> support.</p>



<p class="wp-block-paragraph">What breaks? Monitoring agents, process listing tools and anything that needs to see other users&#8217; processes.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell">sudo systemd-run --quiet --pipe --wait --collect -p User=nobody -p ProtectProc=invisible /usr/local/bin/demo-hardening-lab.sh proc</pre>



<p class="wp-block-paragraph">Real output on the test bench. The lab counts the process directories that <code>/proc</code> shows and the <code>status</code> files that it can read. The numbers change from one run to another because processes come and go, but the proportions are stable:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell"># User=nobody, baseline
process directories in /proc: 39
process status files readable: 36
/proc/cpuinfo: present

# User=nobody, ProtectProc=invisible
process directories in /proc: 4
process status files readable: 1
/proc/cpuinfo: present

# User=nobody, ProtectProc=noaccess
process directories in /proc: 39
process status files readable: 1
/proc/cpuinfo: present

# User=nobody, ProtectProc=ptraceable
process directories in /proc: 4
process status files readable: 1
/proc/cpuinfo: present</pre>



<p class="wp-block-paragraph">The result matches the manual. With <code>invisible</code> and <code>ptraceable</code>, the unit sees 4 process directories instead of 39. With <code>noaccess</code>, the directories are still listed, but only one <code>status</code> file stays readable. Finally, I ran the same test as root, without <code>User=</code>:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell"># root, ProtectProc=invisible
process directories in /proc: 39
process status files readable: 36
/proc/cpuinfo: present</pre>



<p class="wp-block-paragraph">Nothing changed, as the manual announces: root is not affected.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell"># 1. Create a drop-in directory named after your service (replace myapp.service by your own unit)
sudo mkdir -p /etc/systemd/system/myapp.service.d
# 2. Write the drop-in. The [Service] header is required and the file name must end in .conf
sudo tee /etc/systemd/system/myapp.service.d/10-protect-proc.conf &gt; /dev/null &lt;&lt;'EOF'
[Service]
# Hide the processes of other users from this service. It must not run as root.
User=myapp
ProtectProc=invisible
EOF
# 3. Make systemd re-read its configuration, then restart the service
sudo systemctl daemon-reload
sudo systemctl restart myapp.service
# 4. Check that the setting is active, that the service runs and what it logged
systemctl show -p ProtectProc --value myapp.service
systemctl is-active myapp.service
sudo journalctl -u myapp.service -n 20 --no-pager
# 5. Undo everything: remove the drop-ins you created, reload and restart
sudo systemctl revert myapp.service
sudo systemctl daemon-reload
sudo systemctl restart myapp.service</pre>



<p class="wp-block-paragraph"><strong>Effect on my stack.</strong> If you run an agent that inventories processes, such as a SIEM agent, expect <code>invisible</code> to blind it. Web applications and databases that run under their own user normally do not look at other users&#8217; processes, so they are good candidates for systemd kernel protection.</p>



<h3 class="wp-block-heading">ProcSubset</h3>



<p class="wp-block-paragraph"><code>ProcSubset=</code> accepts <code>all</code> (the default) and <code>pid</code>. With <code>pid</code>, the service&#8217;s <code>/proc</code> keeps only the files that belong to process management and introspection. The manual says that it sets the <code>subset=</code> mount option, that it implies <code>MountAPIVFS=yes</code>, that it has the same restrictions as <code>ProtectProc=</code>, and that many kernel APIs under <code>/proc</code> become unavailable, so it suits only a few specific cases. It exists since version 247.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell">sudo systemd-run --quiet --pipe --wait --collect -p User=nobody -p ProcSubset=pid /usr/local/bin/demo-hardening-lab.sh proc</pre>



<p class="wp-block-paragraph">Real output on the test bench:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell">process directories in /proc: 39
process status files readable: 36
/proc/cpuinfo: absent</pre>



<p class="wp-block-paragraph">All the processes remain visible, but <code>/proc/cpuinfo</code> is gone. Therefore, expect programs that read <code>/proc/cpuinfo</code> or <code>/proc/meminfo</code> to fail.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell"># 1. Create a drop-in directory named after your service (replace myapp.service by your own unit)
sudo mkdir -p /etc/systemd/system/myapp.service.d
# 2. Write the drop-in. The [Service] header is required and the file name must end in .conf
sudo tee /etc/systemd/system/myapp.service.d/10-proc-subset.conf &gt; /dev/null &lt;&lt;'EOF'
[Service]
# Show only the process files in /proc for this service.
ProcSubset=pid
EOF
# 3. Make systemd re-read its configuration, then restart the service
sudo systemctl daemon-reload
sudo systemctl restart myapp.service
# 4. Check that the setting is active, that the service runs and what it logged
systemctl show -p ProcSubset --value myapp.service
systemctl is-active myapp.service
sudo journalctl -u myapp.service -n 20 --no-pager
# 5. Undo everything: remove the drop-ins you created, reload and restart
sudo systemctl revert myapp.service
sudo systemctl daemon-reload
sudo systemctl restart myapp.service</pre>



<p class="wp-block-paragraph"><strong>Effect on my stack.</strong> Keep this directive for small, simple services, because language runtimes and exporters often read system files from <code>/proc</code>.</p>



<h2 class="wp-block-heading">The hostname</h2>



<h3 class="wp-block-heading">ProtectHostname</h3>



<p class="wp-block-paragraph"><code>ProtectHostname=</code> takes a boolean or <code>private</code>. The manual says that <code>yes</code> gives the unit its own UTS namespace and blocks <code>sethostname()</code> and <code>setdomainname()</code>, and that <code>private</code> allows the changes but confines them to that namespace. A hostname can follow a colon, as in <code>yes:foo</code>. In both cases, the unit no longer sees later changes of the host&#8217;s hostname. The directive does not block <code>hostnamectl</code>: use <code>User=</code> and <code>Group=</code> for that. It exists since version 242.</p>



<p class="wp-block-paragraph">What breaks? Almost nothing in practice: only programs that set a hostname, such as installers, some container tools or network setup scripts.</p>



<p class="wp-block-paragraph">The lab changes a hostname, so it only runs when you pass <code>LAB_ALLOW_HOST=1</code>, and you must always pair it with <code>ProtectHostname</code>. Without the directive, the script would change the real hostname of the machine. Note the guard first:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell">sudo systemd-run --quiet --pipe --wait --collect /usr/local/bin/demo-hardening-lab.sh host

# real output on the test bench (no directive, no LAB_ALLOW_HOST):
host: skipped (pass LAB_ALLOW_HOST=1)</pre>



<pre class="EnlighterJSRAW" data-enlighter-language="shell">sudo systemd-run --quiet --pipe --wait --collect -E LAB_ALLOW_HOST=1 -p ProtectHostname=yes /usr/local/bin/demo-hardening-lab.sh host

# real output on the test bench:
hostname: change blocked
[host hostname unchanged: yes]</pre>



<p class="wp-block-paragraph">The change is refused, and I checked that the hostname of the machine was unchanged afterwards. The <code>private</code> value failed on my bench, for the same reason as the control group values:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell">sudo systemd-run --quiet --pipe --wait --collect -E LAB_ALLOW_HOST=1 -p ProtectHostname=private /usr/local/bin/demo-hardening-lab.sh host

# real output on the test bench:
Failed to parse ProtectHostname: private</pre>



<p class="wp-block-paragraph">Systemd 257 does not know <code>private</code>, while the current manual documents it. Check your version before you rely on it.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell"># 1. Create a drop-in directory named after your service (replace myapp.service by your own unit)
sudo mkdir -p /etc/systemd/system/myapp.service.d
# 2. Write the drop-in. The [Service] header is required and the file name must end in .conf
sudo tee /etc/systemd/system/myapp.service.d/10-protect-hostname.conf &gt; /dev/null &lt;&lt;'EOF'
[Service]
# Forbid changing the hostname from this service.
ProtectHostname=yes
EOF
# 3. Make systemd re-read its configuration, then restart the service
sudo systemctl daemon-reload
sudo systemctl restart myapp.service
# 4. Check that the setting is active, that the service runs and what it logged
systemctl show -p ProtectHostname --value myapp.service
systemctl is-active myapp.service
sudo journalctl -u myapp.service -n 20 --no-pager
# 5. Undo everything: remove the drop-ins you created, reload and restart
sudo systemctl revert myapp.service
sudo systemctl daemon-reload
sudo systemctl restart myapp.service</pre>



<p class="wp-block-paragraph"><strong>Effect on my stack.</strong> My notes mention no service that sets a hostname, so I would expect this to be the safest directive of systemd kernel protection.</p>



<h2 class="wp-block-heading">Measure the result with systemd-analyze security</h2>



<p class="wp-block-paragraph">Now that you know the ten directives of systemd kernel protection, you can measure their combined effect. I started a transient service that only sleeps, first without any directive and then with all nine protections of this part at once. The manual describes the overall value as an exposure level from 0.0 to 10.0. Here is what the tool printed, with the other lines cut:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="ini"># no directive
[...]
→ Overall exposure level for demo-hardening-lab-probe.service: 9.6 UNSAFE <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f628.png" alt="😨" class="wp-smiley" style="height: 1em; max-height: 1em;" />

# with ProtectKernelTunables, ProtectKernelModules, ProtectKernelLogs, ProtectClock,
# ProtectControlGroups, PrivateDevices, ProtectProc=invisible, ProcSubset=pid and ProtectHostname
[...]
→ Overall exposure level for demo-hardening-lab-probe.service: 7.3 MEDIUM <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f610.png" alt="😐" class="wp-smiley" style="height: 1em; max-height: 1em;" /></pre>



<p class="wp-block-paragraph">The score fell from 9.6 to 7.3. Each directive of this part has a small weight, between 0.1 and 0.2 on this bench, as the unprotected run shows:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell">✗ PrivateDevices=                                             Service potentially has access to hardware devices                           0.2
✗ ProtectClock=                                               Service may write to the hardware clock or system clock                      0.2
✗ ProtectKernelLogs=                                          Service may read from or write to the kernel log ring buffer                 0.2
✗ ProtectControlGroups=                                       Service may modify the control group file system                             0.2
✗ ProtectKernelModules=                                       Service may load or read kernel modules                                      0.2
✗ ProtectHostname=                                            Service may change system host/domainname                                    0.1
✗ ProtectKernelTunables=                                      Service may alter kernel tunables                                            0.2
✗ ProtectProc=                                                Service has full access to process tree (/proc hidepid=)                     0.2
✗ ProcSubset=                                                 Service has full access to non-process /proc files (/proc subset=)           0.1</pre>



<p class="wp-block-paragraph">A single directive therefore moves the score only a little. For example, a demo unit with only <code>ProtectKernelTunables=yes</code> went from 9.6 to 9.2. Use the score to find protections you have not looked at yet, not as a goal.</p>



<h2 class="wp-block-heading">Common mistakes</h2>



<ol class="wp-block-list"><li><strong>Editing the file that the package installed.</strong> An update will replace it. Use a drop-in instead.</li><li><strong>Forgetting <code>daemon-reload</code>.</strong> After you write a drop-in by hand, systemd keeps the old configuration until you reload it. <code>systemctl edit</code> reloads for you.</li><li><strong>Enabling several directives at once.</strong> When the service fails, you do not know which one caused it. Change one directive, restart, read the journal.</li><li><strong>Using <code>ProtectProc=</code> on a root service.</strong> The manual says that root is not affected, and my test showed no change. Combine it with <code>User=</code> or <code>DynamicUser=yes</code>.</li><li><strong>Switching on <code>ProtectClock=</code> for a time daemon.</strong> Chrony or ntpd must set the clock.</li><li><strong>Using <code>PrivateDevices=yes</code> on a service that needs hardware.</strong> Use <code>DeviceAllow=</code> for the devices it needs.</li><li><strong>Forgetting <code>/dev/null</code> with <code>DevicePolicy=strict</code>.</strong> My test shows the error: <code>Operation not permitted</code>.</li><li><strong>Expecting <code>ProtectKernelModules=</code> to stop every module load.</strong> The manual says that limited automatic loading can still happen.</li><li><strong>Trusting an empty file as a proof.</strong> A hidden path is an empty node with mode 000. Measure what the service reads, not whether it can open the file.</li><li><strong>Using a value that your systemd does not know.</strong> <code>private</code> and <code>strict</code> failed on systemd 257. Check <code>systemctl --version</code> and the manual of your version.</li></ol>



<h2 class="wp-block-heading">Final checklist</h2>



<p class="wp-block-paragraph">Check these points each time you add systemd kernel protection to a service.</p>



<ul class="wp-block-list"><li>I tested on a non-critical service or a test machine, with a snapshot or a console.</li><li>I know my systemd version and I read the manual page of that version.</li><li>I added one directive at a time in a drop-in under <code>/etc/systemd/system/UNIT.d/</code>.</li><li>I ran <code>systemctl daemon-reload</code> and restarted the service.</li><li>I checked the property with <code>systemctl show -p NAME --value</code> and read the journal.</li><li>I measured the effect instead of assuming it (bytes read, entries counted, error messages).</li><li>I know how to undo it: <code>systemctl revert</code>, reload, restart.</li></ul>



<h2 class="wp-block-heading">What I take away from systemd kernel protection</h2>



<ul class="wp-block-list"><li><strong>Most of these directives cost nothing</strong> on services that only use files and sockets. A reverse proxy, a database or an application server rarely needs the kernel interfaces that they close.</li><li><strong>The exceptions are predictable.</strong> Time daemons need the clock, GPU users need device nodes, container runtimes need control groups, and monitoring agents need the full <code>/proc</code>.</li><li><strong>Hidden does not mean absent.</strong> Systemd mounts empty mode-000 nodes over the paths it protects. Root can open them but reads nothing, so tests must count what they read.</li><li><strong>Defaults hide traps.</strong> <code>DevicePolicy=auto</code> keeps every device open while no explicit <code>DeviceAllow=</code> exists, so <code>ProtectClock=</code> alone did not make the clock device read-only on my bench.</li><li><strong>Versions matter.</strong> The values <code>private</code> and <code>strict</code> of <code>ProtectControlGroups=</code> and <code>private</code> of <code>ProtectHostname=</code> do not exist in systemd 257.</li><li><strong>The host settings and the service settings complement each other.</strong> Sysctls and module blacklists protect the machine, while systemd kernel protection limits each service.</li></ul>



<h2 class="wp-block-heading">Sources</h2>



<ul class="wp-block-list"><li><a href="https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html">systemd.exec(5)</a>: ProtectKernelTunables, ProtectKernelModules, ProtectKernelLogs, ProtectClock, ProtectControlGroups, PrivateDevices, ProtectProc, ProcSubset, ProtectHostname</li><li><a href="https://www.freedesktop.org/software/systemd/man/latest/systemd.resource-control.html">systemd.resource-control(5)</a>: DevicePolicy, DeviceAllow</li><li><a href="https://www.freedesktop.org/software/systemd/man/latest/systemd.unit.html">systemd.unit(5)</a>: drop-ins and precedence</li><li><a href="https://www.freedesktop.org/software/systemd/man/latest/systemctl.html">systemctl(1)</a>, <a href="https://www.freedesktop.org/software/systemd/man/latest/systemd-run.html">systemd-run(1)</a>, <a href="https://www.freedesktop.org/software/systemd/man/latest/systemd-analyze.html">systemd-analyze(1)</a> and <a href="https://www.freedesktop.org/software/systemd/man/latest/journalctl.html">journalctl(1)</a></li><li>My own notes for the facts about my stack, and the test bench described in the section &quot;Before you start&quot;.</li></ul>



<h2 class="wp-block-heading">Earlier in this series</h2>



<ul class="wp-block-list"><li><a href="https://hecate.neurozone.fr/?p=3481">Systemd hardening, directive by directive: measuring with systemd-analyze security</a></li><li><a href="https://hecate.neurozone.fr/?p=3491">Systemd filesystem protection: hardening part 2, directive by directive</a></li><li><a href="https://hecate.neurozone.fr/?p=3486">Systemd capabilities: from root to one single privilege, with a tested lab</a></li></ul>



<h2 class="wp-block-heading">Related articles</h2>



<ul class="wp-block-list"><li><a href="https://hecate.neurozone.fr/?p=1485">ZDI-CAN-33367: when an avoided copy writes into a read-only file</a></li><li><a href="https://hecate.neurozone.fr/?p=599">How-to: Suricata as an IPS with NFQUEUE, without breaking your server</a></li><li><a href="https://hecate.neurozone.fr/?p=624">How-to: install a Wazuh agent and get something out of it</a></li></ul>


<p>The post <a href="https://hecate.neurozone.fr/2026/11/28/systemd-kernel-protection-directives-tunables-modules-devices/">Systemd kernel protection: ProtectKernelTunables, PrivateDevices and the other kernel and device directives</a> appeared first on <a href="https://hecate.neurozone.fr">Hécate Regnier - Neurozone</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://hecate.neurozone.fr/2026/11/28/systemd-kernel-protection-directives-tunables-modules-devices/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3476</post-id>	</item>
	</channel>
</rss>
