Skip to content

fix(kms): bound compose_hash and instance_id before the policy backend - #1310

Merged
kvinwang merged 2 commits into
nextfrom
fix/kms-identity-widths
Sep 22, 2026
Merged

kvinwang merged 2 commits into
nextfrom
fix/kms-identity-widths

Conversation

@kvinwang

@kvinwang kvinwang commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

Both Ethereum backends padStart short hex values, and nothing between attestation decoding and the backend call enforced compose_hash / instance_id widths on the TDX path, so a 31-byte compose_hash would be submitted as the whitelisted hash with a leading 0x00.

  • AuthApi::is_app_allowed requires a 20-byte app_id, a 32-byte compose_hash and a 20-byte-or-empty instance_id, for every backend call.
  • DstackApp.addComposeHash / addDevice reject bytes32(0), matching _initializeCommon.

Defense in depth: trusted OS images already emit these widths, so no deployment changes.

Split out of #1268 (K-g).

Only `app_id` was length-checked, and both Ethereum backends `padStart` a short
hex value to full width before the `readContract` call. A 31-byte compose hash
is therefore submitted as - and is indistinguishable from - the whitelisted
32-byte hash whose leading byte is `0x00`. The trusted OS always emits a 32-byte
sha256 and either a 20-byte instance id or none, but nothing between the event
log and the contract call asserted that.

Assert it at `AuthApi::is_app_allowed`, the one point every backend call goes
through, and stop `DstackApp.addComposeHash`/`addDevice` from allowlisting
`bytes32(0)` - which is exactly what that padding produces - since
`_initializeCommon` already declines to seed it.
@kvinwang
kvinwang merged commit 884402f into next Sep 22, 2026
13 checks passed
@kvinwang
kvinwang deleted the fix/kms-identity-widths branch September 22, 2026 10:24
kvinwang added a commit that referenced this pull request Sep 25, 2026
#1278, #1310 and #1365 added rows to main_service::upgrade_authority::tests,
so tc-kms-auth-010 failed its exact count of four. Count eight, name the new
coverage, and state which KMS-local reuses #1311 and #1399 introduced: the auth
API info and the self-authorization, never an app decision.

Signed-off-by: Kevin Wang <wy721@qq.com>
kvinwang added a commit that referenced this pull request Sep 25, 2026
#1310 made addComposeHash and addDevice reject bytes32(0). Include its Foundry
test in the shared policy run behind tc-kms-auth-006 and tc-kms-runtime-005.

Signed-off-by: Kevin Wang <wy721@qq.com>
kvinwang added a commit that referenced this pull request Sep 25, 2026
PR #1278 adds two rows proving an auth backend's multi-byte body cannot
abort the KMS, and #1310 and #1365 add one each; tc-kms-auth-010 pins the
exact count, so it now expects eight.

Signed-off-by: Kevin Wang <wy721@qq.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