Skip to content

dstack-util: bound LUKS2 keyslot area to the metadata region#799

Open
h4x3rotab wants to merge 1 commit into
masterfrom
luks2-keyslot-bounds
Open

dstack-util: bound LUKS2 keyslot area to the metadata region#799
h4x3rotab wants to merge 1 commit into
masterfrom
luks2-keyslot-bounds

Conversation

@h4x3rotab

Copy link
Copy Markdown
Contributor

What

The in-memory LUKS2 header validator checks the cipher and KDF shape exhaustively, but never bounds the keyslot area.offset/area.size — the on-disk byte range the encrypted key material is read from. This adds a bounds check.

Why

A malicious host has raw read/write access to the disk. Without this check it can point the keyslot area anywhere inside an otherwise fully-conforming header, and the validator still accepts it.

It's not exploitable on its own: cryptsetup decrypts the keyslot under the KMS-derived passphrase and verifies the recovered key against the digest, so a redirected area just yields the wrong key and luksOpen aborts (a DoS a host with disk write already has). But a validator whose whole job is to pin the header shouldn't let the key material come from an arbitrary offset. This closes the gap as defense-in-depth.

Change

  • Reject a keyslot area outside [2 * hdr_size, PAYLOAD_OFFSET) — after both header copies, before the payload.
  • Test that a header with the area redirected below the header region is rejected.
  • Comment noting salts stay unchecked on purpose (high-entropy KMS passphrase, per report Static HKDF salt "RATLS" with no key versioning #552), so the gap doesn't read as an oversight later.

No cross-copy comparison is added: both copies already pass the same strict whitelist independently, so once the area is bounded they can't meaningfully diverge.

🤖 Generated with Claude Code

The in-memory header validator pinned the cipher/KDF shape but never
checked the keyslot area.offset/size — the byte range the encrypted key
material is read from. A host with raw disk access could redirect it
inside an otherwise-conforming header.

cryptsetup's digest check already stops this from yielding a usable key,
so it isn't exploitable on its own, but the validator shouldn't accept a
header pointing its key material somewhere arbitrary. Bound the area to
[2 * hdr_size, PAYLOAD_OFFSET) and reject anything outside it.

Also note why salts stay unchecked (high-entropy KMS-derived passphrase,
per #552) so the gap doesn't read as an oversight next time.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant