zeroize can't reach everything, so I made my memory-dump test say exactly what it can
In my last post I wrote about Synapse Mind, a local memory for Windows written in Rust, and about Gate 2: a test that starts the real app, feeds it fake secrets, takes full memory dumps of every process involved, and sea
In my last post I wrote about Synapse Mind, a local memory for Windows written in Rust, and about Gate 2: a test that starts the real app, feeds it fake secrets, takes full memory dumps of every process involved, and searches them for those secrets.
A commenter asked a good question: zeroize wipes the buffers you own, but what about the copies you don't own? Windows, UI Automation, WebView2, SQLCipher and ONNX Runtime all keep their own memory. Which of those does the test actually cover?
My honest answer was a hand-written table in SECURITY.md. That is better than nothing, but a hand-written table is only a claim. So I opened issue #1 to turn it into something the test produces itself. Three of its five items are now done. This post is about how, and about what still can't be measured.
Step 1: who owns this byte?
Before this change, Gate 2 knew two things about every match: which process it was in, and what kind of memory it was (private, stack, mapped or image). That was enough for a PASS/VETO decision, but not enough to say whose copy it was.
A Windows minidump already has the missing piece. Besides the memory itself, it contains a module list: base address, size and file name of every loaded DLL. Reading it is a few dozen lines:
- find the
ModuleListStream(type 4) in the stream directory - read each 108-byte
MINIDUMP_MODULEentry: base (u64), size (u32), name RVA - read the name as a
MINIDUMP_STRING(byte length + UTF-16)
Now a match inside a module image can be reported as "inside UIAutomationCore.dll" instead of just "image".
With that, every match gets exactly one owner. The rules are short and ordered:
pub fn attribute(role: Role, region: &str, module: Option<&str>,
secret_id: &str, enc: Enc, part: Part) -> Owner {
if region == "image" {
return Owner::Module(module.unwrap_or("?").to_string());
}
if !is_owned_region(region) {
return Owner::OsShared; // mapped sections such as the desktop heap
}
if secret_id == "db-key" && enc == Enc::Raw && part == Part::Tail {
return Owner::K1RngTail; // the one accepted risk
}
if is_key_secret(secret_id) {
return Owner::KeyMaterial;
}
match role {
Role::UiaWorker => Owner::UiaWorker,
Role::WebView2 => Owner::WebView2,
Role::Other => Owner::OtherProcess,
Role::App if region.starts_with("stack") => Owner::AppStack,
Role::App => Owner::AppHeap,
}
}
One limit I could not get around, and I would rather say it than hide it: a heap byte cannot be traced to the library that allocated it from a dump alone. SQLCipher and ONNX Runtime allocate from the same process heap as my own code. A match there is counted as "app heap", and the table says so. A module name is only exact when the match sits inside that module's image.
Step 2: the table is generated, not written
gate2-app --zeroize-report <file> now writes the zeroize table at the end of the run. Each row counts its findings and says how many dumps it is based on.
One rule mattered more than the others: a row whose processes were never dumped is reported as "not measured", never as clean. Zero findings in zero dumps is not a result. There is a unit test for exactly this case.
The PASS/VETO logic did not change. Attribution is recorded next to it, not instead of it.
Step 3: how long does raw text live in the UI Automation helper?
Recap from the first post: UIAutomationCore.dll copies the text it reads into its own heap and frees it without zeroing. So the app never reads text in its own process. A single-use helper process does the read, sends the result back and is killed. When it dies, its memory goes with it.
That leaves a window: while the helper is alive, the text is in it. The old table said "about 30-45 ms", based on a latency benchmark. Now it is measured on every run.
The measurement starts right before the read request is written to the helper, and stops after the helper process has exited and been reaped. That makes it an upper bound on how long the text can exist there. Only the duration is stored; the text is never touched.
| Live window, release build, 40 reads | p50 | p95 |
|---|---|---|
| Measured at the end of a Gate 2 run | 48 ms | 53 ms |
| Measured on its own, idle system | 35 ms | 40 ms |
The Gate 2 value is higher because it runs right after the app and all its WebView2 processes have been shut down, while the system is still busy. The table uses that value, because it is the more conservative one.
A flaky test, for free
The first Gate 2 run with the new code crashed halfway. Not on a finding, but on this (my Windows is Turkish; "EriΕim engellendi" means "Access denied"):
pano: Custom { kind: Other, error: Error { code: HRESULT(0x80070005), message: "EriΕim engellendi." } }
The harness puts fake secrets on the clipboard, one after another. The app under test listens for clipboard changes and reads each one. Only one process can have the clipboard open at a time, so the harness's next OpenClipboard collided with the app's read of the previous one. It had always been possible; it just had not happened before.
The fix was a short retry loop (up to 2 seconds). The rerun passed.
The result
The final run, on the new build:
- 41 dumps: the app, 5 UIA helpers, 31 WebView2 processes
- 0 raw secrets or keys in process memory owned by the app, helpers or WebView2
- 0 raw secrets in the encrypted database file
- every remaining match in shared OS sections (mostly the desktop heap, which every GUI process sees)
- 0 matches in any module image, including ONNX Runtime
Seven of the ten rows are now backed by dumps. Two are out of scope by design: the Windows clipboard's own copy, and the desktop heap. One is still marked β.
What is still not measured
Two items of the issue are open, and both are research rather than code:
- Pagefile and hibernation file. A minidump only sees user-mode memory. If Windows pages a buffer out before it is wiped, the copy on disk is invisible to this test. I need a way to force memory pressure and then scan the page file, probably on a throwaway VM. Until then, the advice stays the same: use full-disk encryption.
- K1. Sometimes the last 12 bytes of the database key show up in the app's memory, left behind by the Windows random number generator path when the key is created. It is an accepted, documented risk that varies from 0 to 5 matches between runs (0 in this one). I want to find out why, and whether it can be reduced.
If you have done either of these before, especially scanning pagefile.sys for test data, I would love to hear how. The issue is open: https://github.com/0xStoic-bit/Synapse_Mind/issues/1
- Repo: https://github.com/0xStoic-bit/Synapse_Mind
- The generated table: SECURITY.md
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.