cargo mimir and cargo heimdall from zero
This guide takes a Rust program from source to a seccomp filter it runs under. It uses two cargo front-ends:
cargo mimir(nornir'snornir-mimir-bin) builds the program once and writes its code graph: the Rust half from the compiler, the C half from the C compiler, and the binary graph of every ELF the build linked. With a scope it also runs Mímir's executor, which writes the program's possible set: every system call the graph can reach.cargo heimdall(Heimdall'snordisk-heimdall-cli) measures the program, writes its measured profile, joins the two into a union filter, and runs the program under that filter.
A measured profile alone kills the program on a path the tests never ran. A possible set alone has no arguments and no evidence from a run. The union allows both: what was measured keeps its argument rules, and what only the graph knows is allowed by name.
The worked example is examples/union-cc: a Rust program with C compiled by the cc crate in build.rs. Its e2e.sh runs every step below and is the end-to-end test of the whole chain (branch CI: --extra heimdall-e2e in Heimdall, --extra mimir-e2e in nornir).
1. Get the tools
The tool image (nothing else installed)
Heimdall's ci/tools.Containerfile holds everything: the pinned nightly (nightly-2026-10-05, with rustc-dev, llvm-tools and rust-src), the stable toolchain, LLVM 23.1.5's clang, cargo-mimir, cargo-mimir-dump and mimir-driver, mimir-exec, c-mimir-dump and its four wrappers, heimdall and cargo-heimdall, the x86_64-unknown-linux-musl target and python3. Build it from a nornir checkout and this repo:
ci/tools-image.sh <nornir checkout> <nornir commit> <heimdall commit> [tag]
It needs the LLVM 23.1.5 image (LLVM_IMAGE in the Containerfile) in the same podman store, and prints the image ID and the digest to pin. Then, in your crate:
podman run --rm -it --userns=keep-id -v "$PWD:/work" -w /work <image> cargo mimir doctor
heimdall profile probe and enforce install seccomp filters in the container; rootless podman's default seccomp profile allows that.
On a host
rustup toolchain install nightly-2026-10-05 --profile minimal --component rustc-dev,llvm-tools-preview,rust-src
cargo +nightly-2026-10-05 install --locked cargo-mimir-dump # cargo-mimir-dump and mimir-driver
cargo install --locked nornir-mimir-exec # mimir-exec
cargo install --locked nornir-mimir-bin --features cli # cargo-mimir
cargo install --locked nordisk-heimdall-cli # heimdall, cargo-heimdall
The C half (--with-c) needs c-mimir-dump built on LLVM 23.1.5 and that LLVM's clang; the tool image is the supported way to get them.
Released versions lag main: cargo mimir make --with-c and cargo mimir doctor are in nornir-mimir-bin after 0.4.0, and heimdall profile enforce and --job in nordisk-heimdall-cli after 0.6.2. Until those are on crates.io, the tool image built from the mains has them.
Check the host: cargo mimir doctor
cargo mimir doctor checks every piece cargo mimir make runs and names a fix for each fault. It installs nothing. In the tool image:
ok cargo-mimir-dump /usr/local/bin/cargo-mimir-dump
ok nightly nightly-2026-10-05: rustc 1.101.0-nightly (282215592 2026-10-04)
ok components rustc-dev, llvm-tools, rust-src
ok mimir-driver /usr/local/bin/mimir-driver starts on nightly-2026-10-05 (rustc 282215592)
ok mimir-exec /usr/local/bin/mimir-exec
ok c-mimir-dump /usr/local/bin/c-mimir-dump (LLVM 23.1.5)
ok c-mimir wrappers c-mimir-cc, -cxx, -ar, -ld in /usr/local/bin
ok clang /opt/llvm/bin/clang is clang 23.1.5
ok build env no CC/CXX/AR override past the capture
cargo mimir make: ready; --root/--cut: ready; --with-c: ready
A fault looks like this, with its fix on the next line:
FAIL mimir-exec mimir-exec is not on PATH (nor beside cargo-mimir-dump)
fix: cargo install --locked nornir-mimir-exec
The last line says which uses are ready: plain make, make --root/--cut (the executor), and make --with-c. The exit is 1 when any check fails.
2. The worked example, step by step
union-cc has two paths:
union-cc ccalls the C functionunion_cc_parent(c/parent.c,getppid) and prints the parent's PID. The probe corpus runs this path.union-cc rare <dir>makes a directory and removes it (mkdir,rmdir). No test runs it, so only the graph knows it.
2.1 Build once, graph everything: cargo mimir make
cargo mimir make --with-c --out out/make --root 'union-cc[bin=union_cc]@0.1.0::main'
One cargo build runs under cargo-mimir-dump (the Rust dump: MIR, symbols, linker lines) with CC/CXX/AR set to c-mimir-dump's wrappers (the C capture). Then:
| out/make/ | what |
source/ |
the Rust dump of every crate the build compiled |
link/ |
the linker line of every program |
c-capture/, c-source/ |
the captured C units, and the C half read from them |
graph/union-cc/ |
the binary graph of the ELF, with the Rust and C source merged in |
exec-dump/, std/ |
the executor's dump of the program and of the toolchain's crates |
exec/union_cc.possible.json |
the possible set (mimir.possible-syscalls/1) |
target/ |
cargo's target dir; the program is target/debug/union-cc |
receipt.json |
what ran, with every file's sha256: c_half, c_capture, exec, programs |
--root and --cut scope the executor: the reach starts at the instances a root names and never enters what a cut names. A name is Mímir's instance key without generic arguments: <package>[bin=<crate>]@<version>::<path>. A name no instance has is refused, and the executor names the program's phases, so the first run shows the right key.
The possible set's file is named by the crate name (union_cc, _ for -). Look at a function of the graph:
$ cargo mimir show out/make/graph/union-cc --function union_cc_parent
union_cc_parent @ 0x19bf0
0x19bf0..0x19bf9 call successors=[19bf9] calls=[561f0] imports=[]
0x19bf9..0x19bfd ret successors=[] calls=[] imports=[]
In graph/union-cc/report.json the function carries its C source: source_file parent.c, line 5, a c union-cc@0.1.0#… - union_cc_parent moniker.
2.2 Measure: cargo heimdall profile probe and gen
The workload is profiles/union-cc/workload.toml:
workload = "union-cc"
timeout_secs = 60
repeat = 1
[binary]
glibc = "{target}/debug/union-cc" # {target} = $CARGO_TARGET_DIR, else target
[[run]]
name = "rust_and_c"
args = ["c"]
expect_exit = 0
CARGO_TARGET_DIR=out/make/target cargo heimdall profile probe union-cc --libc glibc
cargo heimdall profile gen union-cc --libc glibc
probe runs every [[run]] in learning mode (seccomp USER_NOTIF: log and allow) and writes profiles/union-cc/x86_64-glibc.probe.json. gen writes x86_64-glibc.rs, .json and .oci.json: the measured profile. It has getppid (the C call ran) and neither mkdir nor rmdir (no run took the rare path). A person reviews the diff before it is committed.
2.3 Join: heimdall profile union
heimdall profile union --measured profiles/union-cc/x86_64-glibc.json \
--possible out/make/exec/union_cc.possible.json --out out/union
union: 38 rule(s) = 28 measured + 10 from the possible set of union_cc (18 call(s)); 0 unknown name(s) left out -> out/union/x86_64-glibc.{rs,json,oci.json}
A measured rule stays as it is. A call only the possible set has (mkdir, rmdir, …) is allowed with any arguments and listed under review.bare. A name the arch does not know is never allowed (review.unknown).
cargo heimdall union does graph src, profile gen and profile union in one command, from heimdall graph src instead of cargo mimir make:
cargo heimdall union union-cc --bin union-cc --libc glibc --graph out/g --out out/union
2.4 Run under the filter: heimdall profile enforce
heimdall profile enforce --profile out/union/x86_64-glibc.json -- out/make/target/debug/union-cc c
heimdall profile enforce --profile out/union/x86_64-glibc.json -- out/make/target/debug/union-cc rare /tmp/d
Both paths run. The exit is the program's own; a signal ends it with 128 + the signal. The negative control is the measured profile alone on the rare path:
$ heimdall profile enforce --profile profiles/union-cc/x86_64-glibc.json -- out/make/target/debug/union-cc rare /tmp/d2
heimdall profile enforce: out/make/target/debug/union-cc: killed by seccomp: <name> (<nr>, x86_64): it made a call profiles/union-cc/x86_64-glibc.json does not allow
$ echo $?
159
That is the reason for the union: the path no test ran dies under the measured profile and runs under the union.
2.5 Every step at once
examples/union-cc/e2e.sh [out dir]
It checks every link by name (the C half captured and merged, the possible set has mkdir and rmdir, the measured profile has getppid and not mkdir, the union has all three, both paths run under the union, the negative control dies with 159) and ends e2e GREEN, or e2e RED: <the check that failed> with exit 1.
2.6 The graph alone, no base and nothing measured: heimdall graph filter
heimdall graph filter --make out/make --bin graph-pure --libc glibc --out out/filter
heimdall profile enforce --profile out/filter/x86_64-glibc.json -- out/make/target/debug/graph-pure /tmp/d
The filter is the calls of the graph (the exec graph's possible set with the calls of its binary half) and restart_syscall, nothing else. The kernel issues restart_syscall itself; no call site makes it. There is no base set: exit, exit_group and rt_sigreturn are allowed only when the graph names a call site of them. The profile records this as review.implied = "kernel-issued", and enforce (also --function) builds the filter with that implied set.
Graph mode refuses (exit 1) and lists every open item:
- an open call site: an indirect call no rule bounds, a C function without a map entry, a call the arch does not know; each may make any call;
- a gap in the graph tools (never a rule): neither
exitnorexit_grouphas a call site in the graph (nothing could end the process), or the graph hasrt_sigaction(it can install a signal handler) and nort_sigreturn(the handler could not return). A graph withoutrt_sigactionneeds nort_sigreturn, and does not get it.
--allow-open writes the profile anyway, with the list in review.open and the first note NOT-ENFORCEABLE: an experiment, never a filter to ship.
A measured profile only checks the graph:
heimdall graph check --graph out/make --program graph-pure --measured profiles/graph-pure/x86_64-glibc.json
A measured call that the graph does not name is printed as BUG <call> … and the check exits 1: a call site the graph tools missed. It is never added to a filter.
examples/graph-pure/e2e.sh runs make, filter (no --allow-open) and enforce on a std-only program (threads, a unix socket, a file): 0 open items, and the program runs.
3. One filter per job type: --job
A program that runs several kinds of jobs needs a filter per job: a scan job must not get the calls of an app-graph job. A [[job]] in workload.toml names one job type: its entry in the graph (root), what it never enters (cut), and the corpus runs that drive it (runs, matched like --only, by substring of the run name). The worked case is Holger's scan worker: one program, holger-scan-worker, that runs a scan job, a verify-bundle job and an app-graph job (job_runner::programs::run dispatches them). Its result is checked in: profiles/holger-scan-worker/ (PROPOSED), one filter per job, with these rows in its workload.toml:
[[job]]
name = "scan"
root = ["holger-server-lib@3.7.0::sandbox::worker::run", "holger-server-lib@3.7.0::sandbox::scan_program"]
cut = [
"holger-scan-worker[bin=holger_scan_worker]@3.7.0::serve",
"holger-scan-worker[bin=holger_scan_worker]@3.7.0::probe",
"holger-scan-worker[bin=holger_scan_worker]@3.7.0::probe_job",
"holger-sandbox@6.0.2::remote",
]
runs = ["-scan-"]
[[job]]
name = "app-graph"
root = ["holger-server-lib@3.7.0::job_runner::app_graph::run"]
runs = ["app-graph"]
Run from a Holger checkout (siblings beside it, as Holger's own build wants), in the tool image with the musl target:
mkdir -p p/holger-scan-worker
cp <heimdall>/profiles/holger-scan-worker/{workload.toml,x86_64-musl.probe.json} p/holger-scan-worker/
cargo heimdall union holger-scan-worker --profiles p \
--workspace . --bin holger-scan-worker --package holger-scan-worker \
--libc musl --target x86_64-unknown-linux-musl \
--graph g --out u --job scan --job app-graph
--package holger-scan-worker makes both graph passes check that package alone: the rest of Holger's workspace does not check for musl (another member needs openssl-sys). What it printed (2026-11-12, Holger h38 db37e86):
union: 44 rule(s) = 31 measured + 13 from the possible set of holger_scan_worker (39 call(s)); 0 unknown name(s) left out -> u/scan/x86_64-musl.{rs,json,oci.json}
union: 108 rule(s) = 88 measured + 20 from the possible set of holger_scan_worker (70 call(s)); 0 unknown name(s) left out -> u/app-graph/x86_64-musl.{rs,json,oci.json}
The two filters differ where it matters: the app-graph job starts git and cargo and asks the box's crates index, so its filter has execve, fork, socket, connect, chroot and setuid; the scan filter has none of them. The app-graph runs are measured over the whole job tree (a seccomp filter is inherited by git, cargo, rustc and cargo-lens). Under heimdall profile enforce each app-graph run passes under its own filter and dies by SIGSYS under the scan filter. The verify-bundle job (h37 f02d803: 46 = 34 measured + 12, 41 possible calls) runs wasm, so its possible set has getrlimit, pread64 and sched_yield that the scan job's lacks.
profile gen --job writes the job's measured profile from its own runs alone into profiles/<workload>/jobs/<job>/<arch>-<libc>.{rs,json,oci.json}; the probe file stays the workload's. cargo heimdall union --job runs, per job, graph src reached from that job's roots (with its cuts and any --cut given) into <graph>/<job>, profile gen --job, and profile union into <out>/<job>/. The jobs after the first reuse the first job's dump of the toolchain. --root and --job do not go together, an unknown job is refused with the known ones listed, and a job with no matching run is refused (no probe run …).
Root a job at the program's real entry, and cut the sibling jobs. A program with a dispatcher (a CLI with subcommands, a worker that picks a program by name) runs a shared prefix in main before it dispatches: argument parsing, logging, self-checks. Every job makes those calls. A root at the job's own function drops them from the possible set; they are then only measured, with no call site. So write root = ["<program>::main"] and cut = every other job's function. youki is the worked case (profiles/youki/): with create rooted at commands::create::create, memfd_create was measured but had no call site. Rooted at main with the 17 other subcommands cut, the possible set has its two call sites: youki's sealed self-copy against CVE-2019-5736 (pentacle) and journald logging. Holger's scan worker rows above still root at the job functions; its main prefix is in their measured part only.
Per function; a job is just a named function root. A function service (F1) runs ONE function of its starter in a copy of the starter, after the copy's filter is on. Its filter is made the same way as a job's, with the function as the root: cargo heimdall union <w> --bin <starter> … --function '<package>[bin=<bin>]@<version>::serve_entry'. The root is the function and heimdall-container's starter::call (what runs in the copy), never main; nothing of the parent's path before the copy is reached. The measured part comes from heimdall profile probe-exec --function -- <starter> <args>, which records the function alone, and heimdall profile enforce --function runs it under its own filter. One root is one filter: a [[job]] names a root with its runs; --function is a root whose runs are all of its probe file.
4. Every verb
cargo mimir
| verb | does |
make --out <new dir> [--with-c] [--c-tool P] [--root N]… [--cut N]… [--std-dump D] [--dump-tool P] [--target-dir D] [--manifest-path P] [-- <cargo build args>] |
one build, one graph set and a receipt (section 2.1) |
doctor [--dump-tool P] [--c-tool P] |
is this host ready for make (section 1) |
src <workspace> --out <dir> [--bin N]… |
a source graph from the installed driver |
bin <ELF> --out <dir> [--arch …] [--libs D]… [--follow-needed] [--with-source D] [--syscall-table F] |
the binary graph of one ELF, without running it |
show <dir> [--function <name or 0xaddr>] |
function bodies from a graph dir |
stats <dir> |
coverage, counts and unresolved reasons |
cargo heimdall and heimdall
cargo heimdall <verb> … is heimdall <verb> … for profile and graph; it adds check and union.
| verb | does |
profile probe <workload> --libc L [--only S]… [--pairs] |
the corpus in learning mode → <arch>-<libc>.probe.json |
profile gen <workload> --libc L [--job J] |
the measured profile (.rs, .json, .oci.json) |
profile check <workload> --libc L (cargo heimdall check) |
probe again; exit 1 on a call outside the checked-in profile |
profile union --measured F --possible F --out D |
the union filter (section 2.3) |
profile enforce --profile F -- <program> [args] |
run one program under a profile, enforcing (section 2.4) |
profile probe-exec, probe-container, probe-oci, probe-log, merge, sites |
measure a program where it really runs (CLI.md) |
graph src <workspace> --out D [--bin N]… [--root N]… [--cut N]… [--std-dump D] [--tools D] |
Mímir's dumps and executor → <program>.possible.json |
graph make … |
cargo mimir make (same options) |
graph filter --make D --bin P --libc L --out D [--workload W] [--allow-open] |
the filter from the graph alone (section 2.6); refused while an item is open |
graph check --graph D --program P --measured F |
a measured call with no call site in the graph is a BUG (section 2.6) |
graph stats D, graph check, graph bin, graph show |
CLI.md |
union <workload> --bin B --libc L --graph D --out D [--job J]… [--root N]… [--cut N]… (cargo heimdall) |
graph src + profile gen + profile union in one command |
Exit codes for the profile verbs: 0 done, 1 refused or check failed, 2 usage, 3 host or I/O error. enforce exits with the program's code.
5. What this does not cover
- The C half reaches the binary graph (
graph/<program>/) andcargo mimir show, not the executor: a system call made only from C code is not in the possible set. In union-cc,getppidcomes from the measured profile. A C path no test runs is not covered by the union. - Dynamic loading, JIT and self-modifying code are outside static analysis; the graph keeps unresolved call sites and does not guess.
- A call only the possible set has is allowed with any arguments; only measured calls keep argument rules.
--with-cneeds LLVM 23.1.5 (the tool image); a compiler variable such asCC_x86_64_unknown_linux_gnuthat would take the build's C past the capture is refused.- The e2e test runs on x86_64 glibc. musl is in the tool image; aarch64 is not tested here.