Skip to content

build: Harden the systemd user services - #267

Open
kpanuragh wants to merge 1 commit into
linux-credentials:mainfrom
kpanuragh:systemd-hardening
Open

kpanuragh wants to merge 1 commit into
linux-credentials:mainfrom
kpanuragh:systemd-hardening

Conversation

@kpanuragh

Copy link
Copy Markdown
Contributor

Closes #21.

Adds sandboxing to both systemd user units. systemd-analyze security: daemon 9.2 → 6.0, UI 9.2 → 5.8.

What's enabled (both units)

  • NoNewPrivileges, LockPersonality, RestrictRealtime, RestrictSUIDSGID, RestrictNamespaces, SystemCallArchitectures=native, UMask=0077.
  • SystemCallFilter=@system-service plus memfd_secret, with SystemCallErrorNumber=EPERM. memfd_secret is needed because the hybrid QR code secret (daemon) and PINs (UI) are passed over D-Bus in memfd_secret fds.
  • Daemon only:
    • MemoryDenyWriteExecute.
    • RestrictAddressFamilies=AF_UNIX AF_NETLINK AF_INET AF_INET6: D-Bus/BlueZ/pcscd, udev, and the hybrid tunnel.
  • UI only:
    • RestrictAddressFamilies=AF_UNIX AF_NETLINK.
    • No MemoryDenyWriteExecute, since GTK's GL renderer may run on a JIT-compiling driver such as llvmpipe.

What's deliberately not enabled

Anything that gives the service a private mount namespace: ProtectSystem, ProtectHome, PrivateTmp, PrivateDevices, ProtectKernel*, ProtectProc, … There are three reasons:

  • Trust check: the daemon compares its own mount namespace with the caller's when deciding whether to trust it (gateway/mod.rs), so it would reject xdg-desktop-portal.
  • Portal caller detection: xdg-desktop-portal identifies the UI, as a caller of other portals, through /proc/<pid>/root.
  • User namespaces: in the user service manager these options need user namespaces.

PrivateDevices would also hide /dev/hidraw* from the daemon. This is explained in a comment in each unit.

If we want filesystem sandboxing later, the trust check would need another way to compare callers.

Testing

I installed the generated units as user services (pointing at a debug build, plus a drop-in setting CREDSD_TRUSTED_CALLERS so a test client could stand in for the portal) and ran real create requests completed with a phone over hybrid.

  1. First run, enforced @system-service only: the daemon got EPERM writing the QR secret (memfd_secret) and the hybrid task panicked, so no QR code was shown. That's how memfd_secret was found. Separately, the panic on that error path (hybrid.rs:213) might be worth turning into a proper error.
  2. Log-only run (SystemCallFilter= cleared, SystemCallLog=~@system-service), completed with a phone: across both processes, the kernel audit log recorded exactly one syscall outside the set: memfd_secret (447) from the daemon.
  3. Final units, fully enforced: NoNewPrivs: 1, Seccomp: 2 on both processes. The phone flow completed and CreateCredential returned a registration response. Calls seen: CreateSession → NotifyHybridStarted → NotifyHybridConnecting → NotifyHybridConnected → NotifyCeremonyCompleted. No seccomp denials, and the trust check still passed (same mount namespace).

Not exercised: USB security keys (no key here) and the PIN flow. memfd_secret is allowed in the UI for the PIN path based on the code (client.rs → write_secret). If someone can run a USB/PIN flow with these units, that would close the gap.

Add sandboxing options to both user units. Only options enforced with
seccomp and no_new_privs are used: credentialsd decides whether a caller
is trusted partly by comparing mount namespaces, so options that give the
service a private mount namespace would make it reject
xdg-desktop-portal, and they would also need user namespaces in the user
service manager.

Both units filter system calls to @System-service plus memfd_secret,
which carries the hybrid QR code secret and PINs over D-Bus. The daemon
may use AF_UNIX, AF_NETLINK and AF_INET/AF_INET6 (for the hybrid tunnel);
the UI only AF_UNIX and AF_NETLINK. The UI keeps writable executable
memory for JIT-compiling GL drivers.

systemd-analyze security: daemon 9.2 -> 6.0, UI 9.2 -> 5.8.

Closes linux-credentials#21
@kpanuragh

kpanuragh commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Tested the USB + PIN path as well, using a virtual FIDO2 key (bulwarkid/virtual-fido attached via USB/IP, so it shows up as a real /dev/hidraw* with the uaccess ACL), PIN enabled.

Under the hardened units in log-only mode (SystemCallLog=~@system-service):

  • Device access: the daemon enumerated and opened the hidraw device, got GetInfo/GetRetries, and the UI showed the PIN prompt.
  • PIN entry: each PIN entry made the UI call memfd_secret (4 entries, 4 log entries for credentialsd-ui syscall 447). That confirms the UI needs it.
  • Other syscalls: none outside the set, from either process.

Update: the PIN step now completes under the enforced hardened units. Entering the PIN created the credential (code=0), with no seccomp or sandbox denials.

The earlier failure was in virtual-fido, not libwebauthn or the hardening:

With both fixes, the USB + PIN path works with the hardened units as in this PR. A real key would still be a good final check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add systemd hardening

1 participant