abi: bound-check QE AuthData ParsedDataSize before slicing#102
Open
evilgensec wants to merge 2 commits into
Open
abi: bound-check QE AuthData ParsedDataSize before slicing#102evilgensec wants to merge 2 commits into
evilgensec wants to merge 2 commits into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
qeAuthDataToProto(abi/abi.go) reads a 16-bitParsedDataSizefrom the QE AuthData of a TDX quote's certification data and uses it to slice the buffer:ParsedDataSizeis 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 incheckQeAuthData(which checksParsedDataSize == 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.QuoteToProto→verify.RawTdxQuote) and there is norecoveron that path, a malformed quote panics the verifier rather than being cleanly rejected.A 2-byte input reproduces it directly:
Fix
Add the missing pre-slice bound check (mirroring the existing pre-slice length checks in
certificationDataToProtoandsignedDataToProto), plus a short-buffer guard for theParsedDataSizeread 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-boundsParsedDataSizeand a too-short buffer now both return an error rather than panicking.