docs: document the unlogged-table fork tweak limitation (M5)#20
Merged
Conversation
An unlogged relation's init fork is reset onto the main fork by PostgreSQL with a raw copy_file() in reinit.c, outside the storage hooks. For that copy of encrypted bytes to decrypt as the main fork, CalcBlockIv encrypts the init fork with the main fork's XTS tweak (INIT_FORKNUM aliases MAIN_FORKNUM). The tradeoff is that the two forks share the tweak at each block, so an attacker with the data files can tell which main-fork blocks are byte-identical to the init-fork template. This is required by PostgreSQL's own unlogged-relation reset and is a confidentiality-only limitation of XTS, so it is documented in the threat model rather than changed. Also expands the CalcBlockIv comment with the security rationale. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
M5: XTS tweak aliasing for unlogged-table init/main forks
The security review's M5 finding:
CalcBlockIvmapsINIT_FORKNUMtoMAIN_FORKNUM, so an unlogged table's init and main forks reuse the same XTS(key, tweak)at each block position.Why this is required, not a bug
PostgreSQL resets an unlogged relation after a crash by raw-copying the init fork file over the main fork (
copy_file()insrc/backend/storage/file/reinit.c), a filesystem-level copy of already-encrypted bytes that never passes through the storage hooks. For that copy to decrypt correctly as the main fork, the init fork must be encrypted with the main fork's tweak. The aliasing is therefore functionally required by PostgreSQL's own reset mechanism.The tradeoff
The two forks share the XTS tweak per block, so their ciphertext reveals which main-fork blocks are byte-identical to the (small, known) init-fork template. This is:
Decision
A real fix would require an invasive new core-patch hook in
reinit.cto re-encrypt on reset, plus per-relation on-disk format versioning and migration across PG 16/17/18. Given the leak is narrow and the aliasing is mandated by PostgreSQL's reset, this documents M5 as an accepted, confidentiality-only limitation instead, consistent with how the review treats XTS's lack of integrity.documentation/docs/concepts/threat-model.md: new "Unlogged table forks" entry under what open_pg_tde does not protect against, plus a summary-table row.src/encryption/enc_tde.c: expands theCalcBlockIvcomment with the security rationale.🤖 Generated with Claude Code