Skip to content

abi: reject overlapping certificate table ranges - #212

Merged
brongan merged 1 commit into
google:mainfrom
brongan:cert-table-alloc-bound
Dec 2, 2026
Merged

brongan merged 1 commit into
google:mainfrom
brongan:cert-table-alloc-bound

Conversation

@brongan

@brongan brongan commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

CertTable.Unmarshal now returns abi.ErrCertTableOverlap when two entries have overlapping byte ranges.

Problem

Verifiers parse untrusted certificate table bytes before they check the attestation report signature. CertTable.Unmarshal copied a new byte slice for each header entry without checking for overlap. A 1 MiB input with 21,844 entries (524,280 header bytes including the terminator) all pointing to the same 524,296-byte range made Unmarshal allocate 11,452,721,824 bytes (~10.7 GiB).

flowchart LR
  subgraph Input["1 MiB input"]
    H0["Entry 0: offset=524280, len=524296"] --> P["Shared bytes (524,296 B)"]
    H1["Entry 1: offset=524280, len=524296"] --> P
    HN["Entry 21843: offset=524280, len=524296"] --> P
  end
  Input -->|"Before"| OOM["10.7 GiB allocated"]
  Input -->|"After"| Err["ErrCertTableOverlap (0 B copied)"]
Loading

Design

Extended guest requests use 4 KiB pages and pad unused space at the end with zeros. Summing entry lengths and comparing against the data block size misses overlapping entries whenever that zero padding is large enough to cover the duplicate bytes. Checking directly that entry byte ranges do not overlap catches every overlap regardless of page padding or entry order, and keeps total certificate bytes at or below the data block size.

Layout Fits in dataSize Before After
Contiguous entries Yes Succeeds Succeeds
Gaps or 4 KiB page padding Yes Succeeds Succeeds
Out-of-order offsets Yes Succeeds Succeeds
Zero-length entry (Length == 0) Yes Succeeds Succeeds
Overlap exceeding dataSize No Allocates N * L bytes Returns ErrCertTableOverlap
Overlap inside padded page Yes Allocates duplicate copies Returns ErrCertTableOverlap

Spec and implementation comparison

  • AMD GHCB specification (Publication #56421, Section 4.1.8.1, SNP Extended Guest Request): Defines cert_table at offset 0x0 of the guest data pages as 24-byte (GUID, Offset, Length) entries ending with an all-zero entry. It does not say whether entry ranges can overlap.
  • Linux sev_report_new: Copies from offset 0 up to max(offset + length) once as a flat buffer capped at 16 KiB.
  • Why this PR is stricter: CertTable.Unmarshal accepts untrusted buffers of any size and copies each entry into its own slice. Separate copies protect parsed certificates if the caller reuses the buffer and let Go free the rest of the input. Rejecting overlapping ranges stops memory amplification before signature verification and still accepts every layout from CertTable.Marshal, Linux sev-guest, and 4 KiB page padding.

Testing

go test -race -cover ./abi reaches 100.0% statement coverage on (*CertTable).Unmarshal, and FuzzCertTableUnmarshal passes without changes.

@brongan
brongan force-pushed the cert-table-alloc-bound branch from 9406ab3 to 9c69919 Compare November 11, 2026 23:08
@brongan brongan changed the title abi: bound CertTable allocation to input size abi: reject overlapping certificate table ranges Nov 11, 2026
@brongan
brongan force-pushed the cert-table-alloc-bound branch 5 times, most recently from ecffe76 to 1946a6b Compare November 12, 2026 22:19
@brongan
brongan marked this pull request as ready for review November 12, 2026 22:34
@brongan
brongan requested a review from kongoshuu November 12, 2026 22:39
@brongan
brongan requested review from yawangwang and removed request for kongoshuu November 23, 2026 19:45
Return an error when two entries in a certificate table overlap.

Verifiers parse untrusted certificate tables before they check report
signatures. If several entries point to the same bytes, a small input
can cause gigabytes of allocation. Checking for overlap directly instead
of summing entry lengths also catches overlaps inside zero-padded 4 KiB
request pages.
@brongan
brongan force-pushed the cert-table-alloc-bound branch from 1946a6b to 5f0cbd7 Compare December 2, 2026 20:21
@brongan
brongan merged commit 5f0cbd7 into google:main Dec 2, 2026
20 checks passed
@brongan
brongan deleted the cert-table-alloc-bound branch December 2, 2026 21:24
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