Parse TCG_PCClientPCREvent structures with an eventSize of 0 (#212)

This commit is contained in:
Brandon Weeks 2021-04-14 13:59:06 -07:00 committed by GitHub
parent 31ad4f57fd
commit b6c6a0c365
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 3 deletions

View File

@ -657,9 +657,6 @@ func parseRawEvent(r *bytes.Buffer, specID *specIDEvent) (event rawEvent, err er
if err = binary.Read(r, binary.LittleEndian, &h); err != nil { if err = binary.Read(r, binary.LittleEndian, &h); err != nil {
return event, fmt.Errorf("header deserialization error: %w", err) return event, fmt.Errorf("header deserialization error: %w", err)
} }
if h.EventSize == 0 {
return event, errors.New("event data size is 0")
}
if h.EventSize > uint32(r.Len()) { if h.EventSize > uint32(r.Len()) {
return event, &eventSizeErr{h.EventSize, r.Len()} return event, &eventSizeErr{h.EventSize, r.Len()}
} }

View File

@ -15,6 +15,7 @@
package attest package attest
import ( import (
"bytes"
"encoding/json" "encoding/json"
"io/ioutil" "io/ioutil"
"testing" "testing"
@ -149,6 +150,29 @@ func TestParseEventLogEventSizeTooLarge(t *testing.T) {
} }
} }
func TestParseEventLogEventSizeZero(t *testing.T) {
data := []byte{
// PCR index
0x4, 0x0, 0x0, 0x0,
// type
0xd, 0x0, 0x0, 0x0,
// Digest
0x94, 0x2d, 0xb7, 0x4a, 0xa7, 0x37, 0x5b, 0x23, 0xea, 0x23,
0x58, 0xeb, 0x3b, 0x31, 0x59, 0x88, 0x60, 0xf6, 0x90, 0x59,
// Event size (0 B)
0x0, 0x0, 0x0, 0x0,
// no "event data"
}
if _, err := parseRawEvent(bytes.NewBuffer(data), nil); err != nil {
t.Fatalf("parsing event log: %v", err)
}
}
func TestParseShortNoAction(t *testing.T) { func TestParseShortNoAction(t *testing.T) {
// https://trustedcomputinggroup.org/wp-content/uploads/TCG_PCClientSpecPlat_TPM_2p0_1p04_pub.pdf#page=110 // https://trustedcomputinggroup.org/wp-content/uploads/TCG_PCClientSpecPlat_TPM_2p0_1p04_pub.pdf#page=110
// says: "For EV_NO_ACTION events other than the EFI Specification ID event // says: "For EV_NO_ACTION events other than the EFI Specification ID event