feat(broker): keep a confined worker off unix sockets below linux 7.1
Implements RFC 0009. Stacked on #75, which changes the same sys module in confine.rs, so this targets that branch until #75 merges.
Problem
Landlock refuses connects to pathname Unix sockets only from Linux 7.1 (ABI 9), and to abstract ones from 6.12. Before that, a worker fsgate-broker confines can connect to any Unix socket it can name. On a desktop that includes the session bus, where one StartTransientUnit call asks systemd's user manager to start a program outside the confinement, with the user's full access. Nearly every system runs a kernel before 7.1.
Change
-
After the confining process applies its Landlock rules, it reads the effective ABI that
restrict_selfreports. Below ABI 9 it installs a seccomp filter before it becomes the worker. Landlock has already setno_new_privs, so no privilege is needed. Every program the worker starts inherits the filter acrossexec, and nothing can remove it. -
The filter answers:
Call Answer socketwith domainAF_UNIXEACCESsocketpairwith domainAF_UNIXand typeSOCK_DGRAMEACCESio_uring_setup,io_uring_enter,io_uring_registerENOSYSan x32 call, or a call from another architecture kills the process anything else allowed -
It is 18 hand-written BPF instructions for x86_64 (the 64-bit ABI) and little-endian aarch64, built in a
constwith compile-time checks that each shared step is where the jumps lead. Installing it is the only newunsafe, in the existingsysmodule, with its safety contract extended. Below 7.1, a confined worker on any other target does not start, and the error names--unconfined. No new dependency. -
One change from the RFC as accepted: a datagram
socketpairis refused too. The RFC allowed every Unix pair because its ends reach only each other. That holds for stream and seqpacket pairs, but either end of a datagram pair cansendtoany datagram socket by address, andconnectto another. The unconfined control below shows such a datagram arriving. RFC 0009 records this under "Changes during implementation".
Safety and compatibility
- A confined worker before Linux 7.1 can no longer use a Unix socket service: D-Bus, X11, Wayland, PulseAudio,
nscd,systemd-userdb, andsyslog(3). glibc falls back to files for lookups. A worker that needs one runs with--unconfined, the same choice it faces on 7.1. Changelog: Changed. - It keeps its broker connection, sockets on its standard streams, stream and seqpacket pairs, and the network.
- An invalid call number at or above
0x40000000, such assyscall(-1), kills the process instead of returningENOSYS, because the filter cannot tell it from an x32 call. - From Linux 7.1, nothing changes.
--unconfined, the library, and--experimental-interceptare unaffected.
Verification
The tests went up alone first. CI on 01a0a7c failed on Linux 6.6.162 and on the runners' own kernel (check and msrv): the confined worker connected to the test's socket by path, and created Unix sockets. On 7.3.3, Landlock already refused everything, and both tests passed.
CI on 1f0968f, with the filter, passed all 7 checks. The two new tests in tests/broker_confined.rs passed on 6.6.162 and 7.3.3 (the kernels job, release build of the packaged crate), on the runner's kernel in all three runs of check, and on Rust 1.85 in msrv:
| Test | Shows |
|---|---|
kernel::a_confined_worker_cannot_reach_a_unix_socket | On every kernel, the worker and a program it starts reach none of the test's three sockets: a stream socket by path, one by abstract name, and a datagram socket by path, from a socket of their own and from half of a pair. Each attempt fails with PermissionDenied, and the sockets receive nothing. The unconfined control reaches all three: 2 connections each and 4 datagrams. |
kernel::below_linux_7_1_a_confined_worker_cannot_create_a_unix_socket | Below 7.1, Unix stream, datagram, and seqpacket sockets and a datagram pair fail with EACCES, with SOCK_CLOEXEC and SOCK_NONBLOCK in the type. Stream and seqpacket pairs, a TCP socket, and the broker connection work. The three io_uring calls fail with ENOSYS, and a program making an x32 call dies by SIGSYS. The same in a program the worker starts. On 7.3 and in the unconfined control, all of these work, and io_uring fails with errors other than ENOSYS. |
The test asks the landlock crate whether the kernel handles RESOLVE_UNIX to decide which outcome to expect. The io_uring and x32 calls are in a test-only unsafe module with its own safety contract (RFC 0009, decision 2). Each io_uring call gets arguments the kernel refuses before touching memory.
Locally, on macOS with each worktree's own target directory:
cargo fmt --all --check: cleancargo clippy --all-targets -- -D warnings: clean, and with--target x86_64-unknown-linux-gnu, with-p fsgate --features experimental-intercept --target x86_64-unknown-linux-gnu, and with-p fsgate --all-targets --target aarch64-unknown-linux-gnucargo test --locked: all passed. The new tests are Linux only.
Not verified:
- aarch64 at runtime: it was built and linted only.
- A call from another architecture (
int 0x80on x86_64), and a kernel that refuses the filter. - A program that really uses D-Bus or
nscdunder the filter. - Not independently reviewed.
Documentation and release
- RFC 0009: status, the datagram pair in the design and tests, and "Changes during implementation".
- RFC 0008: its limits point at RFC 0009.
- Threat model, section 3: three new rows (Unix sockets,
io_uring, x32 and other architectures), and the "beyond files" gap narrowed. - README: the filter, and the architectures that need it before 7.1.
- CHANGELOG: under Changed.
- ROADMAP: "Implement RFC 0009" ticked with the CI evidence.