85 Banned Syscalls, Zero Effect: What systemd Hardening Actually Stops
Every out-of-tree hardening template for systemd ships the same two lines: ban fork, ban execve. The reasoning holds on paper — a compromised webapp should n...
Every out-of-tree hardening template for systemd ships the same two lines: ban fork, ban execve. The reasoning holds on paper — a compromised webapp should not be able to spawn a shell. I put both on real units under systemd 257.13 on kernel 6.12.94 and measured. One is inert. The other prevents the unit from starting, because systemd installs the seccomp filter before it calls execve on your binary, not after.
Eighty-five syscalls is an inventory, not a boundary
The filter language is bigger than most templates admit. systemd-analyze syscall-filter on this host defines 30 groups covering 1,056 syscall names. The nine groups in the common recipe union to 72, and 27 of those come from @obsolete alone: _sysctl, afs_syscall, bdflush, break, create_module, ftime. None of them exist on x86-64 in 6.12. A third of the denylist is archaeology.
| Group | Names |
|---|---|
@obsolete | 27 |
@mount | 12 |
@debug | 7 |
@raw-io | 7 |
@clock | 6 |
@cpu-emulation | 5 |
@module | 3 |
@reboot | 3 |
@swap | 2 |
Add the 13 named entries — three io_uring, bpf, two fanotify, userfaultfd, two process_vm_*, two execve*, two fork* — and the set totals 85 with no overlap between groups. That is 8% of the table, chosen by exclusion. The kernel keeps adding syscalls; a denylist ages into a list of things that used to matter.
$ systemd-analyze syscall-filter --no-pager | grep -c '^@'
30
$ systemd-analyze syscall-filter @system-service --no-pager | wc -l
61
The allowlist argument runs backwards from expectation: @system-service is 61 names. It is smaller than the denylist it replaces, denies everything else by construction, and costs the same at runtime — as the numbers below show.
Three services used 64 syscalls, and the denylist collides with three
Filter design starts with knowing what the process actually calls. I traced one HTTP server per runtime through startup plus twenty requests, using strace -f -e trace=all around the process and a second Python client driving the socket.
| Runtime | Distinct names | Calls traced | Hits in the 85-entry denylist |
|---|---|---|---|
| Go 1.24.4, static | 40 | 1,019 | execve |
| Node.js 26.8.1 | 54 | 1,101 | execve, io_uring_setup, io_uring_enter |
| Python 3.13.5 | 39 | 1,480 | execve |
Combined, the three touch 64 distinct names out of 1,056. Against those 64, the denylist overlaps in exactly three, and one of them — execve — is systemd launching the process, not the process launching anything. So the recipe's real behavioural effect on this workload is a single change: Node's io_uring path disappears.
That change is survivable and worth understanding. Node reaches for io_uring through libuv during startup and file I/O. With the three calls returning EPERM, the same server answers the same 200 with the same body, because libuv falls back to its thread pool for filesystem work. You trade a fast async file path for a ban on a subsystem that has produced a steady stream of local privilege escalation bugs. Defensible — but it is not the trade the template advertises.
A denylist does not stop a compromised webapp from reading/etc/shadowthrough a path traversal. It stops it from loadingio_uring. Only one of those ships in the box.
fork() never calls fork, so the fork ban is decoration
Banning fork and vfork is meant to stop process creation. It does not, because against glibc 2.41 fork() is not a syscall — it is a wrapper over clone:
$ strace -f -e trace=clone,fork,vfork,execve ./forktest
execve("./forktest", ["./forktest"], 0x7ffe4decf340 /* 106 vars */) = 0
clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD,
child_tidptr=0x7fc3afa27a10) = 485754
[pid 485754] execve("/bin/true", ["true"], 0x7fff1851da48 /* 106 vars */) = 0
A program that calls fork() then execl("/bin/true") was run under five filter sets. The whole argument fits in one table:
| SystemCallFilter | Child status | Cause |
|---|---|---|
| (none) | 0 | fork via clone, exec succeeds |
~fork vfork | 0 | no protection: fork was never called |
~clone3 | 0 | glibc retries through clone |
~clone | fork: Operation not permitted | the only line that stops fork() |
~@process | fork: Operation not permitted | same effect, 22 names wide |
Banning clone is the honest version of the intent and also the one that breaks every thread pool you own: threads are clone with CLONE_THREAD. Banning clone3 alone is worse than useless, since glibc silently retries the legacy path. That leaves two workable options — ban clone only on genuinely single-threaded services, or stop pretending the syscall layer owns process creation and enforce on paths instead of verbs.
execve cannot be banned in the unit that needs it
systemd installs the filter in the forked child immediately before executing your binary. SystemCallFilter=~execve therefore denies the one call systemd is about to make:
$ systemd-run -p SystemCallFilter=~execve -p SystemCallErrorNumber=EPERM --unit=probe-execve /bin/echo hi ; echo "rc=$?"
rc=203
$ journalctl -u probe-execve -o cat
probe-execve.service: Failed to execute /bin/echo: Operation not permitted
probe-execve.service: Failed at step EXEC spawning /bin/echo: Operation not permitted
probe-execve.service: Main process exited, code=exited, status=203/EXEC
203 is EXIT_EXEC: the unit never starts. The failure is one journal line deep, which is exactly why the line survives in templates — you hit it on first deploy, delete the line, and keep the rest of the recipe believing it works. The comment "comment this out if your server needs it" understates the case. Your server needs it once, unconditionally, and the filter cannot distinguish that call from an attacker's.
The control that does work lives one layer down, where you enumerate paths instead of syscalls:
[Service]
NoExecPaths=/
ExecPaths=/usr/lib /usr/lib64 /lib /lib64
ExecPaths=/usr/bin/my_daemon
ExecPaths=/bin/sh
ExecPaths=/usr/bin/awk
Measured: /bin/bash in that namespace runs normally, and the same shell executing /bin/ls dies with Permission denied and exit 126. The daemon forks, runs its one helper, and cannot run cp, sed, xargs, or curl. Enforcement happens in the kernel's path walk, so it does not depend on the process's own logic staying honest.
The cost is an inventory, and the failure mode is silent. TemporaryFileSystem=/:ro mounts an empty tmpfs over /, so a static Go binary in /tmp disappears and fails to spawn with the same 203/EXEC; binding its directory back read-only made it serve immediately. Missing path and denied path produce identical exit codes and identical journal lines.
The same class of interaction bites again when you compose PrivateUsers=yes with a path that hides /proc. Each directive alone is fine, plus ProcSubset=pid is fine, plus ProtectProc=invisible is fine. Add InaccessiblePaths=/proc and the unit dies before main:
probe-hard.service: Failed to set up user namespacing: No such file or directory
probe-hard.service: Failed at step USER spawning /bin/sleep: No such file or directory
probe-hard.service: Main process exited, code=exited, status=217/USER
217/USER, no mention of /proc, no mention of the uid map. The user namespace is set up by writing /proc/self/uid_map, and you just made /proc unreachable.
The invoice: 44 ns per syscall, 3.2x on malloc, two dead runtimes
Seccomp cost, measured with 500,000 syscall(SYS_getpid) round-trips in a tight loop, three samples per arm, medians:
| Arm | ns per syscall | vs bare |
|---|---|---|
| bare process | 1,201 | — |
| transient unit, no filter | 1,198 | 0% |
| nine-group denylist | 1,242 | +43.8 ns, 3.7% |
@system-service allowlist (61 names) | 1,241 | +43.4 ns, 3.6% |
The 1.2 microsecond baseline deserves reading before the delta. On a 2.5 GHz Skylake with page-table isolation and IBRS, kernel entry costs roughly twenty times what it costs on a machine without them; the marginal 44 ns lands on a ~60 ns baseline on modern silicon and reads as 70%. systemd compiles both filter forms into a binary search over the syscall number, which is why a 61-rule allowlist and an 85-rule denylist price identically.
The allocator is the largest line item, and the only one that scales with request volume. hardened_malloc at commit bf37d54, built -O3 with SLAB_CANARY and ZERO_ON_FREE, against glibc 2.41:
| Workload | glibc | hardened_malloc | Ratio |
|---|---|---|---|
| 64 B alloc/free pair | 23.1 ns | 74.1 ns | 3.2x |
| mixed 16–4096 B pair | 85.4 ns | 245.3 ns | 2.9x |
| RSS per live 64 B block | 106 B | 240 B | 2.3x |
Two measurement traps are worth stealing. The first benchmark reported 0.7 ns per allocation because GCC deleted the malloc/free pair; the numbers above come from a variant where the pointer escapes into a global ring buffer and -fno-builtin-malloc blocks the transform. The one-byte overflow does die — glibc prints finished and exits 0, hardened_malloc prints fatal allocator error: canary corrupted and dies on SIGABRT — but the mitigation evaporates for static Go: nm -D on the 8.2 MB server shows no malloc, free, calloc, or realloc import, so there is no ld.so to preload.
MemoryDenyWriteExecute=yes splits runtimes the same way, and the split is not about age:
| Runtime | Under MDWE |
|---|---|
| Go 1.24.4 (1 MiB touched) | runs |
| Python 3.13.5 | runs |
| bash 5.2, busybox | run |
| Node.js 26.8.1 | Check failed: 12 == (*__errno_location ()) in OS::SetPermissions |
| OpenJDK 21.0.12.1 | Failed to mark memory page as executable |
Both failures are JITs asking for W+X pages after the fact, so the directive is a runtime policy, not a hardening level: it works precisely on the services that never needed it.
Where MDWE does apply, it is a speed bump. The documented circumvention is to stop asking for W+X and ask for executable content instead: put the code in a memfd, map it PROT_READ|PROT_EXEC, call the pointer. Fifteen lines, and it worked on this host under MemoryDenyWriteExecute=yes:
int fd = syscall(SYS_memfd_create, "payload", 0);
write(fd, payload, sizeof payload); /* mov eax, 42 ; ret */
void *p = mmap(NULL, sizeof payload, PROT_READ | PROT_EXEC, MAP_PRIVATE, fd, 0);
printf("executed_from_memfd=%d
", ((int (*)(void))p)());
Measured across three arms: bare executed_from_memfd=42; under MDWE alone, executed_from_memfd=42; MDWE plus SystemCallFilter=~memfd_create, memfd_create: Operation not permitted, exit 2. The directive that costs nothing did nothing. The one-line syscall ban closed the hole, which is the pattern that runs through this whole exercise — a syscall filter works when it names a mechanism an attacker needs, and fails when it names a verb the runtime can route around. The same reasoning applies to io_uring: Docker and containerd ship it blocked by default in their seccomp profiles, and kernel.io_uring_disabled=2 shuts the subsystem off system-wide on 6.6 and later, far cheaper than an 85-entry per-unit list. For the write-side of the same problem, InaccessiblePaths=/dev/shm removes the other executable-content stash systemd's own docs name.
Scored end to end instead of argued: a bare transient unit scores 9.6 UNSAFE with 75 ✗ rows. Thirty-four directives — namespace set, tmpfs root, six InaccessiblePaths, the five SystemCallFilter lines, capability wipe, SystemCallArchitectures=native, UMask=0077 — score 2.1 OK with 13 ✗ left; adding PrivateUsers=yes takes it to 1.9 OK and 12. Unit start moves from 61.9 ms to 141.1 ms median across 15 runs, while the kernel work for the mount topology measures 311 microseconds on top of a 787 microsecond fork/exec pair — the other 79 ms is systemd applying properties, not namespaces.
Seven point seven points of exposure reduction for thirty-four directives. Of the two lines that started this, ~fork vfork contributed zero because glibc never issues that syscall, and ~execve contributed one dead unit with exit code 203. Meanwhile the two single-line bans that did real work — memfd_create and the io_uring trio — appear in neither template, cost 44 ns per syscall between them, and are already the default in containerd's shipped seccomp profile.