fix(broker): refuse every unix socket pair but stream and seqpacket
Problem
Below Linux 7.1, a confined worker can still send datagrams, and descriptors with them, to any Unix datagram socket it can name: by path, or by abstract name before Linux 6.12. RFC 0009 and the threat model (section 3, "reaching a Unix socket outside its confinement ... with a connect or a datagram") say it cannot. This is in 0.4.0.
int sv[2];
socketpair(AF_UNIX, SOCK_RAW, 0, sv); /* allowed by the filter */
sendto(sv[0], "x", 1, 0, (struct sockaddr *)&journald, len); /* delivered */
Stream services, D-Bus among them, are not reachable this way: a datagram socket can only send to another datagram socket.
Root cause
The worker's seccomp filter refuses socketpair(AF_UNIX, ...) only when the type is SOCK_DGRAM. The kernel makes a Unix SOCK_RAW socket a datagram one (unix_create in net/unix/af_unix.c: case SOCK_RAW: sock->type = SOCK_DGRAM; fallthrough;, present in 6.6 and 7.0). socketpair builds both ends through unix_create, and unix_dgram_sendmsg sends to whatever address the caller names, even from half of a pair.
Change
- Filter: a Unix pair is allowed only for
SOCK_STREAMandSOCK_SEQPACKET, the two types that stay connected to each other; every other type is refused withEACCES, including any a later kernel adds. One instruction longer. - Tests (first commit, on the old filter):
a_confined_worker_cannot_reach_a_unix_socketsends a datagram from half of a raw pair and counts what arrives outside the grants.unix_create_scenarioexpects the raw pair to be refused, and in the unconfined control checks that the kernel really gives aSOCK_DGRAMsocket.- New unit tests in
confine.rsrun the filter's instructions on each call it answers, on any kernel.
- Docs: RFC 0009's table, rationale, test list, and a "Changes after release" entry; a changelog entry under Unreleased.
Safety and compatibility
A program that makes a Unix pair of a type other than stream or seqpacket now gets EACCES in a confined worker below Linux 7.1. Only datagram and raw pairs work on Linux at all, and datagram pairs were already refused. From 7.1 the filter is not installed and nothing changes.
Verification
- The tests went up first, without the fix (run on
d559670), and failed for this bug:- On Linux 6.12 and in every
distroscontainer (runner kernel 7.0, filter installed),unix_reach_scenariofailed on "a datagram from half of a raw pair": the confined worker's send succeeded.unix_create_scenariofailed on "a raw pair":Ok(())whereEACCESwas expected. - The new unit test failed on every job with
pair 3:SECCOMP_RET_ALLOW(2147418112) whereEACCES(327693) was expected. Incheck,msrv,arm64, andkernelson 6.6 and 7.3, that failure stoppedcargo testbefore the end-to-end tests. - The fix is the second commit,
26399fb.
- On Linux 6.12 and in every
- Locally on macOS (no Linux here): the filter module's source, built with Linux x86_64 constants, fails the new unit test on
main's filter (pair 3:SECCOMP_RET_ALLOWwhereEACCESwas expected) and passes on the fixed one. cargo +1.100.0 clippy --locked --all-targets -- -D warningsis clean forx86_64-unknown-linux-gnu,aarch64-unknown-linux-gnu, and macOS;cargo +1.85.0 checkis clean for both Linux targets;cargo fmt --all --checkpasses;cargo test --lockedon macOS: 121 passed, 0 failed.
Not verified locally: any Linux run. That is this PR's CI: check (runner kernel 7.0, filter installed), kernels (6.6 and 6.12 with the filter, 7.3 without), arm64, and msrv.
Documentation and release
Changelog entry under Unreleased. 0.4.0 has the hole, so this wants a 0.4.1, and a GitHub advisory once it ships.