Skip to content

Commit

Permalink
eventlog: fix issue in TDX event log
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruoyu-y committed Jun 17, 2024
1 parent adbbe84 commit 172f659
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions common/python/cctrusted_base/eventlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,22 @@ class EventLogs:
"""
spec_id_header_event = None

def __init__(self, boot_time_data:bytes, runtime_data:bytes, parse_format:str=None) -> None:
def __init__(
self,
boot_time_data:bytes,
runtime_data:bytes,
platform:int=0,
parse_format:str=None
) -> None:
self._boot_time_data = boot_time_data
self._runtime_data = runtime_data
self._event_logs = []
self._count:int = 0
self._parse_format:str = parse_format
# Initiate the record number list for each index with default value 0
self.event_logs_record_number_list = [0] * 24
# Underlying platform that the event logs come from
self.platform = platform

@property
def event_logs(self):
Expand Down Expand Up @@ -280,10 +288,9 @@ def _parse_spec_id_event_log(self, data:bytes) -> (TcgEventLog, int):
blob = BinaryBlob(data, 0)

imr_index, index = blob.get_uint32(index)
header_imr = imr_index - 1
header_event_type, index = blob.get_uint32(index)

rec_num = self._get_record_number(header_imr)
rec_num = self._get_record_number(imr_index)

digest, index = blob.get_bytes(index, 20) # 20 zero for digest
# Convert digest to common TcgDigest type
Expand All @@ -294,7 +301,7 @@ def _parse_spec_id_event_log(self, data:bytes) -> (TcgEventLog, int):
header_event_size, index = blob.get_uint32(index) # 4 bytes containing event size
header_event, _ = blob.get_bytes(index, header_event_size)

specification_id_header = TcgEventLog(rec_num, header_imr, header_event_type, digests,
specification_id_header = TcgEventLog(rec_num, imr_index, header_event_type, digests,
header_event_size, header_event)

# Parse EFI Spec Id Event structure
Expand Down Expand Up @@ -348,7 +355,6 @@ def _parse_event_log(self, data:bytes) -> (TcgEventLog, int):
blob = BinaryBlob(data, 0)

imr_index, index = blob.get_uint32(index)
imr_index = imr_index - 1
event_type, index = blob.get_uint32(index)

rec_num = self._get_record_number(imr_index)
Expand Down Expand Up @@ -401,7 +407,14 @@ def _parse_ima_event_log(self, event:bytes) -> TcgEventLog:
digest_idx = 1
template_idx = 2

rec_num = self._get_record_number(int(elements[imr_idx]))
imr_val = int(elements[imr_idx])
# if the underlying platform is TDX
# increment the offset (1) between cc measurement
# register (defined in CCEL) and TDX measurment register
if self.platform == 1:
imr_val = imr_val + 1

rec_num = self._get_record_number(imr_val)

# Merge the elements left as event data
event = bytes(" ".join(elements[template_idx+1:]), "utf-8")
Expand All @@ -424,7 +437,7 @@ def _parse_ima_event_log(self, event:bytes) -> TcgEventLog:
"template_name": elements[template_idx]
}

return TcgEventLog(rec_num, int(elements[imr_idx]),
return TcgEventLog(rec_num, imr_val,
TcgEventType.IMA_MEASUREMENT_EVENT, digests,
event_size, event, extra_info)

Expand Down

0 comments on commit 172f659

Please sign in to comment.