cel: add bounds check in unmarshalFirstTLV to prevent OOM DoS#30
Open
adilburaksen wants to merge 1 commit intogoogle:mainfrom
Open
cel: add bounds check in unmarshalFirstTLV to prevent OOM DoS#30adilburaksen wants to merge 1 commit intogoogle:mainfrom
adilburaksen wants to merge 1 commit intogoogle:mainfrom
Conversation
unmarshalFirstTLV reads a uint32 valueLength from the input buffer and passes it directly to make([]byte, valueLength) without any bounds check. A 5-byte crafted TLV with valueLength=0xFFFFFFFF triggers a 4 GiB allocation attempt, causing an OOM condition in any process that parses untrusted CEL data (e.g. attestation verifiers reading a Confidential VM's event log). Fix: add maxTLVValueSize = 1<<20 (1 MiB) and reject any TLV whose declared length exceeds this limit before allocating. Regression test: TestOversizeTLVValueLength
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.
Summary
unmarshalFirstTLVincel/canonical_eventlog.goreads auint32value lengthfrom the input buffer and passes it directly to
make([]byte, valueLength)with nobounds check. A crafted 5-byte TLV (
[type][0xFF 0xFF 0xFF 0xFF]) causes a4 GiB allocation attempt, crashing any process that parses untrusted CEL data.
Root cause
Impact
Any caller of
DecodeToCELorunmarshalDigeststhat processes attacker-suppliedCEL bytes is vulnerable. Concretely, attestation verifiers that parse Confidential
VM event logs (e.g. go-tpm-tools
server.VerifyAttestation) receive the event logfrom the client VM — making this reachable from untrusted input.
Fix
Add
maxTLVValueSize = 1<<20(1 MiB) and reject oversized lengths beforeallocating:
The cap is generous: the fixed CEL fields (recnum = 8 B, regIndex = 1 B) and digest
TLVs (a few hundred bytes) are well below this limit. Even custom content events are
unlikely to approach 1 MiB in practice.
Test
TestOversizeTLVValueLength(added tocel/canonical_eventlog_test.go) crafts a5-byte TLV with
valueLength = maxTLVValueSize+1and asserts thatunmarshalFirstTLVreturns an error without performing a large allocation.