From 7f557b6cb6031f89fce03918b04850c3b92d5a65 Mon Sep 17 00:00:00 2001 From: K Panuragh Date: Sat, 14 Nov 2026 00:27:26 +0530 Subject: [PATCH] build: Harden the systemd user services 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 #21 --- CHANGELOG.md | 1 + ...iinuwa.credentialsd.Credentials.service.in | 24 +++++++++++++++++++ ...z.iinuwa.credentialsd.UiControl.service.in | 21 ++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06c48f6e..0dcd64bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - daemon: Stop retrying a transport after 5 consecutive failures before user interaction; other transports keep running. - daemon: Show the UI through the backend that xdg-desktop-portal selects, passed in the new `ui_backend` option - daemon: Treat Debian's Firefox ESR (app ID `firefox-esr`) as a privileged client, like the other Firefox builds +- build: Harden the systemd user services with seccomp-based sandboxing (system call filter, address family and namespace restrictions, no new privileges) (#21) - daemon: Build the list of devices offered to the user from libwebauthn's `available_transports()`, the same source discovery uses (#32) - daemon: Allow clients to cancel requests through xdg-desktop-portal. - ui: Pass the caller's activation token to the compositor when showing the dialog, so it can take focus when the requesting window is in the background (#152) diff --git a/systemd/xyz.iinuwa.credentialsd.Credentials.service.in b/systemd/xyz.iinuwa.credentialsd.Credentials.service.in index 3c17b221..acaa638d 100644 --- a/systemd/xyz.iinuwa.credentialsd.Credentials.service.in +++ b/systemd/xyz.iinuwa.credentialsd.Credentials.service.in @@ -5,3 +5,27 @@ Description=Service for creating and storing user credentials Type=dbus BusName=xyz.iinuwa.credentialsd.Credentials ExecStart=@DAEMON_EXECUTABLE@ + +# Hardening +# +# credentialsd decides whether a caller is trusted partly by comparing its own +# mount namespace with the caller's. Options that give the service a private +# mount namespace (ProtectSystem=, ProtectHome=, PrivateTmp=, PrivateDevices=, +# ProtectKernelTunables=, ...) would make it reject xdg-desktop-portal, so only +# options enforced through seccomp and no_new_privs are used. They also work in +# the user service manager without user namespaces. +NoNewPrivileges=yes +LockPersonality=yes +MemoryDenyWriteExecute=yes +RestrictRealtime=yes +RestrictSUIDSGID=yes +RestrictNamespaces=yes +SystemCallArchitectures=native +SystemCallFilter=@system-service +# memfd_secret: the hybrid QR code secret are passed over D-Bus in memfd_secret file descriptors. +SystemCallFilter=memfd_secret +SystemCallErrorNumber=EPERM +# AF_UNIX: D-Bus (including BlueZ) and pcscd. AF_NETLINK: udev device +# monitoring. AF_INET/AF_INET6: the hybrid tunnel to the phone's relay server. +RestrictAddressFamilies=AF_UNIX AF_NETLINK AF_INET AF_INET6 +UMask=0077 diff --git a/systemd/xyz.iinuwa.credentialsd.UiControl.service.in b/systemd/xyz.iinuwa.credentialsd.UiControl.service.in index 813d61aa..1f5f07a4 100644 --- a/systemd/xyz.iinuwa.credentialsd.UiControl.service.in +++ b/systemd/xyz.iinuwa.credentialsd.UiControl.service.in @@ -5,3 +5,24 @@ Description=Internal helper service for credentialsd Type=dbus BusName=xyz.iinuwa.credentialsd.UiControl ExecStart=@UI_EXECUTABLE@ + +# Hardening +# +# Like the daemon, no options that need a private mount namespace: the UI calls +# other portals (e.g. Settings for the colour scheme), and xdg-desktop-portal +# identifies its callers through /proc//root. MemoryDenyWriteExecute= is left out because GTK's GL +# renderer may run on a JIT-compiling driver such as llvmpipe. +NoNewPrivileges=yes +LockPersonality=yes +RestrictRealtime=yes +RestrictSUIDSGID=yes +RestrictNamespaces=yes +SystemCallArchitectures=native +SystemCallFilter=@system-service +# memfd_secret: PINs are passed over D-Bus in memfd_secret file descriptors. +SystemCallFilter=memfd_secret +SystemCallErrorNumber=EPERM +# AF_UNIX: D-Bus and the Wayland/X11 display. AF_NETLINK: GLib's network +# monitor. +RestrictAddressFamilies=AF_UNIX AF_NETLINK +UMask=0077