# Secret memory and plaintext exposure [Documentation](README.md) · [Architecture](ARCHITECTURE.md) · [Assurance](ASSURANCE.md) This is a source-oriented inventory for reviewing secret lifetimes. It covers the named buffers and paths below; it is not an exhaustive proof that every possible plaintext copy has been found. Re-check ownership, capacity, and cleanup when modifying an allocation or context switch. ## What locking does `sec_lock_statics` locks all **85** fixed buffers listed in the `.const` `sec_regions` table (`secmem.asm`) at startup, from the GUI entry point `wstart`. `sec_ws_grow` adjusts the working-set reservation first (floored at 80 MiB minimum via `SetProcessWorkingSetSizeEx` hard-min / soft-max flags). A static lock failure is recorded and shown as a warning; startup does not universally fail closed. The `lktest` probe checks that every listed buffer is actually resident-locked (`QueryWorkingSetEx`), not just that the call was made. `secmem_alloc` allocates a page-rounded arena followed by a trailing 4 KiB `PAGE_NOACCESS` guard page, `VirtualLock`-pins the arena, and registers it in the out-of-line 1024-slot `g_secreg` registry serialized by an `SRWLOCK` (`g_secreg_lock`; no header bytes are placed inside or adjacent to the caller's locked pages). It returns failure rather than handing an unlocked arena to the caller. `secmem_free` wipes a registered live allocation and verifies `VirtualFree(MEM_RELEASE)` before clearing its registry slot. After startup initialization completes, `iat_lockdown` seals both the PE import table and the 4 KiB-isolated `_ROINIT` section (`g_stack_canary`, `g_ptr_cookie`, `g_sstk_tls`, `g_cpu_features`, `g_img_lo`, `g_img_hi`) as `PAGE_READONLY`, and `crash_install` configures `WerSetFlags(0x000001E1)` plus `WerAddExcludedApplication` to exclude heap dumps and crash snapshots from Windows Error Reporting. Successful [VirtualLock](https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-virtuallock) keeps the specified pages resident and out of ordinary paging while locked. Do not extend that into a claim that all secrets are excluded from hibernation, system dumps, kernel access, or every scratch allocation. The application does not control all of those paths. In particular, hibernation writes all of RAM - locked pages included - to `hiberfil.sys`; lock Vordr before hibernating, and rely on full-disk encryption for the hibernation file. ## Selected locked buffers Names are in `src/`; the authoritative list is the `sec_regions` table in `secmem.asm`. The same table drives the lock at startup, the wipe when the vault window closes (`secmem_wipe_statics`, called after `vault_lock`), and the panic wipe. The rows below are the main ones; the table also covers the UTF-8 and wide conversion scratch, search input (`g_search_w`), commit blobs, attachment tile (whose AttachRefs carry per-file keys), generator output and word buffer (`g_wordtmp`), export/import password copies and ZIP key material, BLAKE2b and Argon2 initial hash state (`g_b2bctx`, `g_hbuf`), and the TOTP key and formatted code buffers (`g_totp_code6`, `g_totp_code_w`, `g_totp_disp_w`). | Buffer | Module | Contents | Normal cleanup | |---|---|---|---| | `g_cfg_pass` (1025 B) | main | UTF-8 master password | GUI password-attempt cleanup and process exit | | `g_vkey` (32 B) | vault | Active vault key | `vault_lock` | | `g_xs_vkey` (32 B) | vault | Parked key during temporary context operations | Export/password-check context cleanup | | `g_pwbuf`, `g_pw2buf` (2048 B each) | gui | Wide password / PIN and confirmation | Password/PIN conversion and create/unlock cleanup | | `g_pin_u8`, `g_pin2_u8` (256 B each) | vault | UTF-8 `TPM + PIN` enrollment and unlock buffers | `vault_tpm_enroll_pin` / `vk_derive_tpm_pin` and `vault_lock` | | `g_secret_w` (`CONVW_MAX`*2 B) | gui | Revealed/copied secret | Vault close/lock | | `g_rowpw_w` (1024 B) | gui | Reveal overlay | `gui_colorpw_hide` and close/lock | | `g_e_totp` (512 B), `g_totp_b32` (256 B) | gui | TOTP edit/selected key | Vault close/lock | | `g_pwhist` | gui | Field-history records | Entry teardown and vault-window close | | `g_pworig` | gui | Original values for history comparison | Entry teardown and vault-window close | | `g_pwhblob` | gui | Serialized history staging | Entry teardown and vault-window close | | `g_tilefiles`, `g_tileblob`, `g_imgstageref` | gui | Attachment references, each with its file key | Vault-window close | | `g_conv_w`, `g_valblob`, `g_lblblob` | gui | Display and commit scratch: field values and labels | Vault-window close | | `g_conv`, `g_convlabel` | vault | UTF-8 field/label scratch | Vault lock and vault-window close | | Active vault body (`g_body_ptr`) & foreign import body (`g_foreign_body`) | vault via secmem | Decrypted records, including history and attachment references (plus temporary foreign-import bodies) | `secmem_free` (atomic null-before-free on `g_body_ptr`) | | Edit transaction bodies | gui via secmem | Original body and working copy | Success releases original; failure restores original and releases working copy | | Off-screen compositor bitmap (`gui_present_composite`) | gui (ephemeral window-compatible DDB) | Rendered window frame during a single atomic blit (GDI-scaled at native monitor DPI) | Scrubbed immediately after `BitBlt` with `PatBlt(PATBLT_BLACK_)` and destroyed before returning; never retained between frames | History buffer sizes use `MAX_PWHIST`, `PWHIST_ENTRY`, `MAX_PWORIG`, `PWORIG_STRIDE`, and `PWHBLOB_ENTRY`. Keep their allocation, lock, and wipe sizes consistent rather than copying a stale byte count from documentation. The edit transaction also has a history snapshot (`g_edit_history`), wiped on either outcome. The panic path explicitly visits the original edit body and history snapshot as well as the active body and selected fixed buffers. ## Other sensitive memory Not every secret-bearing allocation is managed by `secmem_alloc`. | Area | Exposure and cleanup to review | |---|---| | Argon2 arena (`g_arena`) | Large ordinary VirtualAlloc arena, too large to pin; wiped before release. The one block that is key-equivalent by itself - the last column's final block, input to the final hash - is `VirtualLock`ed (best-effort) while the KDF runs | | Argon2 H0 and compression state | `g_hbuf` (pinned in `sec_regions`) is scrubbed immediately after seeding initial lane blocks before the memory-hard fill loop runs; `g_inp`, `g_addr`, and `g_le4` are wiped on both normal and error exits; scalar/SSE2/AVX2 compressors scrub their stack scratch and volatile `xmm`/`ymm` registers (`vzeroupper` on AVX2) on return | | `g_urlbuf`, `g_urlbuf2` | URLs may contain private hosts or tokens; wiped after the launch path, and only explicit `http://` / `https://` schemes are passed to `ShellExecuteW` | | ZIP export buffers | Plaintext JSON (in a `secmem` arena), password copies, keys, and archive staging; normal cleanup in `ze_compose`/`ze_free` | | ZIP import | The decrypted JSON is in a `secmem` arena; the raw archive is `VirtualLock`ed best-effort while it is parsed | | Crypto stack frames and registers | AES-GCM (`gcm_seal`/`gcm_open` including `xmm6`), SHA-256 (`sha256_init`/`update`/`final`), SHA-1, BLAKE2b, HOTP/TOTP (`g_totp_key` 160 B + `totp_now` stack), `ct_memcmp`, and password-generation helpers wipe stack scratch and volatile vector registers (`xmm0..xmm5` / `ymm` on x64; `v0..v31` on ARM64) on return; AES key expansion uses hardware instructions (`aeskeygenassist` on x64; `AESE` on ARM64) without table S-boxes | | Attachment staging/open buffers | Plaintext copies are allocated in `secmem` arenas (`attach_stage`, `attach_open`, `gui_tile_view`, `gui_tile_download`) and wiped on teardown | | Windows controls and API buffers | Password and secret `EDIT` controls detach IME (`ImmAssociateContext(hwnd, 0)`) on creation, route `WM_COPY`/`WM_CUT` through `gui_copy` (clipboard exclusion + auto-clear timer), and are scrubbed via `gui_edit_scrub` (overwriting `CONVW_MAX - 1` wide chars with `'X'`, `EM_EMPTYUNDOBUFFER`, `EM_SETSEL` + `WM_CLEAR`, and `SetWindowTextW("")`) before teardown, though OS/control internal allocations and clipboard/provider copies can still exist outside application arrays | These are implementation limitations, not a claim that sensitive intermediate values are harmless. Wiping a working buffer cannot erase a copy already made by the OS, another process, storage snapshots, or a viewer. ## Normal and abnormal cleanup ```mermaid flowchart TD A["Secret loaded or edited"] --> B{"How does the session end?"} B -->|Normal lock or exit| C["Wipe owned buffers; free arenas"] C --> D["Clear owned clipboard copy"] D --> E["Attempt tracked preview cleanup"] E -->|Blocked viewer| F["Retain path; retry while locked"] B -->|Handled fatal exception| G["Attempt selected panic wipes; terminate"] B -->|Forced stop or OS failure| H["Cleanup may not run"] ``` `secmem_panic_wipe` avoids allocation and freeing because the heap may already be damaged. It attempts to wipe known buffers before exception termination. It does not guarantee that every crash reaches that handler or that every sensitive temporary is included. The live-base registry makes repeated frees of an unregistered address no-ops. It does not provide generation-aware pointer identity: an address reused for a new allocation must not be treated as safe through an old alias. ## Clipboard and previews Clipboard exclusion formats (`ExcludeClipboardContentFromMonitorProcessing` carrying a non-zero `DWORD 1` payload, plus `CanIncludeInClipboardHistory = 0` and `CanUploadToCloudClipboard = 0`) are applied fail-closed before placing secret text on the clipboard: if the exclusion marker cannot be set, Vordr calls `EmptyClipboard` and aborts the copy. These formats instruct cooperating Windows components not to index or sync copied secrets; they do not block other local processes from reading the active clipboard. The auto-clear timer verifies `GetClipboardSequenceNumber` ownership before clearing so a later user copy is untouched, and binds `CLIP_TIMER` to the persistent hidden tray window (`g_trayhwnd`) whenever a standalone dialog closes or the vault window minimizes/closes to the tray (`guitest.ps1`). Preview files are created exclusively inside separate random temporary directories (`%TEMP%\VordrPreview-`) protected by an inheritable (`OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE`), protected (`SE_DACL_PROTECTED`) owner+`SYSTEM` DACL plus `S:(ML;;NW;;;ME)`. At GUI startup, `gui_temp_sweep_stale` sweeps stale `VordrPreview-*` directories left by a prior power cut or forced stop strictly by handle (`gui_sweep_handle_ok`): it opens candidate files exclusively (`dwShareMode = 0`) with `FILE_FLAG_OPEN_REPARSE_POINT`, rejects directories, reparse points, and NTFS hardlinks (`nNumberOfLinks > 1`), verifies the canonical handle path (`GetFinalPathNameByHandleW`) begins with `%TEMP%\VordrPreview-` plus a subdirectory separator `\`, clears read-only attributes via `SetFileInformationByHandle` (`FileBasicInfo`), overwrites and flushes, and deletes by handle via `FileDispositionInfo`. Attachment filenames are sanitized via `gui_sanitize_attname` to strip directory components, drive prefixes, ADS `:stream` suffixes, control characters, trailing dots/spaces, and reserved DOS device names. `gui_temp_purge` attempts overwrite, flush, deletion, and directory removal. Failed cleanup stays tracked; the locked tray retries every five seconds. Normal Exit asks the user to close blocked viewers. Forced termination or shutdown can leave files behind, and overwrite/delete is not guaranteed physical erasure. Every preview temporary file and downloaded attachment receives a Mark of the Web (`Zone.Identifier`, `ZoneId=3`) verified fail-closed by `gui_motw` before proceeding; if writing the stream fails on a preview file, the preview is aborted and deleted. Automatic shell preview is restricted to a strict safe-preview allowlist (`preview_exts` in `gui.asm`: `txt`, `png`, `jpg`, `jpeg`, `gif`, `bmp`, `webp`, `pdf`); all other extensions route exclusively to Save As and are never passed to `ShellExecuteExW`. `NoPreview` disables the automatic preview hand-off. Downloads still write plaintext wherever the user explicitly chooses. The viewer's own caches and copies are outside Vordr's cleanup ownership. ## Comparison discipline `ct_memcmp` in `hardening.asm` accumulates differences over the supplied length. `gui_wstr_eq` accumulates content differences while scanning wide strings; string lengths remain timing-visible. Neither description proves absence of microarchitectural side channels. | Use | Comparison path | |---|---| | Vault KCV, including TPM-recovered keys | `ct_memcmp` in vault open | | TPM v2 inner vault/policy binding digest | `ct_memcmp` in `tpm_unseal` | | GCM tag | `ct_memcmp` in `gcm_open` | | Full-file MAC | `ct_memcmp` in vault authentication | | ZIP password verifier and HMAC tag | `ct_memcmp` in `zi_decrypt` | | ZIP per-attachment `SHA-256` plaintext digest | `ct_memcmp` in `zi_addattach` | | Password and export confirmation | `gui_wstr_eq` | | Old/new values for history capture | `gui_wstr_eq` | Public format keywords, attachment-ID lookup, local display sorting, and test sentinel scans have different comparison needs. Classify the data and any observable oracle before assuming an early exit is harmless. ## Review checklist - Identify every owner and copy, including temporary import/export contexts. - Match wipe lengths to allocated capacities and actual initialized contents. - Check success, cancellation, authentication failure, allocation failure, write failure, lock, and fatal-exception paths. - Preserve the original model until a GUI save succeeds. - Confirm plaintext downloads/previews are described accurately to users. - Run relevant probes: `secscan`, `secfreedup`, `lktest`, `tmptest`, `layoutkat`, and the persistence harness. A passing sentinel scan demonstrates the exercised path, not universal cleanup. See [Assurance](ASSURANCE.md) for test limitations.