Skip to content

feat: add --deep MIR-based analysis via capsec-driver#52

Merged
bordumb merged 6 commits intomainfrom
dev-mirDepthCheck
Mar 24, 2026
Merged

feat: add --deep MIR-based analysis via capsec-driver#52
bordumb merged 6 commits intomainfrom
dev-mirDepthCheck

Conversation

@bordumb
Copy link
Copy Markdown
Collaborator

@bordumb bordumb commented Mar 24, 2026

Adds a --deep flag to cargo capsec audit that uses rustcs MIR
(Mid-level IR) to analyze all crates in the dependency tree, catching
authority usage that syntactic analysis misses — macro-expanded FFI
calls try_call!, trait dispatch, and generic instantiation.

Architecture:

  • New crates/capsec-deep/ crate (excluded from workspace, requires nightly)
  • capsec-driver binary implements rustc_driver::Callbacks::after_analysis
  • Walks MIR BasicBlocks → TerminatorKind::Call → extracts DefId targets
  • Classifies calls against authority patterns via def_path_str
  • Detects FFI calls via tcx.is_foreign_item — sees through macro wrappers
  • Filters std/core/alloc and proc-macro crates to reduce noise
  • Uses RUSTC_WRAPPER to analyze all crates including transitive dependencies
  • Communicates findings via JSONL temp file ($CAPSEC_DEEP_OUTPUT)
  • CLI reads JSONL, patches crate names/versions to match Cargo metadata, deduplicates against syntactic findings, merges into unified output

Tested on heartwood: 613 → 837 findings, 12 → 26 crates analyzed.
New findings include std::net socket config calls, std::fs::OpenOptions,
std::env::temp_dir, and FFI calls resolved through macros that the
syntactic scanner could not see.

  Adds a `--deep` flag to `cargo capsec audit` that uses rustcs MIR
  (Mid-level IR) to analyze all crates in the dependency tree, catching
  authority usage that syntactic analysis misses — macro-expanded FFI
  calls try_call!, trait dispatch, and generic instantiation.

  Architecture:
  - New `crates/capsec-deep/` crate (excluded from workspace, requires nightly)
  - `capsec-driver` binary implements `rustc_driver::Callbacks::after_analysis`
  - Walks MIR BasicBlocks → TerminatorKind::Call → extracts DefId targets
  - Classifies calls against authority patterns via def_path_str
  - Detects FFI calls via tcx.is_foreign_item — sees through macro wrappers
  - Filters std/core/alloc and proc-macro crates to reduce noise
  - Uses RUSTC_WRAPPER to analyze all crates including transitive dependencies
  - Communicates findings via JSONL temp file ($CAPSEC_DEEP_OUTPUT)
  - CLI reads JSONL, patches crate names/versions to match Cargo metadata,
    deduplicates against syntactic findings, merges into unified output

  Tested on heartwood: 613 → 837 findings, 12 → 26 crates analyzed.
  New findings include std::net socket config calls, std::fs::OpenOptions,
  std::env::temp_dir, and FFI calls resolved through macros that the
  syntactic scanner could not see.
@bordumb bordumb self-assigned this Mar 24, 2026
@github-actions
Copy link
Copy Markdown

Auths Commit Verification

Commit Status Details
5a80709b ✅ Verified Signed by z6MktnihicwetvA16FtHFynaJTn9eDZw51eizUEA1yGJCR4o@auths.local

Result: ✅ 1/1 commits verified

@github-actions
Copy link
Copy Markdown

Auths Commit Verification

Commit Status Details
a7566f23 ✅ Verified Signed by z6MktnihicwetvA16FtHFynaJTn9eDZw51eizUEA1yGJCR4o@auths.local
5a80709b ✅ Verified Signed by z6MktnihicwetvA16FtHFynaJTn9eDZw51eizUEA1yGJCR4o@auths.local

Result: ✅ 2/2 commits verified

@github-actions
Copy link
Copy Markdown

Auths Commit Verification

Commit Status Details
345bb644 ✅ Verified Signed by z6MktnihicwetvA16FtHFynaJTn9eDZw51eizUEA1yGJCR4o@auths.local
a7566f23 ✅ Verified Signed by z6MktnihicwetvA16FtHFynaJTn9eDZw51eizUEA1yGJCR4o@auths.local
5a80709b ✅ Verified Signed by z6MktnihicwetvA16FtHFynaJTn9eDZw51eizUEA1yGJCR4o@auths.local

Result: ✅ 3/3 commits verified

@github-actions
Copy link
Copy Markdown

Auths Commit Verification

Commit Status Details
d8cba438 ✅ Verified Signed by z6MktnihicwetvA16FtHFynaJTn9eDZw51eizUEA1yGJCR4o@auths.local
345bb644 ✅ Verified Signed by z6MktnihicwetvA16FtHFynaJTn9eDZw51eizUEA1yGJCR4o@auths.local
a7566f23 ✅ Verified Signed by z6MktnihicwetvA16FtHFynaJTn9eDZw51eizUEA1yGJCR4o@auths.local
5a80709b ✅ Verified Signed by z6MktnihicwetvA16FtHFynaJTn9eDZw51eizUEA1yGJCR4o@auths.local

Result: ✅ 4/4 commits verified

@github-actions
Copy link
Copy Markdown

Auths Commit Verification

Commit Status Details
48c8a8f5 ✅ Verified Signed by z6MktnihicwetvA16FtHFynaJTn9eDZw51eizUEA1yGJCR4o@auths.local
d8cba438 ✅ Verified Signed by z6MktnihicwetvA16FtHFynaJTn9eDZw51eizUEA1yGJCR4o@auths.local
345bb644 ✅ Verified Signed by z6MktnihicwetvA16FtHFynaJTn9eDZw51eizUEA1yGJCR4o@auths.local
a7566f23 ✅ Verified Signed by z6MktnihicwetvA16FtHFynaJTn9eDZw51eizUEA1yGJCR4o@auths.local
5a80709b ✅ Verified Signed by z6MktnihicwetvA16FtHFynaJTn9eDZw51eizUEA1yGJCR4o@auths.local

Result: ✅ 5/5 commits verified

@github-actions
Copy link
Copy Markdown

Auths Commit Verification

Commit Status Details
4f8c56d1 ✅ Verified Signed by z6MktnihicwetvA16FtHFynaJTn9eDZw51eizUEA1yGJCR4o@auths.local
48c8a8f5 ✅ Verified Signed by z6MktnihicwetvA16FtHFynaJTn9eDZw51eizUEA1yGJCR4o@auths.local
d8cba438 ✅ Verified Signed by z6MktnihicwetvA16FtHFynaJTn9eDZw51eizUEA1yGJCR4o@auths.local
345bb644 ✅ Verified Signed by z6MktnihicwetvA16FtHFynaJTn9eDZw51eizUEA1yGJCR4o@auths.local
a7566f23 ✅ Verified Signed by z6MktnihicwetvA16FtHFynaJTn9eDZw51eizUEA1yGJCR4o@auths.local
5a80709b ✅ Verified Signed by z6MktnihicwetvA16FtHFynaJTn9eDZw51eizUEA1yGJCR4o@auths.local

Result: ✅ 6/6 commits verified

@bordumb bordumb merged commit 1d638b6 into main Mar 24, 2026
8 checks passed
@bordumb bordumb deleted the dev-mirDepthCheck branch March 24, 2026 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants