Skip to content

Encrypt WAL frames below another VFS shim, add a VFS stack test - #312

Merged
utelle merged 2 commits into
utelle:mainfrom
SchwarzDigits:test/vfs-stack
Nov 17, 2026
Merged

utelle merged 2 commits into
utelle:mainfrom
SchwarzDigits:test/vfs-stack

Conversation

@mtrossbach

Copy link
Copy Markdown
Contributor

With another VFS shim above the Multiple Ciphers VFS that wraps the files, WAL frames were written in plaintext, and after a checkpoint the database could not be read again. sqlite3mcPagerCodec, which encrypts the page content for the WAL, only used the codec if the pager's file had the methods of the Multiple Ciphers VFS; with a shim above it, the pager's file is the shim's. It now asks the file for its codec with SQLITE3MC_FCNTL_PCODEC, as sqlite3mcPagerHasCodec already does; the file control passes through shims.

test/vfsstacktest.c (CI step "VFS stack tests") runs the same steps with the Multiple Ciphers VFS alone, below one and two pass-through VFS shims that wrap every file, and twice in the stack: create an encrypted database, WAL, ATTACH with KEY and with URI parameters, rekey, cipher change (through VACUUM), decrypt and encrypt again, with chacha20, aes256cbc, sqlcipher and aegis. After every step the database must open with the expected key, and no file may contain the plaintext of the rows.

Testing (macOS arm64, flags from Makefile.am):

  • With this change: 384 checks pass; the other CI tests pass as well. ASan and UBSan are clean.
  • On e65527d without the change: only the WAL steps with a shim fail (plaintext in the WAL, database not readable afterwards).
  • On v2.7.1: the WAL steps fail as well, and the cipher change, decryption and encryption of a plaintext database fail with "VFS of database 'vacuum_...' does not support encryption" (fixed in e65527d).
  • With the Multiple Ciphers VFS twice in the stack all steps pass: only the upper one encrypts, the file opens through the normal stack afterwards.

sqlite3mcPagerCodec, which encrypts the page content for the WAL, only
used the codec if the pager's file had the methods of the Multiple Ciphers
VFS. With another VFS shim above it that wraps the files, the pager's file
is the shim's, so the frames were written to the WAL in plaintext, and the
database could not be read again after a checkpoint.

Ask the file for its codec with SQLITE3MC_FCNTL_PCODEC instead, as
sqlite3mcPagerHasCodec already does; the file control passes through shims.
test/vfsstacktest.c runs the same steps with the Multiple Ciphers VFS
alone, below one and two pass-through VFS shims that wrap every file, and
twice in the stack: create an encrypted database, WAL, ATTACH with KEY and
with URI parameters, rekey, cipher change (through VACUUM), decrypt and
encrypt again. After every step the database must open with the expected
key, and no file may contain the plaintext of the rows.
@utelle
utelle merged commit 40dc4d2 into utelle:main Nov 17, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants