fix(lock): lock a gate that holds a grant with no rights
Problem
On Linux, lock() fails for any gate that holds a grant with no rights. That includes a grant made with Rights::from_bits_truncate(0) and one narrowed to nothing before the lock, which narrow allows. The lock fails in strict and best-effort mode alike, while the same gate locks on macOS.
strict lock: LockFailed { source: AddRules(Fs(Compat(Access(Empty)))) }
It fails closed, because the process stays unlocked and the caller gets an error, but the error doesn't say what to change.
Root cause
containment::apply adds one Landlock rule per grant, with the access that grant's rights map to. No rights map to no access, and the landlock crate (0.4.7, access.rs) rejects an empty access set with AccessError::Empty, whatever the compatibility level.
Change
A grant whose rights map to no access adds no rule. Having no rule is what Landlock uses to deny everything beneath a directory, so the kernel and the gate now agree: the kernel refuses a raw open beneath the grant, and the gate refuses it with RightsExceeded.
Safety and compatibility
This only changes a case that used to fail, and it grants nothing. Grants with any rights produce the same rules as before.
Verification
Regression test lock.rs::kernel::a_grant_with_no_rights_locks_and_reaches_nothing. A locked child holds a READ grant, a grant made with no rights, and a grant narrowed to none. It must lock strictly, a raw read of the secret beneath the empty grants must be refused, the gate must refuse that path with RightsExceeded, and a read through the READ grant must still work.
- Before the fix, at 187dd64 (run), the test failed in
checkandmsrvwith the error above. - With the fix, CI on this PR is the run to check.
On macOS with Rust 1.99.1:
cargo test --locked: 96 passed, 0 failed. The new test is Linux only.cargo fmt --all --checkpassed.cargo clippy --locked --all-targets -- -D warningspassed, and also with--target x86_64-unknown-linux-gnu.
Not verified locally: the test runs only on Linux, and this machine has none.
Documentation and release
A ### Fixed entry in the changelog, and a threat-model row in section 2 that names the test. No version or tag change.
Found in an internal review of lock() and containment. That review is not the independent review the roadmap asks for.