Skip to content

sb-dev/openquant / .agents/skills/rust-review

rust-review

Verified

Review Rust crates, services, or libraries for safe/unsafe boundary issues, memory safety, concurrency hazards, panic-induced denial of service, FFI safety, and async runtime mistakes. Use for a Rust security audit, especially unsafe, FFI, or concurrent code.

FileKindSize
SKILL.mdskill md5.4 KB
upstream/.claude-plugin/plugin.jsonconfig530 B
upstream/README.mdmarkdown8.2 KB
upstream/agents/rust-review-dedup-judge.mdmarkdown20.4 KB
upstream/agents/rust-review-fp-judge.mdmarkdown23.1 KB
upstream/agents/rust-review-worker.mdmarkdown31.8 KB
upstream/prompts/clusters/async-runtime.mdmarkdown855 B
upstream/prompts/clusters/concurrency-data-race.mdmarkdown2.6 KB
upstream/prompts/clusters/concurrency-locking.mdmarkdown6.9 KB
upstream/prompts/clusters/error-handling.mdmarkdown1.6 KB
upstream/prompts/clusters/ffi-cross-language.mdmarkdown3.3 KB
upstream/prompts/clusters/info-disclosure.mdmarkdown562 B
upstream/prompts/clusters/input-os-safety.mdmarkdown1.1 KB
upstream/prompts/clusters/layout-safety.mdmarkdown572 B
upstream/prompts/clusters/logic-correctness.mdmarkdown3.8 KB
upstream/prompts/clusters/manifest.jsonconfig10.9 KB
upstream/prompts/clusters/memory-safety.mdmarkdown4.6 KB
upstream/prompts/clusters/panic-dos.mdmarkdown6.0 KB
upstream/prompts/clusters/recursion-dos.mdmarkdown5.3 KB
upstream/prompts/clusters/resource-handling.mdmarkdown1.5 KB
upstream/prompts/clusters/static-hygiene.mdmarkdown746 B
upstream/prompts/clusters/unsafe-boundary.mdmarkdown15.6 KB
upstream/prompts/general/abi-mismatch-finder.mdmarkdown705 B
upstream/prompts/general/adversarial-trait-finder.mdmarkdown1.5 KB
upstream/prompts/general/arithmetic-overflow-finder.mdmarkdown2.1 KB
upstream/prompts/general/assertion-reachable-finder.mdmarkdown879 B
upstream/prompts/general/async-blocking-finder.mdmarkdown1.2 KB
upstream/prompts/general/atomic-race-finder.mdmarkdown1.3 KB
upstream/prompts/general/buffer-overflow-unsafe-finder.mdmarkdown2.6 KB
upstream/prompts/general/bufwriter-unflushed-finder.mdmarkdown995 B
upstream/prompts/general/cancel-safety-finder.mdmarkdown1.2 KB
upstream/prompts/general/cargo-lint-config-finder.mdmarkdown2.4 KB
upstream/prompts/general/closure-ffi-finder.mdmarkdown3.9 KB
upstream/prompts/general/closure-panic-finder.mdmarkdown1.1 KB
upstream/prompts/general/collection-key-mutation-finder.mdmarkdown1.9 KB
upstream/prompts/general/cstring-dangling-finder.mdmarkdown1.3 KB
upstream/prompts/general/deprecated-api-finder.mdmarkdown1.9 KB
upstream/prompts/general/destructor-skip-finder.mdmarkdown1.4 KB
upstream/prompts/general/double-free-finder.mdmarkdown1.6 KB
upstream/prompts/general/drop-panic-finder.mdmarkdown973 B
upstream/prompts/general/dyn-trait-ffi-finder.mdmarkdown2.8 KB
upstream/prompts/general/float-edge-finder.mdmarkdown798 B
upstream/prompts/general/foreign-drop-finder.mdmarkdown2.7 KB
upstream/prompts/general/invalid-free-finder.mdmarkdown1.2 KB
upstream/prompts/general/lossy-from-into-finder.mdmarkdown603 B
upstream/prompts/general/lossy-str-conversion-finder.mdmarkdown1.2 KB
upstream/prompts/general/msrv-mismatch-finder.mdmarkdown401 B
upstream/prompts/general/nondeterminism-finder.mdmarkdown1.6 KB
upstream/prompts/general/opaque-pointer-finder.mdmarkdown1.9 KB
upstream/prompts/general/ord-eq-hash-finder.mdmarkdown754 B
upstream/prompts/general/out-of-bounds-index-finder.mdmarkdown727 B
upstream/prompts/general/packed-field-ref-finder.mdmarkdown3.7 KB
upstream/prompts/general/panic-unwind-unsafe-finder.mdmarkdown3.0 KB
upstream/prompts/general/path-traversal-join-finder.mdmarkdown1.7 KB
upstream/prompts/general/pointer-exposure-finder.mdmarkdown1.8 KB
upstream/prompts/general/raw-fd-lifecycle-finder.mdmarkdown2.0 KB
upstream/prompts/general/recursive-deserialize-stack-overflow-finder.mdmarkdown4.8 KB
upstream/prompts/general/recursive-drop-stack-overflow-finder.mdmarkdown2.7 KB
upstream/prompts/general/recursive-format-stack-overflow-finder.mdmarkdown4.1 KB
upstream/prompts/general/refcell-borrow-panic-finder.mdmarkdown1.2 KB
upstream/prompts/general/repr-c-padding-finder.mdmarkdown2.2 KB
upstream/prompts/general/resource-exhaustion-finder.mdmarkdown2.4 KB
upstream/prompts/general/result-discarded-finder.mdmarkdown1.6 KB
upstream/prompts/general/select-bias-finder.mdmarkdown1.2 KB
upstream/prompts/general/send-sync-bounds-finder.mdmarkdown2.6 KB
upstream/prompts/general/serialize-struct-mismatch-finder.mdmarkdown2.3 KB
upstream/prompts/general/shared-memory-race-finder.mdmarkdown2.8 KB
upstream/prompts/general/static-mut-race-finder.mdmarkdown2.8 KB
upstream/prompts/general/str-slice-boundary-finder.mdmarkdown1.0 KB
upstream/prompts/general/string-comparison-finder.mdmarkdown1.4 KB
upstream/prompts/general/toctou-finder.mdmarkdown1.3 KB
upstream/prompts/general/uninitialized-read-finder.mdmarkdown1.8 KB
upstream/prompts/general/union-ub-finder.mdmarkdown3.5 KB
upstream/prompts/general/unsafe-sync-impl-finder.mdmarkdown3.7 KB
upstream/prompts/general/unwrap-on-untrusted-finder.mdmarkdown1.3 KB
upstream/prompts/general/use-after-free-finder.mdmarkdown2.9 KB
upstream/prompts/general/vec-set-len-uninit-finder.mdmarkdown2.5 KB
upstream/scripts/build_run_plan.pyscript24.0 KB
upstream/scripts/generate_sarif.pyexecutablescript22.9 KB
upstream/scripts/pyproject.tomlmanifest220 B
upstream/scripts/test_gating.pyscript12.6 KB
upstream/scripts/test_generate_sarif.pyscript19.5 KB
upstream/scripts/test_prompt_regexes.pyscript4.3 KB
upstream/scripts/test_split.pyscript10.2 KB
upstream/scripts/test_validate_artifacts.pyscript10.3 KB
upstream/scripts/validate_artifacts.pyscript11.4 KB
upstream/skills/rust-review/SKILL.upstream.mdmarkdown43.5 KB

