|
| 1 | +# Carbon Swarm Audit Summary — Cowrie v1.3.0 |
| 2 | + |
| 3 | +- **Branch:** `feat/carbon-audit-fixes` (branched from `main` @ `af022ab` in isolated worktree `/tmp/cowrie-carbon-audit`) |
| 4 | +- **Commits:** `e06936b` (`SPEC.md` v1.3.0 sync — F7), `3199bd6` (code + regression tests — F1–F6, E2, E3, N1, N3) |
| 5 | +- **Overall Result:** 7 external audit findings + 3 evaluation areas independently reproduced by 3 adversarial reviewers (**R1 Security/FFI**, **R2 Runtime/vLLM**, **R3 Spec/API**). Every real bug received a fail-before / pass-after regression test; all 13 verification suites pass with zero compiler warnings, zero C-ABI regressions, and zero changes to `formal/` or `/home/omen/cowrie`. |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## 1. Four Highest-Impact Fixes |
| 10 | + |
| 11 | +### 1. Deterministic Session Taint Root & Push-Site Deduplication (**F2**) |
| 12 | +- **Impact:** Eliminates the multi-read UX deadlock where 15 untrusted reads forced 15 separate Ed25519 signatures and 15 nonce consumptions for a single privileged tool call — and unblocks `StatelessChallengeVerifier` (single active slot) on multi-CID tainted sessions. |
| 13 | +- **What Changed:** Added `compute_session_taint_root` / `session_taint_root_cid` using a domain-separated `0x53 0x20` prefix (`0x53 0x20 || SHA-256("COWRIE_TAINT_SET_V1\0" || sorted_unique_cids)`) so taint-set roots can never collide with single-frame `0x12 0x20` CIDs while remaining 100% compatible with `CapabilityTokenV2`, C-ABI, and `EvidenceBundle`. Deduplicated all 5 taint push sites in `cowrie mcp-proxy`, added `cowrie_session_taint_root` C-ABI, emitted `session_taint_root` + `tainted_count` in `-32025` error responses, and updated `CowrieToolGuard` + HITL callback. Legacy per-CID tokens remain accepted. |
| 14 | + |
| 15 | +### 2. Secret-Path Normalization, Deepest-Ancestor Symlink Resolution & `_cowrie_*` Smuggling Fix (**F1 + N1**) |
| 16 | +- **Impact:** Closes real secret-path bypasses across both Rust (`trust.rs`) and Python (`cowrie/__init__.py`) **plus** a high-severity smuggling bug discovered during triage (`N1`: `_cowrie_path: "/etc/shadow"` inside `params.arguments` bypassed `find_secret_path_in_value` and reached child MCP servers). |
| 17 | +- **What Changed:** Implemented an iterative deepest-existing-ancestor symlink/dangling-link resolver (capped at 40 hops), RFC 8089 `file://localhost/` & `127.0.0.1/` + `FILE://` + `%XX` decoding, interior quote & POSIX backslash unquoting, lexical `..` normalization, allowlist `"/"` rejection & `~` expansion, exact `_COWRIE_CONTROL_KEYS` allowlist instead of wildcard `_cowrie_*` skipping, and `_cowrie_*` stripping from `params.arguments` in `mcp-proxy`. |
| 18 | + |
| 19 | +### 3. Bounded JSON Parser Memory Budget & O(1)-Drain `mcp-proxy` Framing (**F3**) |
| 20 | +- **Impact:** Prevents trivial pre-validation OOM crashes when a hostile client or MCP server sends a multi-gigabyte newline-free line or an expanded JSON array/object bomb. |
| 21 | +- **What Changed:** Threaded `MAX_DECODED_BYTES` (64 MiB) and `MAX_KEY_LEN` (65,536) accounting through `parse_json_impl` (`canonical.rs`), returning `CowrieError::AllocLimit (18)` without breaking the 33-variant C-ABI freeze. Replaced unbounded `BufReader::lines()` on both `stdin` and `child_out` in `mcp-proxy` with `read_line_bounded` (16 MiB default, draining oversize lines to `\n` in O(1) memory so subsequent JSON-RPC frames remain synchronized, and tainting context fail-closed on child overflow). Fixed the $O(N^2)$ `text.slice(i)` number regex in `wasm/mcp-mediator.mjs`. |
| 22 | + |
| 23 | +### 4. vLLM Connector 1× Merkle Verification, Multi-Rank TP/PP Parity & Pinned Slab Accounting (**F5**) |
| 24 | +- **Impact:** Removes two redundant multi-GB Merkle scans from the vLLM scheduler thread (fixing 3× -> 1× verification per cache hit), fixes a **0%-hit-rate bug on TP>1/PP>1 deployments** discovered during triage, and fixes pinned-memory fragmentation starvation, orphan leaks, and async CUDA D2H use-after-release races. |
| 25 | +- **What Changed:** Added additive read-only O(1) `cowrie_statepage_probe_header` (verifying Page 0 + 94B EOF trailer + HMAC + pins via `pread` without mapping payload bytes) and cached scheduler matches so full Merkle verification runs unconditionally once in worker `start_load_kv` while keeping `cowrie_statepage_open_strict(verify_hash=0)` fail-closed. Added deterministic `_rank_doc_cid` across scheduler and workers for TP/PP>1 parity. Fixed `_ReusableSlabPool` idle eviction, `_fast_staging.clear()` draining, exception rollbacks, `_d2h_stream.synchronize()` before aborted-slab release, and V4 manifest multi-page offset/padding bugs. |
| 26 | + |
| 27 | +*(Additional high-value fixes shipped in `3199bd6` & `e06936b`: **E3** fixed a live UTF-8 char-boundary panic and $O(N^2)$ grep DoS in `lens.rs`, plus `evidence.rs` accepting `state == "revoked"` with `revoked_at == 0`, unsigned Plane C tensors, and unescaped JSON reports, plus Python `evidence.py` `$bytes` sentinel corruption and **N3** uninitialized FFI `*out_json`; **F4** fixed `FloatBits` canonical equality and `CWNL0002` skew-guarded expiry pruning/compaction; **F6** removed `_find_lib()`'s incompatible `fallback_path` and enforced safe-path + ABI checks on `COWRIE_LIB`/`COWRIE_LIB_PATH`; **E2** shrank the default `cowrie` CLI by `75.9 KB` / `-6.0%` and removed `1,211` LOC of IVF/ZoneMap/SIMD code and `bench-live-ivf` from the CLI; **F7** synced `SPEC.md` to v1.3.0.)* |
| 28 | + |
| 29 | +--- |
| 30 | + |
| 31 | +## 2. What Was Refused (and Why) |
| 32 | + |
| 33 | +1. **Scoped workspace glob rules for auto-allowing tainted `fs_write` (`E1` — REFUSED / DEFERRED):** |
| 34 | + - With F2 (`session_taint_root`), a user approves an entire multi-read tainted snapshot with a single signature — removing the UX deadlock without weakening causal taint boundaries. |
| 35 | + - A userspace stdio MCP proxy cannot verify a child server's CWD, symlink races, or write-to-build-script RCE paths (`build.rs`, `Makefile`, `setup.py`, `src/main.rs`), and auto-allowing tainted `fs_write` contradicts `docs/SECURITY.md`'s fail-closed guarantees. |
| 36 | +2. **Making `Value::FloatBits(u64)` private or a newtype (`F4a` — REFUSED API BREAK):** |
| 37 | + - Changing the public enum variant breaks downstream Rust callers (`lib.rs`, `main.rs`, `lens.rs`, `fuzz/src/wire_model.rs`) while wire encoding, JSON, and FFI already canonicalized `-0.0` and `NaN` (no CID malleability). Fixed with API-preserving manual `PartialEq`/`Eq` over `canonicalize_f64_bits`. |
| 38 | +3. **Allowing `verify_hash=0` on `cowrie_statepage_open_strict` (`F5a` — REFUSED SECURITY WEAKENING):** |
| 39 | + - Weakening `cowrie_statepage_open_strict` would regress `SEC-09` (fail-closed C-ABI pins). Solved cleanly with read-only `cowrie_statepage_probe_header` that never exposes payload pointers. |
| 40 | +4. **Non-atomic write race claim in `_persist_slab_bg` (`F5b` — REFUSED FALSE POSITIVE):** |
| 41 | + - Counter-evidence verified in `crates/cowrie-core/src/shard.rs:652, 736-766`: `save_statepage_atomic_ext_opts` already writes to an `O_CREAT|O_EXCL 0600` `.tmp` file and atomically renames it into place. (Fixed the real TP/PP>1 `doc_cid` mismatch instead.) |
| 42 | +5. **Audit's claimed F1(a) shell examples & F1(c) Python symlink gap (`F1` — PARTIAL COUNTER-EVIDENCE):** |
| 43 | + - `cat ~/.ssh/"id_rsa"` and `$HOME/.s""sh/id_rsa` were already blocked on `main`, and Python's `os.path.realpath` already resolved multi-level non-existent descendants. Fixed the *real* remaining bypasses (`/etc/"shadow"`, `~/.s""sh/id""_rsa`, backslash escapes, `file://localhost/`, Rust multi-level/dangling symlinks, allowlist `"/"`, and N1 `_cowrie_*` smuggling). |
| 44 | +6. **Dropping `COWRIE_LIB_PATH` (`F6` — REFUSED CI BREAK):** |
| 45 | + - `Makefile` and CI rely on `COWRIE_LIB_PATH`; preserved both `COWRIE_LIB` and `COWRIE_LIB_PATH` while enforcing identical `_is_safe_shared_lib` + fail-closed existence/ABI checks on both. |
| 46 | +7. **Disabling `ivf`/`zonemap` by default in `cowrie-core` (`E2` — REFUSED CONFORMANCE BREAK):** |
| 47 | + - Turning them off in `cowrie-core` by default would break `libcowrie_core.so`, `conformance.py`, `cowrie.h`, and `fuzz`. Kept them default-on in `cowrie-core`, disabled them in `cowrie-cli` (`default-features = false`), and gated `bench-live-ivf` behind `feature = "bench"`. |
| 48 | +8. **Adding a new `CowrieError` code for JSON/line budget (`F3` — REFUSED ABI BREAK):** |
| 49 | + - `harness/check_err_codes.py` freezes the 33-variant error ABI (`1..=33`). Reused `CowrieError::AllocLimit (18)`. |
0 commit comments