Gradual memory-safety hardening for unsafe Rust and mixed-language programs
README.md

Fe-C #

Part of the overby.me monorepo, where this lives in safety/fe-c and where all development happens.

It is also published on its own, as tangled.org/overby.me/fe-c and github.com/overby-me/fe-c. Both are read-only mirrors, rebuilt from the monorepo with josh: a commit made to either is overwritten by the next sync, so please open issues and pull requests on the monorepo.

Gradual memory-safety hardening for unsafe Rust and mixed-language programs.

Fe-C is the iron–carbon alloy system. Pure iron is soft; a controlled amount of carbon, correctly alloyed, gives cast iron and steel. Safe Rust plus a controlled amount of C-heritage unsafe, correctly checked, is stronger than either. The name is also a sideways nod to Fil-C — read Fe-C is not Fil-C before assuming anything about guarantees.

What it does #

Safe Rust is proven at compile time, so Fe-C spends its runtime budget only where the type system abdicates: raw-pointer accesses, raw-to-safe casts, and FFI boundaries are checked against a global allocation table, resolved from where the pointer was derived rather than from the address that faulted, so a report names the root cause instead of a distant dereference.

Working today (each backed by a nix build .#checks.<system>.fe-c-* entry):

  • Raw-pointer dereference and write-intrinsic checks, extent-aware, in both modes.
  • Raw-to-safe cast checks (&*p, &(*p).f) and slice-mint checks (slice::from_raw_parts), including generic element types.
  • Stack scope registration and poisoning, with escape analysis, so a pointer that outlives its frame traps and the report names the escape site.
  • Heap use-after-free, with quarantine, plus a case-mode re-check after possibly-freeing calls.
  • Allocator-family libc interposition (malloc/calloc/realloc/free/ posix_memalign), so buffers allocated by C are tracked too.
  • Nine real CVEs caught in real, unmodified crates, one of them across real C (rusqlite plus bundled SQLite). See STATUS.md.

Designed, not built yet (do not plan around these):

  • The per-crate hardening dial. Mode is currently one build-wide setting, not a per-crate attribute, and cargo-fe-c is a stub.
  • extern "C" inbound prologue checks; mem* and syscall-wrapper interposition tiers; sampled guard-page/canary allocations (GWP-ASan style).
  • Alignment checking, at-rest capabilities, and interprocedural provenance.
  • Any performance number at all. See docs/evaluation-2026-07.md.

Hardening modes #

Mode Metallurgy Checked Assumed
--harden=case Case hardening: hard surface, fast ductile core Raw→safe casts, FFI boundaries, alloc/free, optional re-checks after potential deallocation Rust aliasing + validity rules hold inside elided (type-proven) regions; the optimizer shares those assumptions
--harden=through Through hardening: uniform to the core Every access, via opaque runtime calls the optimizer cannot reason around Only the cementite runtime and syscall stubs (the same shape of trusted base Fil-C's runtime keeps)

fil is a reserved alias for through, to be enabled only once the guarantee is actually earned (precedent: Zig's proposed fil ABI mode).

Modes are designed to be per-crate, recorded in crate metadata and mediated by cross-mode call adapters (PLAN I3). As built, mode is one setting for the whole build (FEC_MODE), and nothing yet records it in metadata or adapts at a seam. Both modes are first-class in behaviour and in the differential gate; the dial is not. See PLAN.md.

Fe-C is not Fil-C #

  • Fil-C is unconditional: garbage in, memory safety out, for arbitrary code; its compiler never optimizes on assumptions the runtime doesn't enforce; the cost is ~1.5–4× everywhere.
  • Fe-C case is conditional: deterministic detection of the bug classes Rust programs actually ship (unsafe/FFI misuse), at near-zero cost for safe code — but an aliasing-UB path can corrupt state without crossing a checked boundary. It is a testing/hardening tool, not a containment boundary for hostile code.
  • Fe-C through aims at the Fil-C-grade guarantee inside Rust's world, staged deliberately (see PLAN.md §5–7). What it delivers today is "checked before every visited access", not Fil-C's "the optimizer never dereferences directly": checks are injected after rustc's MIR pipeline and the access itself is still an ordinary load or store, so LLVM keeps its noalias, dereferenceable and align assumptions. Lowering accesses through the runtime is a v1 question, not a shipped property.
  • No overhead number exists for either mode. The cost claims in this file and in PLAN are hypotheses until fe-c-bench exists.
  • Fe-C does not check Rust's aliasing model in any mode — that is Miri's job; run both.
  • For lifetime-bound bugs (too-relaxed signatures letting borrows outlive their frame), Fe-C detects and contains the consequence; it does not prevent the mistake. Correct signatures, cargo audit, and static analysis do.
  • case mode's free-during-scope detection is single-thread-sound: a concurrent free between re-check and dereference can be missed. through mode has no such window.
  • through mode guarantees memory safety for programs free of data races on pointer slots (already UB in Rust). Fil-C is stronger here: it makes races harmless to memory unconditionally. See docs/through-mode-coherence.md.
  • If you need guaranteed containment today: Fil-C, CHERI hardware, or a wasm boundary.

Architecture #

One Rust workspace. No compiler fork, no LLVM linkage, no submodules.

Crate Role
cargo-fe-c Cargo subcommand + RUSTC_WRAPPER. Stub today: builds are driven by pointing RUSTC at fe-c-driver with FEC_* env vars, from the flake checks. -Zbuild-std was tried and does not currently work (see STATUS)
fe-c-driver rustc-as-a-library (rustc_public where possible); MIR analysis + rewriting of accesses into plain runtime calls; per-crate mode metadata
cementite The hard phase (Fe₃C): allocation table (never-recycled IDs + liveness epochs), check functions, quarantining #[global_allocator], libc interceptors

Toolchain coupling budget: one pinned nightly in rust-toolchain.toml, bumped by an automated pipeline (the Kani maintenance model).

Substrate #

Fe-C pairs with ../libc (vendored Eyra lineage) so that "whole-process" means whole process: the libc's own unsafe is instrumented like everyone else's. The unchecked residue shrinks to syscall stubs and a few lines of asm.

Nix ❄️ #

Everything routes through the flake:

  • nix build .#cargo-fe-c / .#cementite / .#fe-c-driver
  • nix develop — pinned nightly + rustc-dev + rust-src + miri
  • nix build .#checks.x86_64-linux.fe-c-<name> runs one of 27 checks: fmt, clippy, unit, miri, interpose, census, provenance, instrument, the corpus entries with their controls, false-positive, and the differential gate. Run them individually; nix flake check is forbidden repo-wide (it OOMs on this tree).
  • Not built yet: fe-c-sysroot-<mode>-<target> (instrumented core/alloc/ std), and fe-c-bench.

Status #

Working checker, no security claim yet, no performance data.

Monorepo table row:

| [Fe-C 🦀](https://tangled.org/@overby.me/overby.me/tree/main/safety/fe-c) | Gradual memory-safety hardening for unsafe Rust and mixed-language programs |

Prior art #

Fil-C (InvisiCaps, FUGC) · SafeFFI (USENIX Security '26) · Miri · rustc_public · Kani (maintenance model) · CHERI rustc / strict provenance · Eyra · GWP-ASan · Zig #36237