fix(broker): refuse a socket directory whose macOS access list lets others change it

Merged
KI
22d ago
+223-4

Problem

On macOS, fsgate-broker --socket accepted a directory that another user could change, as long as its mode bits looked private:

mkdir -m 700 ~/run
chmod +a "everyone allow add_file,delete_child" ~/run
fsgate-broker --unconfined --grant /srv/data:r --socket ~/run/broker.sock -- ./worker   # started

Any user can then delete ~/run/broker.sock and put their own socket there, so the next client that connects by that path talks to them. RFC 0007's check exists to stop exactly that.

Found in an internal review at ea159a6. The maintainer chose to fix it as a public PR.

Root cause

check_socket_path refuses a directory that another user owns, or that others can write without the sticky bit, by reading st_mode. macOS keeps an extended access list beside the mode bits, and an allow entry there grants rights the mode does not show. Linux has no gap: a POSIX access list's mask is the group bits (acl(5)), so a list that lets anyone else write makes the directory group-writable, which the check already refuses.

Change

  • On macOS, check_socket_path also reads each directory's access list, without following symlinks, and refuses one with an allow entry, for anyone, that gives add_file, add_subdirectory, delete_child, delete, writesecurity, or chown: the rights that let their holder add or delete entries, delete or rename the directory, or change its list, mode, or owner. Entries that only deny, as every macOS home directory has, are fine. The message says chmod -N removes the list. The broker exits 1 before binding, as for the other refusals.
  • Reading the list needs acl_get_link_np and friends, which std, rustix, and libc do not wrap. They are declared in a new module, fsgate-broker/acl.rs, with #![allow(unsafe_code)] and a written safety contract: the list is owned by a guard that frees it once, and entries are used only while it lives. It is compiled on macOS only.
  • RFC 0007 gets a "Changes after release" entry, the threat model row cites the new test, the review brief lists the third place with unsafe, and the changelog has a Fixed entry.

Safety and compatibility

A macOS socket directory with such an entry now fails to start the broker. That is the fix. A directory whose list allows these rights to the broker's own user is refused too, since an entry names a user or group and the check does not resolve membership; chmod -N or a deny-only list works. Nothing changes on Linux, or for the default inherited connection, which has no socket path.

New unsafe is confined to one module, as AGENTS.md asks. The crate still denies unsafe_code everywhere else.

Verification

Before the fix, on this branch with the check removed, the new test failed on its first case: the broker started with everyone allow add_file on the socket directory (exit Some(0), expected 1).

After it, on macOS with Rust 1.99.1, merged with main at 2f8ba36:

  • cargo test --locked: 133 passed, 0 failed, including broker.rs::a_socket_path_whose_access_list_lets_others_change_it_is_refused. It runs the real broker against directories with add_file, delete_child, chown, and writesecurity entries, and checks exit 1, the message, and that no socket was bound and the command did not run. A directory with only everyone deny delete and everyone allow list,search starts the broker.
  • cargo fmt --all --check passed. cargo clippy --locked --all-targets -- -D warnings is clean on macOS and for x86_64-unknown-linux-gnu. cargo +1.85.0 check --locked --all-targets passed.

Not verified: the Linux reasoning is from acl(5), not a Linux test with a named-user entry, because this machine has no Linux and setting one up needs setfacl in CI. add_subdirectory and delete are refused by the same mask test as the four cases above, not each by its own case. Access lists on filesystems other than APFS were not tried.

Documentation and release

RFC 0007, the threat model, docs/security-review.md, and the changelog. No version change. The M9 roadmap entry records the CI run on 445538b as evidence: all 25 checks passed, and the macos job ran the new test.