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 .msl region-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 warning alignment.private_memory_not_comparable with 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.

Left, two dumps whose heap block A sits at offset 0x10 in dump 0 and at 0x50 in dump 1, so a same-offset comparison pits block A against an unrelated block B. Right, block A matched by signature in three dumps and stacked into a matrix whose columns are byte offsets within the block; constant columns are invariant and the columns that vary per run are key candidates.

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”:

  1. Parse the allocator in every dump: find its blocks (Scudo chunks, Windows heap blocks, Go heap slots), their user bytes and their addresses.

  2. 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.

  3. 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:

heap_policy

effect on the candidates

off

heap roles ignored, and the heap analysis is skipped

annotate

each region carries its heap roles; the set and the scores are unchanged

mask

allocator metadata (chunk headers, free links, allocator metadata, top chunk) is removed; needs a usable heap map

user_data

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 (default_floor_for_n)

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).

Decision diagram. An explicitly named method (positional, windows_heap, go_heap or scudo) is used as named. Under auto, any positional-only option gives positional. Fewer than two dumps or a first dump that is not a native .msl gives positional. A first dump from a Windows process leads to windows_heap if every dump is a Windows .msl whose segment or NT heap parses with at least one allocated block, else positional. Otherwise, a first dump with a validated Go heap leads to go_heap if its runtime metadata is readable and every other dump is a native .msl of the same OS with a Go arena mapping, else positional. Otherwise, a first dump that names a writable anon:scudo:primary mapping leads to scudo if its heap is detected as Scudo and every other dump is a readable .msl of the same OS naming such a mapping, else positional. Every other path gives positional. A note says encrypted dumps never pick a heap method, only the first dump is Go-parsed and Scudo-detected, and a Go cohort that also names Scudo mappings stays go_heap with a reason pointing to --method scudo.

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_source explicit).

  • A positional-only option forces positional. Under auto, any option only a positional consensus honours selects positional: an N-sweep, an explicit escalation, a region filter, any reduce knob (heap_policy included), or a plugin request (emit set to true or, on REST, to a parameters object, or a plugin knob off its default; emit: false declines the plugin like leaving it unset and never steers the choice).

  • Otherwise the dumps decide, in this order:

    • windows_heap when every dump is a Windows .msl whose segment / NT heap parses with at least one allocated block. A Windows first dump that fails this gives positional.

    • go_heap when the first dump has a validated Go heap and readable Go runtime metadata, and every other dump is a native .msl of the same OS with a Go arena mapping. A first dump with a Go heap that fails the rest gives positional, never scudo. When every dump also names a Scudo primary mapping (a Go process on Android), the reason adds (also a Scudo heap; --method scudo pairs Scudo chunks).

    • scudo when every dump is a readable (plaintext or decrypted) .msl of 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, so auto never picks a scudo run that then refuses with scudo.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_heap run refuse with goheap.wrong_allocator. An encrypted .msl cohort is probed decrypted when the run gets its key material (--key-file, --passphrase or --kem-key-file on pipeline run and pipeline suggest-method; key_file / passphrase / kem_key_file in 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 gives positional with the reason code method.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 scudo under auto. Releases before this one never picked scudo, so such a cohort ran the positional reduction; --method positional (REST / MCP method: "positional") still runs it that way. scudo is a --method choice on every surface (CLI and MCP pipeline run, REST / web method: "scudo" or a scudo parameter object), and MCP also has the stand-alone tool search_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 (emit)

on by default

off by default; an explicit request is refused (scudo.plugin_unsupported, winheap.plugin_unsupported, goheap.plugin_unsupported)

escalation (escalate)

on by default

off by default; an explicit request is refused (<prefix>.unsupported_option)

N-sweep, region filter, reduce knobs (incl. heap_policy)

available

refused (<prefix>.unsupported_option)

pipeline consensus stage

runs

skipped: the pairing happens inside search_reduce

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

scudo

windows_heap

go_heap

allocator parsed

Android Scudo primary chunks (AOSP android-17.0.0_r1 64-bit size-class table)

Windows segment heap and NT heap (LFH included)

Go runtime heap: spans and slots, without symbols

primary pairing

signature scudo:c<class>:o<origin>:s<size> from the chunk header

signature win:<heap kind>:<heap role>:<component>:<bucket>:s<user length>

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 go:sc<spanclass>:s<size>

free blocks

not compared (allocated primary chunks only; secondary allocations not scanned)

not compared (allocated blocks only; undecodable heap areas are reported as opaque)

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 auto

yes (readable Scudo .msl cohort, reference detected as Scudo)

yes

yes (needs readable runtime metadata)

measured

no real-data result recorded yet

Windows ssh.exe dumps (Windows 11 ARM64 segment heap, Windows 10 x64 NT heap): every proven session key kept and found by brute force

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 offset is an offset in the reference dump’s flat vas view (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_judged count in candidates.json instead.

Reference

Entry points per method (library = memdiver.services):

method

library

CLI

MCP

REST / web

choose

suggest_pipeline_method(dump_paths)

memdiver pipeline suggest-method DUMP...

suggest_pipeline_method

POST /api/pipeline/method-suggestion

whole run

pipeline_run(..., method=...)

memdiver pipeline run --method {auto,positional,windows_heap,go_heap,scudo} (--heap-allocator for Windows)

pipeline_run(method=...)

POST /api/pipeline/run with method or a scudo / windows_heap / go_heap parameter object

scudo reduce

search_reduce_android

consensus-begin --allocator scudo (or auto without --size, when the dumps fit Scudo), consensus-add, search-reduce --state S --reference-dump R -o OUT

search_reduce_scudo

POST /api/pipeline/run (method: "scudo"), web method Android Scudo (cold boots)

windows_heap reduce

search_reduce_windows_heap

consensus-begin --allocator windows_heap, consensus-add, search-reduce

search_reduce_windows_heap

POST /api/pipeline/run (windows_heap: {allocator})

go_heap reduce

search_reduce_go_heap

consensus-begin --allocator go_heap, consensus-add, search-reduce

search_reduce_go_heap

POST /api/pipeline/run (go_heap: {allocator})

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

  1. Block consensus engine: the shared pairing, the reduced heap consensus matrix, the verdicts and the hand-off to brute force.

  2. Windows heaps: segment heap and NT heap blocks across processes.

  3. Android Scudo: Scudo chunks across cold boots.

  4. Go heap: span pairing, runtime metadata and the in-slot reduce.