diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4e7aaa06..cb986592 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,11 +36,11 @@ jobs: libssl-dev \ libayatana-appindicator3-dev \ librsvg2-dev - # SHA-pinned; the toolchain version no longer rides on the action ref, so - # it must be passed explicitly (kept in sync with rust-toolchain.toml). + # dtolnay/rust-toolchain hardcodes the version in the tag commit the SHA + # pins (no `toolchain` input exists at it) — this is the `1.96.1` tag, + # kept in sync with rust-toolchain.toml. Bump = new tag's SHA. - uses: dtolnay/rust-toolchain@2fe4ca74464c5902a4f6e302d0a619b4ea911ccc # 1.96.1 with: - toolchain: 1.96.1 components: rustfmt, clippy - uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2 - name: fmt diff --git a/.github/workflows/fuzz.yml b/.github/workflows/fuzz.yml new file mode 100644 index 00000000..27014a5c --- /dev/null +++ b/.github/workflows/fuzz.yml @@ -0,0 +1,57 @@ +name: fuzz + +# Nightly libFuzzer run on the remote-facing decode surface (OSTIF audit +# T-13, G-001): the framed wire protocol `sc serve` parses from untrusted +# peers, its body decoders, and canonical object decoding. Runs on a +# schedule, never as a PR gate — nightly + sanitizers don't belong in the +# merge path. A crash uploads its reproducer input as an artifact. +on: + schedule: + # Nightly, before the 06:23 audit run. + - cron: "17 3 * * *" + # Build + short run when the fuzz surface itself changes, so a broken + # harness is caught in the PR that breaks it (not a required check). + pull_request: + paths: + - "fuzz/**" + - ".github/workflows/fuzz.yml" + workflow_dispatch: + +permissions: + contents: read + +jobs: + wire-decode: + name: cargo fuzz (wire_decode) + runs-on: ubuntu-latest + timeout-minutes: 30 + env: + # The repo-root rust-toolchain.toml pins stable 1.96.1 and overrides the + # installed rustup default; libFuzzer needs nightly, and this env var + # outranks the toolchain file. + RUSTUP_TOOLCHAIN: nightly + steps: + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + # dtolnay/rust-toolchain encodes the toolchain in the tag the SHA pins + # (there is no `toolchain` input at these commits) — this is the + # `nightly` tag's commit. + - uses: dtolnay/rust-toolchain@4fd1da8b0805d2d2e936788875a7d65dbd677dc2 # nightly + - uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2 + with: + workspaces: fuzz + - name: install cargo-fuzz + run: cargo install cargo-fuzz --locked + - name: build fuzz target + run: cargo fuzz build wire_decode + - name: fuzz for 10 minutes + # rss_limit above MAX_OBJECT_SIZE-sized legitimate allocations so the + # documented frame-length pre-allocation (ADR-0039 deferred item) + # doesn't false-positive; a real runaway still trips it. + run: cargo fuzz run wire_decode -- -max_total_time=600 -rss_limit_mb=4096 + - name: upload crash reproducers + if: failure() + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: fuzz-artifacts + path: fuzz/artifacts/ + if-no-files-found: ignore diff --git a/.github/workflows/sbom.yml b/.github/workflows/sbom.yml index 5d9ffd6d..2cacf687 100644 --- a/.github/workflows/sbom.yml +++ b/.github/workflows/sbom.yml @@ -25,9 +25,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + # The pinned tag commit hardcodes 1.96.1 (no `toolchain` input exists). - uses: dtolnay/rust-toolchain@2fe4ca74464c5902a4f6e302d0a619b4ea911ccc # 1.96.1 - with: - toolchain: 1.96.1 - name: install cargo-cyclonedx run: cargo install cargo-cyclonedx --locked --version 0.5.9 - name: rust SBOMs (binaries, all target platforms) diff --git a/Cargo.toml b/Cargo.toml index 414c83d2..742e6e0e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [workspace] resolver = "2" members = ["crates/core", "crates/vfs", "crates/gitio", "crates/crypto", "crates/repo", "crates/cli", "crates/tlsio", "apps/desktop/src-tauri"] -exclude = ["vendor/glib-0.18.5-patched"] +exclude = ["vendor/glib-0.18.5-patched", "fuzz"] # Tauri 2's Linux GTK3 stack is pinned to glib 0.18.5, whose VariantStrIter # implementation contains RUSTSEC-2024-0429. This published-source copy carries diff --git a/fuzz/.gitignore b/fuzz/.gitignore new file mode 100644 index 00000000..ab0eaa1a --- /dev/null +++ b/fuzz/.gitignore @@ -0,0 +1,5 @@ +target/ +corpus/ +artifacts/ +coverage/ +Cargo.lock diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml new file mode 100644 index 00000000..1a509897 --- /dev/null +++ b/fuzz/Cargo.toml @@ -0,0 +1,30 @@ +[package] +name = "scl-fuzz" +version = "0.0.0" +publish = false +edition = "2021" + +# Its own workspace: fuzz targets need nightly + libFuzzer and must not join +# the stable root workspace (root Cargo.toml excludes this directory). +[workspace] + +[package.metadata] +cargo-fuzz = true + +[dependencies] +libfuzzer-sys = "0.4" +scl-core = { path = "../crates/core" } +scl-repo = { path = "../crates/repo" } + +[patch.crates-io] +glib = { path = "../vendor/glib-0.18.5-patched" } + +[[bin]] +name = "wire_decode" +path = "fuzz_targets/wire_decode.rs" +test = false +doc = false +bench = false + +[profile.release] +debug = 1 diff --git a/fuzz/fuzz_targets/wire_decode.rs b/fuzz/fuzz_targets/wire_decode.rs new file mode 100644 index 00000000..bbb24d38 --- /dev/null +++ b/fuzz/fuzz_targets/wire_decode.rs @@ -0,0 +1,37 @@ +//! Fuzz the remote-facing decode surface: the framed wire protocol that +//! `sc serve` parses from untrusted peers, and the canonical object decoding +//! underneath it. ADR-0039 hardened these paths against hostile input and +//! self-identified the frame-length header as the residual weak point — this +//! target exercises exactly that surface (OSTIF audit T-13, G-001). +//! +//! The invariant under test is totality: every entry point returns Ok or Err +//! on arbitrary bytes; a panic, overflow, or runaway allocation is a finding. + +#![no_main] + +use libfuzzer_sys::fuzz_target; +use std::io::Cursor; + +use scl_repo::wire; + +fuzz_target!(|data: &[u8]| { + // The socket layer: attacker bytes through the frame reader, then each + // recovered frame through both request and response parsing. + let mut cur = Cursor::new(data); + while let Ok(Some(frame)) = wire::read_frame_opt(&mut cur) { + let _ = wire::Request::decode(&frame); + let _ = wire::parse_response(frame); + } + + // The same bytes straight into each body decoder (a hostile peer controls + // frame payloads independently of the framing). + let _ = wire::Request::decode(data); + let _ = wire::decode_refs_body(data); + let _ = wire::decode_ids_body(data); + let _ = wire::decode_str_body(data); + let _ = wire::decode_u32_body(data); + let _ = wire::decode_bool_body(data); + + // The object layer transfers ultimately deserialize into. + let _ = scl_core::Object::decode(data); +});