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/general/closure-ffi-finder.md

View on GitHub
---
name: closure-ffi-finder
description: Detects Rust closures passed to extern "C" callbacks without panic isolation
---

**Finding ID Prefix:** `CLOSUREFFI`.

**Bug shape:** A Rust closure (or function pointer derived from one) is registered as a C callback via FFI. When the C library invokes the callback and the Rust closure panics, the unwind crosses the `extern "C"` boundary into C — **undefined behavior before Rust 1.81, and a process `abort` since Rust 1.81** (a compiler-version change, *not* the 2024 edition — edition-2021 code on rustc ≥ 1.81 already aborts; still a DoS on a server). Two derivatives: (a) the closure captures `&'a T` references whose lifetime cannot be enforced by Rust on the C side, producing UAF when C invokes the callback after the captures' scope ends; (b) `Box<dyn FnMut>` is `into_raw`'d and passed as user-data without a paired `from_raw` in a deregister path, producing leaks plus the panic-unwind hazard.

**Verification gates (ALL must pass):**

1. **Closure→C call:** Rust closure (`|...| { ... }`, `Box::new(|...| ...)`, `Box<dyn Fn(...)>`) converted to a function-pointer-typed argument of an `extern "C" fn(..)` or registered through a `*mut c_void` + trampoline pattern (`extern "C" fn trampoline(... user_data: *mut c_void)`).
2. **For the panic hazard, no `catch_unwind` guard:** the trampoline (or the closure body itself if directly `extern "C"`) does not wrap the call in `std::panic::catch_unwind` and convert the result to an error code / safe-default return. (This gate scopes the *panic* sub-case only — the capture-UAF and leak derivatives in gate 3 are independent of `catch_unwind` and are filed regardless of whether a guard exists.)
3. **A hazard is present — at least one of:** *(panic)* the closure body calls into Rust code that *can* panic — `unwrap`/`expect`/indexing/`assert!`/arithmetic on untrusted inputs/allocations (the unwind-across-FFI hazard); *(capture-UAF, derivative (a))* the closure captures `&'a T` references whose lifetime the C side can outlive; or *(leak, derivative (b))* a `Box<dyn Fn*>` is `into_raw`'d / handed over as user-data with no paired `from_raw` on a deregister path. If the body is provably panic-free (`no_std` arithmetic in `wrapping_*` form, no allocs, no `unwrap`/`expect`/indexing/`assert!`) **and** neither derivative (a) nor (b) applies, do not file. Do not assign or lower a severity yourself — that is the fp+severity judge's job; your decision here is file / don't-file on whether any of these hazards is reachable.

**FPs to reject:**

- Trampoline already uses `catch_unwind` and converts to a C-friendly error code.
- The trampoline body is provably panic-free (gate 3 already covers this), or the callback runs in a non-server / non-DoS-relevant context. (Note: `#[unwind(abort)]` is **not** a valid guard — that attribute was removed years ago and does not compile. And `-C panic=abort` is **not** a mitigation: under it a panic in the callback still aborts the whole process — the same DoS the bug shape warns about — and `catch_unwind` becomes a no-op.)
- The callback is registered for `signal()` and the issue is signal-safety (covered by `REENTRANT`).

**Search patterns:**

```
extern\s+"C"\s*\{
\bextern\s+"(C|C-unwind|system)"\s*fn\b
\bBox::into_raw\b
\bdyn\s+Fn(Once|Mut)?\b
catch_unwind
```

The first pattern matches only the `extern "C" {` block opener — ripgrep is line-oriented, so the old body-spanning `extern "C" \{[^}]*fn...fn...\)` could not match a multi-line block; Read the located block to enumerate its function-pointer callback params instead.

For each hit, find the trampoline and check for `catch_unwind`.

**Patch:** wrap the closure body inside the `extern "C"` trampoline with `std::panic::catch_unwind(AssertUnwindSafe(|| { ... }))` and translate `Err` to a C error code (or to the C library's documented failure return). For `Box<dyn FnMut>` user-data, ensure the deregister path calls `Box::from_raw` exactly 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