Heap-aware reduction
MemDiver finds keys by comparing N memory dumps of the same program: bytes
that hold a fresh secret change from run to run, almost everything else does
not. That comparison needs to know which byte in one dump corresponds to which
byte in another. For code and static data the answer is “the same offset”. For
the heap, where most keys live, it is not: separately started processes and
cold-booted devices place their heap objects at different addresses. This
section explains how MemDiver reduces heap memory anyway, first by labelling
heap bytes inside the ordinary positional comparison, then, for cohorts whose
heaps cannot line up at all, by pairing whole heap blocks across the dumps and
comparing those (the heap methods scudo, windows_heap and go_heap).
Why positional consensus breaks on heaps
The default reduction is a positional consensus. The N dumps are lined up
so that “byte i” means the same place in each dump: by module and offset for
native .msl dumps, by virtual address, by module-relative keys, or by raw
file offset as a fallback. The per-byte population variance across the N
dumps then separates constant bytes (variance 0) from bytes that change a
little (counters, pointers) and from bytes that look like fresh random data
(the variance of a uniformly random byte is 5461.25). The high-variance,
high-entropy, key-sized runs are the candidates. The consensus itself is
described in the consensus integration
and auto-floor guides.
That works for module images, .data, .bss and other memory that sits at
the same place in every run. It fails for the heap in one of two ways:
The heap is dropped. A virtual-address or module-relative alignment keeps only pages every dump has in common (the
.mslregion-key alignment likewise keeps only private regions whose type, size and ordinal match). Heaps of separately started processes rarely share addresses, so their bytes fall out of the comparison. MemDiver reports this as the warningalignment.private_memory_not_comparablewith the dropped byte counts per dump (silent when every dump’s heap was compared; otherwise it fires when some dump lost all its captured heap, or when the dropped private bytes reach 5 % of all captured bytes).The heap lines up by accident. Where heap pages do line up (a raw file-offset fallback, or a heap region whose type, size and ordinal match in every dump), the allocator still placed different objects there. The same offset then compares a key object in one dump with an unrelated object in another: unrelated bytes look like per-run randomness, and a real key may be compared against noise.
Positional comparison versus block consensus: comparing the same offset pits unrelated heap objects against each other, while pairing the block itself lines up its bytes.
The idea: compare like with like
Heap-aware reduction replaces “same offset” with “same object”:
Parse the allocator in every dump: find its blocks (Scudo chunks, Windows heap blocks, Go heap slots), their user bytes and their addresses.
Pair blocks across the dumps by what they are, not where they are: an allocator signature (size class, requested size, heap component, …) and, where one signature occurs several times, the block content with pointers masked out.
Build a per-block matrix: the N copies of each paired block form N rows of equal length; laid end to end they give a synthetic N × L byte matrix whose per-column variance is meaningful again. Each block of one reference dump (in a pipeline run the first dump; brute force later reads its bytes) then gets a verdict, and the blocks that can hold a per-run value become the candidates.
The shared engine behind step 2 and 3 is described in Block consensus engine.
Two families in MemDiver
Heap roles inside a positional run (heap_policy)
The first family keeps the positional comparison and adds allocator knowledge to it. The reference dump’s heap is parsed, every consensus byte gets a heap role (chunk header, user data, free-list link, allocator metadata, …), and the reduction can use it:
|
effect on the candidates |
|---|---|
|
heap roles ignored, and the heap analysis is skipped |
|
each region carries its heap roles; the set and the scores are unchanged |
|
allocator metadata (chunk headers, free links, allocator metadata, top chunk) is removed; needs a usable heap map |
|
only chunk user data (live or freed payload, and bytes whose role differs between dumps) is kept; needs an allocator whose user-data roles were validated: ptmalloc2, golang, cpython, segment_heap or nt_heap |
A pipeline run that sets no heap_policy picks user_data when the variance
floor resolves to 0 and the reference’s allocator is one of those five, and
annotate otherwise. When an automatic user_data run proves fewer keys than
expected, brute force runs once more over the candidates the filter removed
(the heap fallback). The floor resolves to 0 by default for N ≤ 5, because
the default variance floor scales with the number of dumps:
N (dumps) |
≤ 5 |
10 |
20 |
30 |
40 |
≥ 50 |
|---|---|---|---|---|---|---|
default floor ( |
0 |
500 |
1500 |
2000 |
2000 |
2500 |
Values in between are interpolated linearly (N = 15 gives 1000, N = 45 gives
2250). The same table is the floor the go_heap method applies inside its
kept slots. Details: Heap policy in a pipeline run.
This family narrows the candidates but still relies on positional correspondence: it helps when the heap lines up (for example one long-lived process dumped N times), not when it does not.
Heap methods (scudo, windows_heap, go_heap)
The second family leaves the positional frame. A heap method builds no
positional consensus at all: it parses the allocator in every dump, pairs
blocks across the dumps, gives every block of the reference dump one verdict
and writes the kept blocks as candidates in the reference dump’s own byte
view. These are the methods for cohorts whose heaps cannot line up: Android
cold boots (scudo), separately started Windows processes (windows_heap)
and separately started Go processes (go_heap). A heap method has no
heap_policy; it works on allocator blocks from the start.
Choosing a method
A pipeline run names its method or leaves it on auto, the default on every
surface. The figure shows how auto decides (app.pipeline_method).
How a pipeline run resolves --method auto: the first question that decides wins, and every other path ends in positional.
An explicit method always wins (
method_sourceexplicit).A positional-only option forces
positional. Underauto, any option only a positional consensus honours selectspositional: an N-sweep, an explicit escalation, a region filter, any reduce knob (heap_policyincluded), or a plugin request (emitset to true or, on REST, to a parameters object, or a plugin knob off its default;emit: falsedeclines the plugin like leaving it unset and never steers the choice).Otherwise the dumps decide, in this order:
windows_heapwhen every dump is a Windows.mslwhose segment / NT heap parses with at least one allocated block. A Windows first dump that fails this givespositional.go_heapwhen the first dump has a validated Go heap and readable Go runtime metadata, and every other dump is a native.mslof the same OS with a Go arena mapping. A first dump with a Go heap that fails the rest givespositional, neverscudo. When every dump also names a Scudo primary mapping (a Go process on Android), the reason adds (also a Scudo heap;--method scudopairs Scudo chunks).scudowhen every dump is a readable (plaintext or decrypted).mslof the same OS that names a writable[anon:scudo:primary*]mapping, and the first dump’s heap is detected as Scudo by allocator detection: the same check the Scudo method itself applies, soautonever picks ascudorun that then refuses withscudo.wrong_allocator.everything else is
positional.
Only the first dump is fully Go-parsed (about 0.5 s per gocryptfs dump, per the code’s probe-cost note) and allocator-detected; the others are checked for a Go arena or Scudo mapping name only, and a later dump without a Go heap makes the
go_heaprun refuse withgoheap.wrong_allocator. An encrypted.mslcohort is probed decrypted when the run gets its key material (--key-file,--passphraseor--kem-key-fileonpipeline runandpipeline suggest-method;key_file/passphrase/kem_key_filein the library, MCP and REST; the key-material panel of the web pipeline form), and the same key material opens every dump in every stage of the run. Without it an encrypted first dump givespositionalwith the reason codemethod.encrypted, which names the key inputs and the explicit method as the two ways out. A keyed probe is never cached.An Android Scudo cohort runs
scudounderauto. Releases before this one never pickedscudo, so such a cohort ran the positional reduction;--method positional(REST / MCPmethod: "positional") still runs it that way.scudois a--methodchoice on every surface (CLI and MCPpipeline run, REST / webmethod: "scudo"or ascudoparameter object), and MCP also has the stand-alone toolsearch_reduce_scudo.
Every run records the outcome as method_effective, method_source
(explicit or auto) and method_reason (an English sentence;
method_reason_code, for example method.no_heap_fits, and
method_reason_params give the same reason in structured form); a heap-method run, and a CLI heap
collect session, also write them at the top level of candidates.json (see
What candidates.json holds).
To see the choice without running
anything, ask for a suggestion: CLI memdiver pipeline suggest-method DUMP...,
MCP suggest_pipeline_method, REST POST /api/pipeline/method-suggestion; the
web pipeline shows it as information.
The CLI collect session can leave the choice to search-reduce as well:
consensus-begin --allocator auto without --size begins a heap-auto
session, consensus-add records each dump, and search-reduce --state S --reference-dump R then applies the same detection to the collected dumps,
with R as the first dump (detect_heap_method). It prints
memdiver: heap method <method> (auto): <reason> on stderr and reduces the
session as that method’s session. This detection reads no key material, so
for an encrypted cohort, a reference with no heap method, or a Scudo cohort
whose dumps do not all name the primary mapping, search-reduce falls back to
the Scudo session, which detects the allocator on the reference opened with
its own --key-file / --passphrase / --kem-key-file and also finds a
primary through anonymous mappings. When no heap method fits after that it
refuses with consensus.no_heap_method (begin again with --size for a positional
session, or force one with --allocator scudo, windows_heap or go_heap).
brute-force --state on a heap-auto session is refused with
consensus.heap_auto_plugin_unsupported. A state file written before this
session kind existed (allocator: auto without a method field) is still the
Scudo session it was. REST and MCP have no collect sessions.
What a heap method refuses, and why
A heap method has no positional consensus, so everything built on one does not apply:
option |
positional |
heap methods |
|---|---|---|
Volatility 3 plugin ( |
on by default |
off by default; an explicit request is refused ( |
escalation ( |
on by default |
off by default; an explicit request is refused ( |
N-sweep, region filter, reduce knobs (incl. |
available |
refused ( |
pipeline |
runs |
skipped: the pairing happens inside |
The plugin is built from the per-byte variance around a hit along the
reference’s address space, and escalation and the N-sweep re-run a positional
reduce; a heap method’s variance lives only in its synthetic slab of paired
blocks. The refusal is shared by the library, CLI, MCP and REST
(app.heap_block_options), so every surface answers with the same code.
The three heap methods compared
|
|
|
|
|---|---|---|---|
allocator parsed |
Android Scudo primary chunks (AOSP |
Windows segment heap and NT heap (LFH included) |
Go runtime heap: spans and slots, without symbols |
primary pairing |
signature |
signature |
whole spans (geometry, slot-state pattern, word shapes), then anchor labels from runtime metadata |
duplicates |
pointer-masked content |
pointer-masked content |
left-over slots go through the shared block engine with signature |
free blocks |
not compared (allocated primary chunks only; secondary allocations not scanned) |
not compared (allocated blocks only; undecodable heap areas are reported as |
compared: live and freed slots |
what is emitted |
each kept chunk whole |
each kept block whole |
sub-slot regions: the positional reduce gates (N-scaled floor, entropy, alignment, minimum region) run inside the kept slots; ranked reachable-live, other live, freed |
picked by |
yes (readable Scudo |
yes |
yes (needs readable runtime metadata) |
measured |
no real-data result recorded yet |
Windows |
gocryptfs (Go 1.22.1), N = 3, 5, 10, 20: the reference’s own master key verified in 18/18 pipeline runs |
The measurements are the ones recorded in the heap guide and the Go heap section; the method pages give the details.
Where the result goes next
Every heap method writes the same candidates.json contract the positional
search-reduce writes, so brute force reads it unchanged:
Coordinates. A region’s
offsetis an offset in the reference dump’s flatvasview (its captured memory, densely concatenated; see coordinate spaces), not in a consensus slab. Each offset is verified by reading the reference bytes back before it is written.Reference dump. A pipeline run uses its first dump as the reference; the CLI and library take it as
--reference-dump/reference_path, and it must be one of the compared dumps. Brute force then reads that dump (memdiver brute-force --candidates ... --dump <reference>), at stride 1 by default, with no consensus state, so hits carry no neighbourhood variance.Oracles. Before the sweep the oracle passes a self-test (8 random negatives plus determinism probes). Memory-proof oracles (
derived-state,packet-residue) are bound to the bytes of the same reference dump, so they prove a key from the memory it was found in. See the oracle interface.No escalation. If brute force finds nothing, there is no floor to lower: the verdicts are not variance thresholds. Check the funnel and the
not_judgedcount incandidates.jsoninstead.
Reference
Entry points per method (library = memdiver.services):
method |
library |
CLI |
MCP |
REST / web |
|---|---|---|---|---|
choose |
|
|
|
|
whole run |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The reduce functions share one signature shape (dump_paths,
reference_path, output_dir, key_sizes, key-material arguments,
allocator, mixed_ok, progress hooks, force_memory) and one return shape.
key_sizes only sizes the reported window estimate; it never filters a
region. A REST run that names two methods is refused with
pipeline.method_conflict.
Reading order
Block consensus engine: the shared pairing, the reduced heap consensus matrix, the verdicts and the hand-off to brute force.
Windows heaps: segment heap and NT heap blocks across processes.
Android Scudo: Scudo chunks across cold boots.
Go heap: span pairing, runtime metadata and the in-slot reduce.
- Block consensus engine
- Inputs
- Step 1: pair by signature (
align_blocks) - Step 2: pair duplicates by masked content (
content_align) - Step 3: the reduced heap consensus matrix (
assemble_vector) - Step 4: one verdict per reference block (
classify_blocks) - Step 5: back to the reference dump (
translate_regions) - What
candidates.jsonholds - Worked example
- Pseudo-code
- Limits and pitfalls
- Source map
- Windows heap (
windows_heap) - Android Scudo (scudo)
- Go heap (go_heap)
- 1. Why Go heaps defeat positional consensus
- 2. Go heap primer (what MemDiver needs)
- 3. Parsing the Go heap without symbols
- 4. The Go metadata approach
- 5. Building the reduced heap consensus matrix
- 6. Worked example (synthetic, from the tests)
- 7. Using it
- 8. Measured results and where each number comes from
- 9. Limits and open issues
- 10. Source map