Skip to content

fix(dstack-mr): bound the PE header region before hashing it - #1231

Merged
kvinwang merged 2 commits into
nextfrom
fix/dstack-mr-pe-header-bounds
Sep 24, 2026
Merged

kvinwang merged 2 commits into
nextfrom
fix/dstack-mr-pe-header-bounds

Conversation

@kvinwang

@kvinwang kvinwang commented Sep 20, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

authenticode_sha384_hash (dstack-mr/src/kernel.rs) used SizeOfHeaders and the certificate-directory offset, both read from the image, as slice bounds without checking them. A SizeOfHeaders past the image, smaller than the cert directory end, or a PE truncated before the cert directory panics (range end index 4294967280 out of range for slice of length 8192). Release builds are panic = "abort" and the measurement runs in-process in the verifier/KMS, so a malformed image aborts the service instead of failing one measurement.

Not attacker-reachable in practice: images are content-addressed (sha256sum.txt hash == os_image_hash, gated by the on-chain whitelist) before parsing. This guards against a malformed published image. Reported as GHSA-wgq9-5x6m-wg2w.

Fix

Check cert_dir_end <= size_of_headers <= data.len() before slicing, which also covers the two earlier slices.

Verification

  • New regression test panics at kernel.rs:56 without the fix, passes with it; cargo test -p dstack-mr 30 passed.
  • measure-os output is byte-identical before/after on 6 real OS images (real kernels: SizeOfHeaders 0x400, cert_dir_end 232).

@kvinwang
kvinwang merged commit b211786 into next Sep 24, 2026
11 checks passed
@kvinwang
kvinwang deleted the fix/dstack-mr-pe-header-bounds branch September 24, 2026 14:20
kvinwang added a commit that referenced this pull request Sep 25, 2026
… parser bounds

#1387 requires PCI hotplug off for GPU passthrough, so the matrix GPU row
failed; measure it with hotplug off and assert the named rejection without.
#1229 reads XLF bit 1, not bit 6, for the initrd ceiling: fix the harness
oracle and add a row with a 5-level-only kernel. #1367 made diagnose honour
num_nics, num_verity_volumes and swtpm; compare it with measure. Run the
new dstack-mr and dstack-types bound vectors from #1229, #1231, #1236 and

Signed-off-by: Kevin Wang <wy721@qq.com>
#1275 by exact name.
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