fix(gate): refuse a symlink out of the grant with EXDEV on every platform
Problem
Wherever cap-std's component walk refused a symlink that leads out of its grant, which is always on macOS, the audit event recorded allow with errno null. That is the event a success produces, so an escape attempt looked like a successful operation in the audit log. RFC 0002 records an errno for every failure after an allow. A broker's worker also received the refusal with no errno.
The model-based test of the gate in #60 found it: a symlink named b that points to .., at the root of a grant, then an open of b.
Root cause
The walk reports an escape as io::Error::new(PermissionDenied, "a path led outside of the filesystem"), which carries no OS errno. It is the only error without one that the gated operations return. On Linux, openat2 with RESOLVE_BENEATH reports the same refusal as EXDEV. cap-std also uses the walk on Linux when openat2 is unavailable or keeps failing with EAGAIN, as the threat model notes.
Change
Gate::gated gives that error EXDEV before it is audited or returned, so the caller, the audit event, and a broker's worker see EXDEV on every platform.
Safety and compatibility
The request was always refused. Only how the refusal is reported changes. On macOS, GateError::Io's source for an escape is now EXDEV (ErrorKind::CrossesDevices), where it was PermissionDenied with no errno. Code that matched ErrorKind::PermissionDenied for this case on macOS no longer matches. Linux already returned EXDEV.
Verification
On macOS 26.2 (Darwin 25.2) with Rust 1.99.1:
cargo test --locked -p fsgate --no-fail-fast --test gate --test audit: all pass. Withlib.rsfrommain,an_escape_is_audited_with_its_errno,symlink_to_an_outside_directory_cannot_escape, andabsolute_symlink_target_cannot_escapefail. On Linux the twogate.rstests pass either way, becauseopenat2already returnsEXDEV. They hold the platforms to one answer.cargo fmt --all --checkandcargo clippy --all-targets -- -D warnings: clean.cargo clippy --locked --target x86_64-unknown-linux-gnu -p fsgate --all-targets -- -D warnings, also with--features experimental-intercept: clean. This is a type-check, not a run.cargo test --locked: 97 passed, 0 failed.
Not verified:
- The Linux runs. CI on this PR is their first.
- The walk's fallback on Linux, which needs
openat2to keep failing. The mapping does not depend on the platform.
Documentation and release
A changelog entry under Unreleased, and the threat model's row for a symlink out of a grant names the errno and the audit test. No release.