SO_PEERPIDFD Gets More Useful
A while ago I wrote about the limited usefulness of SO_PEERPIDFD. for authenticating sandboxed applications. The core problem was simple: while pidfds gave us a race-free way to identify a process, we still had no standardized way to figure out what that process actually was - which sandbox it ran in, what application it represented, or what permissions it should have.
The situation has improved considerably since then.
cgroup xattrs
Cgroups now support user extended attributes. This feature allows arbitrary metadata to be attached to cgroup inodes using standard xattr calls.
We can change flatpak (or snap, or any other container engine) to create a cgroup for application instances it launches, and attach metadata to it using xattrs. This metadata can include the sandboxing engine, application ID, instance ID, and any other information the compositor or D-Bus service might need.
Every process belongs to a cgroup, and you can query which cgroup a process belongs to through its pidfd - completely race-free.
Standardized Authentication
Remember the complexity from the original post? Services had to implement different lookup mechanisms for different sandbox technologies:
- For flatpak: look in
/proc/$PID/root/.flatpak-info
- For snap: shell out to
snap routine portal-info
- For firejail: no solution
- …
All of this goes away. Now there’s a single path:
- Accept a connection on a socket
- Use
SO_PEERPIDFD
to get a pidfd for the client - Query the client’s cgroup using the pidfd
- Read the cgroup’s user xattrs to get the sandbox metadata
This works the same way regardless of which sandbox engine launched the application.
A Kernel Feature, Not a systemd One
It’s worth emphasizing: cgroups are a Linux kernel feature. They have no dependency on systemd or any other userspace component. Any process can manage cgroups and attach xattrs to them. The process only needs appropriate permissions and is restricted to a subtree determined by the cgroup namespace it is in. This makes the approach universally applicable across different init systems and distributions.
To support non-Linux systems, we might even be able to abstract away the cgroup details, by providing a varlink service to register and query running applications. On Linux, this service would use cgroups and xattrs internally.
Replacing Socket-Per-App
The old approach - creating dedicated wayland, D-Bus, etc. sockets for each app instance and attaching metadata to the service which gets mapped to connections on that socket - can now be retired. The pidfd + cgroup xattr approach is simpler: one standardized lookup path instead of mounting special sockets. It works everywhere: any service can authenticate any client without special socket setup. And it’s more flexible: metadata can be updated after process creation if needed.
For compositor and D-Bus service developers, this means you can finally implement proper sandboxed client authentication without needing to understand the internals of every container engine. For sandbox developers, it means you have a standardized way to communicate application identity without implementing custom socket mounting schemes.
-
SO_PEERPIDFD Gets More Useful
-
XDG Intents Updates
-
Integrating libdex with GDBus
-
Testing with Portals
-
Display Next Hackfest 2025
-
GNOME 49 Backlight Changes
-
Blender HDR and the reference white issue
-
Booting into Toolbox Containers
-
On the Usefulness of SO_PEERPIDFD
-
Fedora Silverblue Development Utils
-
Developing Gnome Shell on Fedora Silverblue
-
Setting up a personal server in 2023
Do you have a comment?
Toot at me on mastodon or send me a mail!