Skip to content

abi: bound-check QE AuthData ParsedDataSize before slicing#102

Open
evilgensec wants to merge 2 commits into
google:mainfrom
evilgensec:fix/qeauthdata-parseddatasize-oob
Open

abi: bound-check QE AuthData ParsedDataSize before slicing#102
evilgensec wants to merge 2 commits into
google:mainfrom
evilgensec:fix/qeauthdata-parseddatasize-oob

Conversation

@evilgensec

Copy link
Copy Markdown

What

qeAuthDataToProto (abi/abi.go) reads a 16-bit ParsedDataSize from the QE AuthData of a TDX quote's certification data and uses it to slice the buffer:

authData.ParsedDataSize = uint32(binary.LittleEndian.Uint16(data[authDataParsedDataSizeStart:authDataParsedDataSizeEnd]))
authDataEnd := authDataParsedDataSizeEnd + authData.GetParsedDataSize()
authData.Data = data[authDataStart:authDataEnd]   // no bounds check

ParsedDataSize is fully attacker-controlled (it comes from the untrusted quote). If it is larger than the bytes actually present, data[authDataStart:authDataEnd] slices out of bounds and panics instead of returning an error. The validating length check in checkQeAuthData (which checks ParsedDataSize == len(Data)) runs on the next line — only after the slice — so it never executes in the out-of-bounds case.

Because the parse runs under the public verification entry points (abi.QuoteToProtoverify.RawTdxQuote) and there is no recover on that path, a malformed quote panics the verifier rather than being cleanly rejected.

A 2-byte input reproduces it directly:

qeAuthDataToProto([]byte{0xFF, 0xFF})
// panic: runtime error: slice bounds out of range [:65537] with capacity 2

Fix

Add the missing pre-slice bound check (mirroring the existing pre-slice length checks in certificationDataToProto and signedDataToProto), plus a short-buffer guard for the ParsedDataSize read itself, so malformed QE AuthData is rejected with an error instead of panicking.

Testing

go test ./abi/... passes, including two new regression tests: an out-of-bounds ParsedDataSize and a too-short buffer now both return an error rather than panicking.

qeAuthDataToProto read an attacker-controlled 16-bit ParsedDataSize from a TDX quote's QE certification data and used it to slice the buffer (data[authDataStart:authDataEnd]) with no bounds check. A ParsedDataSize larger than the remaining bytes sliced out of bounds and panicked the parser, and through QuoteToProto / verify.RawTdxQuote the whole verifier, instead of returning an error for the malformed quote. The validating length check in checkQeAuthData ran only after the slice, so it never executed in the out-of-bounds case.

Add the missing pre-slice bound check (mirroring certificationDataToProto and signedDataToProto) plus a short-buffer guard for the ParsedDataSize read, and regression tests.
quoteToProtoV5 reads signedDataSizeV5 as a uint32 but stores it in an int32, so a high-bit-set value becomes negative. The guard int32(len(additionalData)) < signedDataSizeV5 is then bypassed (a positive length is never < a negative size) and data[offset : offset+signedDataSizeV5] slices out of bounds and panics. Same out-of-bounds-slice class as the QE AuthData fix in this PR; the V4 path (quoteToProtoV4) compares as uint32 and is unaffected. Reject a negative size before the slice.
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