From 43dc318f122f7b5bfe663a1e28e1d85c5a879321 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 23 Sep 2026 05:14:32 +0200 Subject: [PATCH] Land R-I23 of Cut 1's eighth fix batch: make the resolver's bypass a compile error Soul pass 8 proved the FrozenSymlinkFs port (R-I14) was an honour system one level up from the counter it replaced: restoring the S5-1 cubic bug as `candidate.canonicalize()?` in resolve_frozen_source_symlink's Normal arm left all 193 tests green, and open_frozen_symlink_frame was still calling fs::read_link directly, proving the convention leaks. - Add `read_link` to FrozenSymlinkFs and route open_frozen_symlink_frame and validate_frozen_source_symlink's root resolution through it. - Move every function the resolver can reach into a `frozen_symlink_port` submodule with `#![deny(clippy::disallowed_methods)]`; drivers.rs blanket-allows the lint at the top of the file since most of the crate has legitimate, unrelated reasons to call these methods (host.rs and provisioning.rs get the same blanket allow). Everything the module exports is re-exported so every existing caller and test keeps its bare name. - Add clippy.toml listing Path::canonicalize, fs::canonicalize, fs::symlink_metadata and fs::read_link as disallowed, each with a reason pointing at the port. - Add .github/workflows/lint.yml: this repo had no CI surface at all before this batch, so "denied in CI" had nowhere to attach. - Update validate_frozen_source_symlinks_resolves_a_long_component_chain_ with_a_linear_call_count's formula and doc: read_link and the now-ported root canonicalize add two calls per resolution (components + 4, not + 2), and the doc no longer claims the count can't catch its own regression -- R-I23 is what catches it now (R-I24). Co-Authored-By: Claude Sonnet 5 --- .github/workflows/lint.yml | 21 +++++++ clippy.toml | 25 ++++++++ src/drivers.rs | 124 +++++++++++++++++++++++++++++-------- src/host.rs | 10 +++ src/provisioning.rs | 6 ++ 5 files changed, 161 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/lint.yml create mode 100644 clippy.toml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..b0c3ea9 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,21 @@ +name: lint + +on: + push: + pull_request: + +jobs: + clippy: + # R-I23 (Self's ruling, Cut 1's eighth fix batch, F1): this repo had no + # CI surface at all before this batch, so "denied in CI" had nowhere to + # attach. This is that surface: `clippy.toml`'s `disallowed-methods` + # list only stops a bypass of the frozen-symlink resolver's + # `FrozenSymlinkFs` port (see `src/drivers.rs`, `frozen_symlink_port`) + # if something actually runs clippy with the lint promoted to an error. + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + components: clippy + - run: cargo clippy --all-targets --all-features -- -D clippy::disallowed_methods diff --git a/clippy.toml b/clippy.toml new file mode 100644 index 0000000..05b9aa3 --- /dev/null +++ b/clippy.toml @@ -0,0 +1,25 @@ +# R-I23 (Self's ruling, Cut 1's eighth fix batch, F1): these four methods are +# how the frozen-symlink resolver's authority leaks. Soul pass 8 proved it by +# existence -- `open_frozen_symlink_frame` called `fs::read_link` directly +# while everything else in the resolver went through `FrozenSymlinkFs`, and +# restoring the pass-7 cubic bug as `candidate.canonicalize()?` (or +# `fs::canonicalize(&candidate)?`) at `resolve_frozen_source_symlink`'s +# `Normal` arm passed all 193 tests green, because nothing stopped the +# resolver from reaching past the port. +# +# This list is crate-wide because `disallowed-methods` has no per-module +# scope of its own. `src/drivers.rs` blanket-allows the lint at the top of +# the file (most of the crate has a legitimate reason to call these methods +# directly -- deployment staging, host executable-identity checks, artifact +# digesting, and so on are not part of frozen-symlink resolution) and the +# `frozen_symlink_port` submodule inside it re-denies the lint for its own +# scope, which is the only place these calls must not appear outside the +# port. A future edit that adds a bypass inside that module fails +# `cargo clippy` with this list's reason text; a call anywhere else in the +# crate is unaffected, exactly as before this batch. +disallowed-methods = [ + { path = "std::path::Path::canonicalize", reason = "frozen-symlink resolution must go through FrozenSymlinkFs::canonicalize (src/drivers.rs, frozen_symlink_port); this method is blanket-allowed outside that module" }, + { path = "std::fs::canonicalize", reason = "frozen-symlink resolution must go through FrozenSymlinkFs::canonicalize (src/drivers.rs, frozen_symlink_port); this function is blanket-allowed outside that module" }, + { path = "std::fs::symlink_metadata", reason = "frozen-symlink resolution must go through FrozenSymlinkFs::symlink_metadata (src/drivers.rs, frozen_symlink_port); this function is blanket-allowed outside that module" }, + { path = "std::fs::read_link", reason = "frozen-symlink resolution must go through FrozenSymlinkFs::read_link (src/drivers.rs, frozen_symlink_port); this function is blanket-allowed outside that module" }, +] diff --git a/src/drivers.rs b/src/drivers.rs index cb26e91..61a3900 100644 --- a/src/drivers.rs +++ b/src/drivers.rs @@ -1,3 +1,17 @@ +// R-I23 (Self's ruling, Cut 1's eighth fix batch, F1): `clippy.toml`'s +// `disallowed-methods` list has no per-module scope, so it applies to the +// whole crate by construction. This file uses `Path::canonicalize`, +// `fs::canonicalize`, `fs::symlink_metadata` and `fs::read_link` directly in +// many places that have nothing to do with frozen-symlink resolution +// (deployment staging, host executable-identity checks, artifact digesting, +// hardening, and more); the `frozen_symlink_port` submodule below is the one +// place those calls must go through `FrozenSymlinkFs` instead. This blanket +// allow, plus that submodule's own `#![deny(clippy::disallowed_methods)]`, +// is the scoping clippy.toml itself cannot express: Rust's lint-level +// attributes are lexically scoped, so the inner `deny` wins inside the +// submodule regardless of this outer `allow`, and nowhere else changes. +#![allow(clippy::disallowed_methods)] + use std::collections::BTreeMap; use std::ffi::{OsStr, OsString}; use std::fs::{self, OpenOptions}; @@ -5909,6 +5923,18 @@ fn harden_frozen_source_tree(root: &Path, current: &Path) -> Result<()> { Ok(()) } +// R-I23 (Self's ruling, eighth Cut 1 fix batch, F1): everything the +// frozen-symlink resolver can reach lives in this submodule so that +// `#![deny(clippy::disallowed_methods)]` can cover exactly it -- the rest of +// `drivers.rs` blanket-allows the lint (see the file's top attribute) +// because most of the crate has a legitimate, unrelated reason to call +// `Path::canonicalize`/`fs::canonicalize`/`fs::symlink_metadata`/ +// `fs::read_link` directly. Everything this module exports is re-exported +// right below it so every existing caller and test keeps its current path. +mod frozen_symlink_port { + #![deny(clippy::disallowed_methods)] + use super::*; + /// S6 (Self's ruling, third Cut 1 fix batch): resolves a frozen source /// symlink's full chain against the tree's real, final published root. Every /// component the chain crosses that exists on disk is resolved for real @@ -5936,7 +5962,7 @@ fn harden_frozen_source_tree(root: &Path, current: &Path) -> Result<()> { /// symlinks, doubling or not, now costs O(n) real reads no matter how many /// times its target text repeats a name. #[cfg(unix)] -enum FrozenSymlinkStep { +pub(crate) enum FrozenSymlinkStep { CurDir, ParentDir, Normal(std::ffi::OsString), @@ -5955,12 +5981,12 @@ thread_local! { } #[cfg(test)] -fn reset_frozen_symlink_probe_calls() { +pub(crate) fn reset_frozen_symlink_probe_calls() { FROZEN_SYMLINK_PROBE_CALLS.with(|calls| calls.set(0)); } #[cfg(test)] -fn frozen_symlink_probe_calls() -> u64 { +pub(crate) fn frozen_symlink_probe_calls() -> u64 { FROZEN_SYMLINK_PROBE_CALLS.with(std::cell::Cell::get) } @@ -5984,16 +6010,30 @@ fn record_frozen_symlink_probe_call() {} // longer drift apart. `resolve_frozen_source_symlink` and // `open_frozen_symlink_frame` are generic over this trait instead of // calling `Path::canonicalize`/`fs::symlink_metadata` directly. +// +// R-I23 (Self's ruling, eighth Cut 1 fix batch, F1): `read_link` joined the +// port for the same reason -- Soul pass 8 found `open_frozen_symlink_frame` +// still calling `fs::read_link` directly, the proof the convention leaks. +// This module (`frozen_symlink_port`, below) is also now the only place in +// the crate where `clippy::disallowed_methods` denies calling +// `Path::canonicalize`, `fs::canonicalize`, `fs::symlink_metadata` or +// `fs::read_link` outside this trait; see `clippy.toml` and the `#![allow]` +// at the top of this file. #[cfg(unix)] -trait FrozenSymlinkFs { +pub(crate) trait FrozenSymlinkFs { fn canonicalize(&self, path: &Path) -> std::io::Result; fn symlink_metadata(&self, path: &Path) -> std::io::Result; + fn read_link(&self, path: &Path) -> std::io::Result; } #[cfg(unix)] -struct StdFrozenSymlinkFs; +pub(crate) struct StdFrozenSymlinkFs; +// R-I23: this impl is the port's one production body, so it is the one +// place inside `frozen_symlink_port` allowed to call the real syscalls the +// rest of the module is denied from reaching around the port for. #[cfg(unix)] +#[allow(clippy::disallowed_methods)] impl FrozenSymlinkFs for StdFrozenSymlinkFs { fn canonicalize(&self, path: &Path) -> std::io::Result { record_frozen_symlink_probe_call(); @@ -6004,6 +6044,11 @@ impl FrozenSymlinkFs for StdFrozenSymlinkFs { record_frozen_symlink_probe_call(); fs::symlink_metadata(path) } + + fn read_link(&self, path: &Path) -> std::io::Result { + record_frozen_symlink_probe_call(); + fs::read_link(path) + } } #[cfg(unix)] @@ -6058,7 +6103,7 @@ fn open_frozen_symlink_frame( symlink_path.display() ); *budget -= 1; - let target = fs::read_link(symlink_path)?; + let target = fs_port.read_link(symlink_path)?; ensure!(target.is_relative(), "frozen source symlink is absolute"); let parent = symlink_path .parent() @@ -6082,7 +6127,7 @@ fn open_frozen_symlink_frame( } #[cfg(unix)] -fn resolve_frozen_source_symlink( +pub(crate) fn resolve_frozen_source_symlink( fs_port: &F, canonical_root: &Path, path: &Path, @@ -6224,11 +6269,20 @@ fn resolve_frozen_source_symlink( } #[cfg(unix)] -fn validate_frozen_source_symlink(root: &Path, path: &Path) -> Result<()> { - let canonical_root = root.canonicalize().context("resolving frozen source root")?; +pub(crate) fn validate_frozen_source_symlink(root: &Path, path: &Path) -> Result<()> { + let canonical_root = StdFrozenSymlinkFs + .canonicalize(root) + .context("resolving frozen source root")?; resolve_frozen_source_symlink(&StdFrozenSymlinkFs, &canonical_root, path).map(|_| ()) } +} // mod frozen_symlink_port + +// R-I23: flattened back into `drivers`'s own namespace so every call site +// above and every test below keeps referring to these by their bare names, +// unchanged by the module boundary this batch drew around them. +use frozen_symlink_port::*; + /// S6: run once, against the tree's real, final published path -- after the /// atomic rename off `.partial`, in `freeze_exact`, and again (read-only) /// whenever `observe_frozen` re-checks a tree it did not just write. Separate @@ -11926,15 +11980,32 @@ mod tests { /// 11 ms/359 ms pair happened to straddle the clamp boundary, which is /// what made the ratio look decisive. This test replaces the clock with /// a call count: `record_frozen_symlink_probe_call` fires once per - /// `canonicalize()` in `open_frozen_symlink_frame` and once per - /// `symlink_metadata()` per real component in the `Normal` arm, so the - /// count is `components + 2` for one symlink with a k-component target, - /// deterministic under any host load. A cubic per-component - /// `canonicalize()` cannot come back unnoticed: it would leave the call - /// count linear (unchanged) while the removed work still ran, so this - /// pin cannot catch its *own* regression by call count alone -- it - /// keeps the wall-clock reading in the assertion message for a human to - /// notice, but asserts only on the deterministic count. + /// `canonicalize()`/`read_link()` in `open_frozen_symlink_frame`, once + /// per `canonicalize()` of the root in `validate_frozen_source_symlink`, + /// and once per `symlink_metadata()` per real component in the `Normal` + /// arm, so the count is `components + 4` for one symlink with a + /// k-component target, deterministic under any host load. + /// + /// R-I14 (seventh Cut 1 fix batch, F1) is the reason this doc used to + /// say the count "cannot catch its own regression" -- the port existed, + /// but nothing stopped a call site from reaching past it, and Soul pass + /// 8 proved that by restoring the S5-1 bug as `candidate.canonicalize()?` + /// in the `Normal` arm's `Ok(_)` case: every one of the 193 tests, + /// including this one, stayed green, because a per-component + /// `canonicalize()` that returns its own (already-correct) input adds + /// no call the counter sees. **That claim is now false, and the count is + /// no longer the thing that catches it.** R-I23 (Self's ruling, eighth + /// Cut 1 fix batch, F1) made `Path::canonicalize`, `fs::canonicalize`, + /// `fs::symlink_metadata` and `fs::read_link` a `cargo clippy` compile + /// error anywhere in `frozen_symlink_port` outside the port's own + /// `StdFrozenSymlinkFs` implementation (see `clippy.toml`); Soul's exact + /// mutation is that spelling, so it now fails to build under `cargo + /// clippy -- -D clippy::disallowed_methods`, independent of what this + /// count test asserts. What the count formula still cannot do, and + /// still does not claim to: distinguish a mutation that keeps every + /// call site and every call count the same while doing needless extra + /// work *inside* one of those calls -- that class was never this test's + /// job, and nothing here pretends otherwise. #[cfg(unix)] #[test] fn validate_frozen_source_symlinks_resolves_a_long_component_chain_with_a_linear_call_count( @@ -11972,20 +12043,23 @@ mod tests { let (small_calls, small_elapsed) = resolve_and_count(50)?; let (large_calls, large_elapsed) = resolve_and_count(200)?; - // One symlink open (one canonicalize()) plus one symlink_metadata() - // per real component: components + 2, exactly -- not a bound, an - // exact formula, so a cubic term reappearing as *extra* probe calls + // R-I23 (Self's ruling, eighth Cut 1 fix batch, F1): one root + // canonicalize() in validate_frozen_source_symlink, one symlink open + // (one canonicalize() plus one read_link() in + // open_frozen_symlink_frame), and one symlink_metadata() per real + // component: components + 4, exactly -- not a bound, an exact + // formula, so a cubic term reappearing as *extra* probe calls // (rather than hidden extra work per call) would still be caught. assert_eq!( small_calls, - 52, - "50 real components must cost exactly 50 + 2 = 52 canonicalize()/\ + 54, + "50 real components must cost exactly 50 + 4 = 54 canonicalize()/read_link()/\ symlink_metadata() calls: {small_calls} (took {small_elapsed:?})" ); assert_eq!( large_calls, - 202, - "200 real components must cost exactly 200 + 2 = 202 canonicalize()/\ + 204, + "200 real components must cost exactly 200 + 4 = 204 canonicalize()/read_link()/\ symlink_metadata() calls: {large_calls} (took {large_elapsed:?})" ); // A 4x longer chain costing ~4x the calls (not ~64x, the cubic diff --git a/src/host.rs b/src/host.rs index 5221f12..96e777c 100644 --- a/src/host.rs +++ b/src/host.rs @@ -11,6 +11,16 @@ //! Only the process layer is Windows-specific and it is confined to //! `platform`. Everything else is the same code Idunn runs on yggdrasil. +// R-I23 (Self's ruling, Cut 1's eighth fix batch, F1): `clippy.toml`'s +// `disallowed-methods` list (`Path::canonicalize`, `fs::canonicalize`, +// `fs::symlink_metadata`, `fs::read_link`) exists to keep the frozen-symlink +// resolver in `drivers.rs` from bypassing its `FrozenSymlinkFs` port; it has +// no per-module scope of its own, so it applies to this file too even +// though this file's own executable-identity comparisons have nothing to do +// with that resolver. See `drivers.rs`'s matching attribute for the full +// rationale. +#![allow(clippy::disallowed_methods)] + use std::collections::{BTreeMap, BTreeSet}; use std::fs::{self, File}; use std::io::Write; diff --git a/src/provisioning.rs b/src/provisioning.rs index 1c74a83..1d719d7 100644 --- a/src/provisioning.rs +++ b/src/provisioning.rs @@ -1,3 +1,9 @@ +// R-I23 (Self's ruling, Cut 1's eighth fix batch, F1): see the matching +// attribute in `drivers.rs` -- `clippy.toml`'s `disallowed-methods` list has +// no per-module scope, so it reaches this file's unrelated `.canonicalize()` +// call too unless blanket-allowed here. +#![allow(clippy::disallowed_methods)] + use anyhow::{Context, Result, anyhow, bail}; use cultcache_rs::{ CultCacheEnvelope, CultCacheExpectedEnvelope, DatabaseEntry, SingleFileMessagePackBackingStore,