upstream/prompts/clusters/memory-safety.md

View on GitHub
---
name: cluster-memory-safety
kind: cluster
consolidated: false
covers:
  - use-after-free      # UAF
  - double-free         # DFREE
  - invalid-free        # INVFREE
  - uninitialized-read  # UNINITREAD
  - vec-set-len-uninit  # SETLEN
  - buffer-overflow-unsafe # BOF
  - union-ub             # UNIONUB
  - panic-unwind-unsafe  # PANICUNWIND
---

# Cluster: Memory safety (unsafe code)

Rust memory-safety bugs ALWAYS originate from `unsafe` code. Per empirical study, 70 production memory-safety bugs all had a propagation chain across the safe/unsafe boundary. The sub-passes share one mental model: **for each unsafe block, who owns the memory, when does it Drop, and who else points at it?**

ID prefixes: `UAF`, `DFREE`, `INVFREE`, `UNINITREAD`, `SETLEN`, `BOF`, `UNIONUB`, `PANICUNWIND`.

Cluster gate `has_unsafe` — when `has_unsafe=false`, the orchestrator drops this entire cluster before spawn (the manifest gates the whole cluster, not each pass).

---

## Phase A — Build the unsafe-memory map (ONCE per run)

Run these scans:

```
rg seed: "\bunsafe\s*\{"
rg seed: "(\.|::)(as_ptr|as_mut_ptr|into_raw|from_raw(_parts)?)\("  # method `.into_raw()` AND assoc-fn `Box::from_raw(`/`Rc::into_raw(`/`Vec::from_raw_parts(`/`CString::from_raw(`
rg seed: "\bptr::(read|write|copy(_nonoverlapping)?|drop_in_place|offset|add|sub)\b"
rg seed: "\.(add|sub|offset|read|write|copy_to|copy_from|copy_to_nonoverlapping|copy_from_nonoverlapping)(_unaligned|_volatile)?\s*\("  # raw-pointer METHOD form (p.read(), p.add(i)) — complements the ptr:: free-fn line above
rg seed: "\b(get_unchecked(_mut)?)\s*\("
rg seed: "\bMaybeUninit::|\.assume_init(_read|_mut|_ref)?\s*\("  # broad MaybeUninit seed catches turbofish forms with nested generics; method form catches value.assume_init*
rg seed: "\b(mem::uninitialized|mem::zeroed|mem::transmute|mem::forget|ManuallyDrop::)"
rg seed: "\b(alloc|dealloc|realloc)\s*\(|\balloc::(alloc|dealloc|realloc)\b"  # allocator calls: bare/imported `dealloc(p, layout)`, method `.dealloc(`, and fully-qualified `std::alloc::dealloc`
rg seed: "\bunion\s+\w+\b"
rg seed: "\bset_len\s*\(|\bfrom_raw_parts\s*\(|\bspare_capacity_mut\s*\("
rg seed: "drop_in_place|catch_unwind"
```

Record `mem_map[site] = { kind, type, owner_var, lifetime_scope, drop_site }`.

Then read each finder below and apply against `mem_map`.

---

## Phase B — Run finders in order

1. **`UNINITREAD` — Uninitialized read** — prerequisite for INVFREE/UAF (uninit memory can't be freed correctly).
2. **`SETLEN` — Vec length without init** — `set_len` / `from_raw_parts` exposes uninitialized slots through safe APIs; often co-occurs with UNINITREAD on `MaybeUninit` paths but files at the vec init gap.
3. **`INVFREE` — Invalid free via assignment-to-uninit** — `*ptr = val` where `ptr` is uninitialized triggers Drop on garbage.
4. **`UAF` — Use-after-free via dangled raw pointer** — pointer outlives implicit Drop scope.
5. **`DFREE` — Double free via `ptr::read`** — non-Copy heap type duplicated.
6. **`BOF` — Buffer overflow via flawed index** — safe-side arithmetic into `unsafe` unchecked access.
7. **`UNIONUB` — Union variant misread or aliasing** — reading a union field whose validity invariants are not proven for the currently-active variant, or taking a reference into one field while another owned field is live.
8. **`PANICUNWIND` — Panic during unsafe container mutation** — stale `len`/capacity across unwind → second `Drop`/`clear` (UAF/double-free class via metadata, not dangling pointer alone).

---

## Deconfliction

- `INVFREE` > `UAF` if the freed memory was uninitialized (root cause is missing init, not stale pointer).
- `UAF` > `DFREE` if a single pointer dereferenced after free; `DFREE` requires two distinct Drop calls.
- `SETLEN` > `UNINITREAD` when the bug is specifically `Vec::set_len` / `from_raw_parts` without slot init (not `assume_init` on a struct field).
- `UNINITREAD` is independent when `MaybeUninit::assume_init` is the sole failure mode.
- `BOF` is independent (different mechanic).
- `UNIONUB` is independent of `UNINITREAD`/`INVFREE`: it concerns *misinterpretation* of valid bytes, not absence of init.
- `PANICUNWIND` > `DFREE`/`UAF` when unwind leaves container metadata describing already-dropped elements; `DFREE`/`UAF` without a panic on the mutation path.
- `PANICUNWIND` vs `DROPPANIC` (error-handling): container bookkeeping across unwind vs panic inside `impl Drop for T` itself.
- `PANICUNWIND` vs `CLOSUREPANIC` (logic-correctness): user `Fn` between two pointer ops vs custom vec-like `len` not committed before `drop_in_place`.

Build `mem_map` ONCE.
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall