test(lock): compare raw calls in a locked child with the gate on generated trees
Problem
lock() promises that filesystem access outside the grants fails at the kernel, even for code that never touches the gate. The threat model lists where the kernel's answer differs from the gate's: stat, a narrow or revoke after the lock, and a nested grant with fewer rights. Each claim has a test for the case someone wrote down. Nothing checks them against generated trees, or checks that those are the only differences.
This is the second item in M10 of the roadmap.
Change
On Linux, tests/gate_model.rs gets a kernel module. Each case from the model test's generator is replayed in a child process. The child makes the case's grants, calls lock(), and then answers requests one at a time over its stdin and stdout. For each open, create, metadata, and read_dir, it makes the raw std::fs call the gate's operation would make without the gate. The parent checks every answer three ways:
- What a success reached. The object must be one the rules installed at
lock()give the right the call needs. It looks the object up by device and inode in the grants' trees. A raw open of a directory needsLIST. A create of a new file needsCREATEandWRITE. - The tree. A failure leaves every entry unchanged, the secret outside the grants included. A create changes only the file holding its marker.
- The gate's answer. The model predicts it from the tree before the call, and the model test checks the model against the gate. Every place the two answer differently must be one of five gaps, and each gap is a row in section 2 of the threat model:
Metadata: Landlock does not restrictstat.ChangedAfterLock: a narrow or revoke after the lock binds only the gate.NestedGrant: an enclosing grant's rights apply beneath a nested grant with fewer.Route(new row): the kernel checks the object a path resolves to, so it allows a path through a symlink from one grant into another, or into a grant from outside one, or through a.or... The gate removes.and..lexically, as RFC 0001 says, and refuses the symlinks. No route reaches an object the rules don't give the right.CreateWithoutWrite(new row): beneath rules that giveCREATEbut notWRITE, the kernel makes the file, then refuses to open it for writing, and the empty file stays. The gate'screateneeds both rights.
The parent also runs each request through an unlocked gate after the raw call, so the model test's checks also run on the trees the raw calls leave.
Like the model test, the run fails if it never meets each gap, each operation agreeing both ways, and an EACCES on a raw open, create, and read_dir. known_gaps_are_classified pins one fixed case per gap, plus a grant with no rights, which must still lock.
What it found
Two things, before its first Linux run:
lock()failed for a gate holding a grant with no rights. #61 fixed it and is merged. This test generates such grants, so it depends on that fix.- A
.the gate removes lexically:gate.create("<grant>/file/.")createsfile, while the kernel refusesfile/.withENOTDIR. It follows RFC 0001, it reaches nothing outside the grant, and it's documented in theRouterow. Rust'sPath::componentsalso drops a.that isn't first, so the test reads the path as written.
Verification
On macOS 26.2 (Darwin 25.2) with Rust 1.99.1, on this branch merged with main at 9c5aeb8:
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, andcargo +1.85.0 check --locked --target x86_64-unknown-linux-gnu -p fsgate --tests: clean. These are type-checks, not runs.cargo test --locked, built withCARGO_PROFILE_DEV_DEBUG=0to save disk: 106 passed. Thekernelmodule is Linux-only, so it didn't run here.- A harness smoke run, not a test of Landlock: in a temporary copy with the lock and the two checks that need it turned off, 3,000 generated cases passed the protocol, the tree checks, and the classification. That copy found the
.difference above. With no lock, the five gap cases that don't depend on enforcement were classified as designed, andCreateWithoutWritefailed the soundness check, as it must without Landlock.
CI, run 42988394240 on 225f99f, all 8 checks passed. Both kernel tests passed on Linux:
- The
ubuntu-26.04runner's kernel: all three runs of thecheckjob (the checkout,experimental-intercept, and the packaged crate) and both runs of themsrvjob on Rust 1.85.gate_model.rs's five tests took 3.2 to 4.2 s per run. - Linux 6.6 and 7.3 in the
kernelsjob, release build: 7.06 s and 4.79 s. known_gaps_are_classifiedrequires exactly one gap per fixed case, soCreateWithoutWritebehaves as described on all three kernels: the kernel makes the file, then refuses the write withEACCES.
After merging main with #77 (Linux 6.1 and 6.12 and the arm64 job), #79, #80, #81, and #82, run 43170450700 on 3441cbc: all 11 checks passed. Both kernel tests passed on the runner's kernel in all three runs of check and both runs of msrv, on arm64, and on Linux 6.6.162, 6.12.117, and 7.3.3 in the kernels job. Linux 6.1 runs only its below_landlock_v3 tests. The merge resolved conflicts in this test (#79's Coverage::missing beside this PR's #[derive(Clone)]), the threat model (this PR's rows beside #77's updated BestEffort row), and the roadmap. The test's diff against main is unchanged by the merge. The missed-mutant lists from #80 still hold: none of their entries is one this test can catch.
Not verified:
- Coverage counts per gap on Linux. libtest captures the test's printed counts when it passes. The run only proves each gap was met at least once.
- Anything the generator doesn't make: hard links, mounts, and concurrent renames.
Documentation and release
Two new rows in section 2 of the threat model, a Stops row for raw calls on generated trees, and the new tests named in the existing rows for stat, a change after the lock, and nested grants. The roadmap item is ticked, with the CI evidence above. Test-only, so no changelog entry and no release.