Skip to content

Residual key/nonce material on stack after ChaCha20 encrypt/decrypt #232

@rajsin31415

Description

@rajsin31415

Hi,

Following up on the secure-zero fixes in 2.3.3 (issue #230) — those addressed the heap-side wiping, but during a local source review I noticed that the ChaCha20 page-level encrypt/decrypt paths still leave derived material on the stack after return:

  • otk (one-time key, 64 bytes) in CodecEncrypt and CodecDecrypt in cipher_chacha20.c
    *tag (Poly1305 tag, 16 bytes) in both paths
    *nonce locals in the encrypt/decrypt functions

These are stack-local arrays that are not scrubbed before the function returns. After return, the stack frames remain in memory until overwritten by subsequent calls — meaning the derived per-page key material is recoverable from a crash dump or memory forensics tool.

This is not a practical break of ChaCha20-Poly1305 and the severity is low — it requires an attacker who already has a process memory dump. But since the 2.3.3 release specifically targeted memory-wiping completeness, I wanted to flag this as a remaining gap in the same category.

The fix would be adding sqlite3mcSecureZeroMemory() calls for otk, tag, and nonce before each return in the encrypt/decrypt paths, consistent with the approach taken for the heap-side fixes in commit a8a8ea1.

(Related: I also filed a packaging provenance request on the NuGet wrapper repo)

Thank you so much!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions